This represents a switch statement, which can appear inside a class body and represents two or more alternative unpacking schemes based on the first field read. More...
#include "dcSwitch.h"
Classes | |
class | SwitchCase |
class | SwitchFields |
Public Types | |
typedef std::vector< DCField * > | Fields |
typedef std::map< std::string, DCField * > | FieldsByName |
Public Member Functions | |
DCSwitch (const std::string &name, DCField *key_parameter) | |
The key_parameter must be recently allocated via new; it will be deleted via delete when the switch destructs. More... | |
void | add_break () |
Adds a break statement to the switch. More... | |
int | add_case (const vector_uchar &value) |
Adds a new case to the switch with the indicated value, and returns the new case_index. More... | |
bool | add_default () |
Adds a default case to the switch. More... | |
bool | add_field (DCField *field) |
Adds a field to the currently active cases (those that have been added via add_case() or add_default(), since the last call to add_break()). More... | |
void | add_invalid_case () |
Adds a new case to the switch that will never be matched. More... | |
const DCPackerInterface * | apply_switch (const char *value_data, size_t length) const |
Returns the DCPackerInterface that presents the alternative fields for the case indicated by the given packed value string, or NULL if the value string does not match one of the expected cases. More... | |
virtual DCSwitch * | as_switch () |
virtual const DCSwitch * | as_switch () const |
bool | do_check_match_switch (const DCSwitch *other) const |
Returns true if this switch matches the indicated other switch–that is, the two switches are bitwise equivalent–false otherwise. More... | |
virtual void | generate_hash (HashGenerator &hashgen) const |
Accumulates the properties of this switch into the hash. More... | |
DCPackerInterface * | get_case (int n) const |
Returns the DCPackerInterface that packs the nth case. More... | |
int | get_case_by_value (const vector_uchar &case_value) const |
Returns the index number of the case with the indicated packed value, or -1 if no case has this value. More... | |
DCPackerInterface * | get_default_case () const |
Returns the DCPackerInterface that packs the default case, or NULL if there is no default case. More... | |
DCField * | get_field (int case_index, int n) const |
Returns the nth field in the indicated case. More... | |
DCField * | get_field_by_name (int case_index, const std::string &name) const |
Returns the field with the given name from the indicated case, or NULL if no field has this name. More... | |
DCField * | get_key_parameter () const |
Returns the key parameter on which the switch is based. More... | |
const std::string & | get_name () const |
Returns the name of this switch. More... | |
int | get_num_cases () const |
Returns the number of different cases within the switch. More... | |
int | get_num_fields (int case_index) const |
Returns the number of fields in the indicated case. More... | |
vector_uchar | get_value (int case_index) const |
Returns the packed value associated with the indicated case. More... | |
bool | is_field_valid () const |
Returns true if it is valid to add a new field at this point (implying that a case or default has been added already), or false if not. More... | |
virtual void | output (std::ostream &out, bool brief) const |
Write a string representation of this instance to <out>. More... | |
void | output_instance (std::ostream &out, bool brief, const std::string &prename, const std::string &name, const std::string &postname) const |
Generates a parseable description of the object to the indicated output stream. More... | |
virtual bool | pack_default_value (DCPackData &pack_data, bool &pack_error) const |
Packs the switchParameter's specified default value (or a sensible default if no value is specified) into the stream. More... | |
virtual void | write (std::ostream &out, bool brief, int indent_level) const |
Generates a parseable description of the object to the indicated output stream. More... | |
void | write_instance (std::ostream &out, bool brief, int indent_level, const std::string &prename, const std::string &name, const std::string &postname) const |
Generates a parseable description of the object to the indicated output stream. More... | |
Public Member Functions inherited from DCDeclaration | |
virtual DCClass * | as_class () |
virtual const DCClass * | as_class () const |
virtual void | output (std::ostream &out) const |
Write a string representation of this instance to <out>. More... | |
void | write (std::ostream &out, int indent_level) const |
Write a string representation of this instance to <out>. More... | |
This represents a switch statement, which can appear inside a class body and represents two or more alternative unpacking schemes based on the first field read.
Definition at line 30 of file dcSwitch.h.
DCSwitch::DCSwitch | ( | const std::string & | name, |
DCField * | key_parameter | ||
) |
The key_parameter must be recently allocated via new; it will be deleted via delete when the switch destructs.
Definition at line 29 of file dcSwitch.cxx.
void DCSwitch::add_break | ( | ) |
Adds a break statement to the switch.
This closes the currently open cases and prepares for a new, unrelated case.
Definition at line 273 of file dcSwitch.cxx.
int DCSwitch::add_case | ( | const vector_uchar & | value | ) |
Adds a new case to the switch with the indicated value, and returns the new case_index.
If the value has already been used for another case, returns -1. This is normally called only by the parser.
Definition at line 201 of file dcSwitch.cxx.
References add_invalid_case().
bool DCSwitch::add_default | ( | ) |
Adds a default case to the switch.
Returns true if the case is successfully added, or false if it had already been added. This is normally called only by the parser.
Definition at line 231 of file dcSwitch.cxx.
References add_invalid_case().
bool DCSwitch::add_field | ( | DCField * | field | ) |
Adds a field to the currently active cases (those that have been added via add_case() or add_default(), since the last call to add_break()).
Returns true if successful, false if the field duplicates a field already named within this case. It is an error to call this before calling add_case() or add_default(). This is normally called only by the parser.
Definition at line 250 of file dcSwitch.cxx.
void DCSwitch::add_invalid_case | ( | ) |
Adds a new case to the switch that will never be matched.
This is only used by the parser, to handle an error condition more gracefully without bitching the parsing (which behaves differently according to whether a case has been encountered or not).
Definition at line 221 of file dcSwitch.cxx.
Referenced by add_case(), and add_default().
const DCPackerInterface * DCSwitch::apply_switch | ( | const char * | value_data, |
size_t | length | ||
) | const |
Returns the DCPackerInterface that presents the alternative fields for the case indicated by the given packed value string, or NULL if the value string does not match one of the expected cases.
Definition at line 284 of file dcSwitch.cxx.
bool DCSwitch::do_check_match_switch | ( | const DCSwitch * | other | ) | const |
Returns true if this switch matches the indicated other switch–that is, the two switches are bitwise equivalent–false otherwise.
This is only intended to be called internally from DCSwitchParameter::do_check_match_switch_parameter().
Definition at line 499 of file dcSwitch.cxx.
References DCPackerInterface::check_match().
|
virtual |
Accumulates the properties of this switch into the hash.
Definition at line 416 of file dcSwitch.cxx.
References HashGenerator::add_blob(), HashGenerator::add_int(), HashGenerator::add_string(), and DCField::generate_hash().
DCPackerInterface * DCSwitch::get_case | ( | int | n | ) | const |
Returns the DCPackerInterface that packs the nth case.
Definition at line 126 of file dcSwitch.cxx.
int DCSwitch::get_case_by_value | ( | const vector_uchar & | case_value | ) | const |
Returns the index number of the case with the indicated packed value, or -1 if no case has this value.
Definition at line 112 of file dcSwitch.cxx.
DCPackerInterface * DCSwitch::get_default_case | ( | ) | const |
Returns the DCPackerInterface that packs the default case, or NULL if there is no default case.
Definition at line 136 of file dcSwitch.cxx.
DCField * DCSwitch::get_field | ( | int | case_index, |
int | n | ||
) | const |
Returns the nth field in the indicated case.
Definition at line 162 of file dcSwitch.cxx.
DCField * DCSwitch::get_field_by_name | ( | int | case_index, |
const std::string & | name | ||
) | const |
Returns the field with the given name from the indicated case, or NULL if no field has this name.
Definition at line 173 of file dcSwitch.cxx.
DCField * DCSwitch::get_key_parameter | ( | ) | const |
Returns the key parameter on which the switch is based.
The value of this parameter in the record determines which one of the several cases within the switch will be used.
Definition at line 94 of file dcSwitch.cxx.
const string & DCSwitch::get_name | ( | ) | const |
Returns the name of this switch.
Definition at line 84 of file dcSwitch.cxx.
Referenced by DCFile::add_switch().
int DCSwitch::get_num_cases | ( | ) | const |
Returns the number of different cases within the switch.
The legal values for case_index range from 0 to get_num_cases() - 1.
Definition at line 103 of file dcSwitch.cxx.
int DCSwitch::get_num_fields | ( | int | case_index | ) | const |
Returns the number of fields in the indicated case.
Definition at line 153 of file dcSwitch.cxx.
vector_uchar DCSwitch::get_value | ( | int | case_index | ) | const |
Returns the packed value associated with the indicated case.
Definition at line 144 of file dcSwitch.cxx.
bool DCSwitch::is_field_valid | ( | ) | const |
Returns true if it is valid to add a new field at this point (implying that a case or default has been added already), or false if not.
Definition at line 191 of file dcSwitch.cxx.
|
virtual |
Write a string representation of this instance to <out>.
Implements DCDeclaration.
Definition at line 305 of file dcSwitch.cxx.
References output_instance().
void DCSwitch::output_instance | ( | std::ostream & | out, |
bool | brief, | ||
const std::string & | prename, | ||
const std::string & | name, | ||
const std::string & | postname | ||
) | const |
Generates a parseable description of the object to the indicated output stream.
Definition at line 323 of file dcSwitch.cxx.
References DCField::format_data(), and DCField::output().
Referenced by output().
|
virtual |
Packs the switchParameter's specified default value (or a sensible default if no value is specified) into the stream.
Returns true if the default value is packed, false if the switchParameter doesn't know how to pack its default value.
Definition at line 452 of file dcSwitch.cxx.
References DCPacker::begin_pack(), DCPacker::end_pack(), DCPacker::pack_default_value(), and DCPacker::pack_literal_value().
|
virtual |
Generates a parseable description of the object to the indicated output stream.
Implements DCDeclaration.
Definition at line 314 of file dcSwitch.cxx.
References write_instance().
void DCSwitch::write_instance | ( | std::ostream & | out, |
bool | brief, | ||
int | indent_level, | ||
const std::string & | prename, | ||
const std::string & | name, | ||
const std::string & | postname | ||
) | const |
Generates a parseable description of the object to the indicated output stream.
Definition at line 367 of file dcSwitch.cxx.
References DCField::format_data(), indent(), and DCField::output().
Referenced by write().