Panda3D
|
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 vector< DCField * > | Fields |
typedef map< string, DCField * > | FieldsByName |
Public Member Functions | |
DCSwitch (const 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 string &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 string &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 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 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... | |
string | 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 (ostream &out, bool brief) const |
Write a string representation of this instance to <out>. More... | |
void | output_instance (ostream &out, bool brief, const string &prename, const string &name, const 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 (ostream &out, bool brief, int indent_level) const |
Generates a parseable description of the object to the indicated output stream. More... | |
void | write_instance (ostream &out, bool brief, int indent_level, const string &prename, const string &name, const string &postname) const |
Generates a parseable description of the object to the indicated output stream. More... | |
![]() | |
virtual DCClass * | as_class () |
virtual const DCClass * | as_class () const |
virtual void | output (ostream &out) const |
Write a string representation of this instance to <out>. More... | |
void | write (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 33 of file dcSwitch.h.
DCSwitch::DCSwitch | ( | const 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 30 of file dcSwitch.cxx.
References get_name().
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 323 of file dcSwitch.cxx.
References apply_switch().
Referenced by add_field().
int DCSwitch::add_case | ( | const string & | 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 238 of file dcSwitch.cxx.
References add_invalid_case().
Referenced by is_field_valid().
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 274 of file dcSwitch.cxx.
References add_field(), and add_invalid_case().
Referenced by 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 297 of file dcSwitch.cxx.
References add_break(), and DCSwitch::SwitchFields::add_field().
Referenced by add_default().
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 261 of file dcSwitch.cxx.
References add_default().
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 337 of file dcSwitch.cxx.
References output().
Referenced by add_break().
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 570 of file dcSwitch.cxx.
References DCSwitch::SwitchFields::add_field(), DCPackerInterface::check_match(), DCSwitch::SwitchCase::do_check_match_switch_case(), and DCSwitch::SwitchFields::get_nested_field().
Referenced by pack_default_value().
|
virtual |
Accumulates the properties of this switch into the hash.
Definition at line 480 of file dcSwitch.cxx.
References HashGenerator::add_int(), HashGenerator::add_string(), DCField::generate_hash(), and pack_default_value().
Referenced by write_instance().
DCPackerInterface * DCSwitch::get_case | ( | int | n | ) | const |
Returns the DCPackerInterface that packs the nth case.
Definition at line 146 of file dcSwitch.cxx.
References get_default_case().
Referenced by get_case_by_value().
int DCSwitch::get_case_by_value | ( | const string & | 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 130 of file dcSwitch.cxx.
References get_case().
Referenced by get_num_cases().
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 158 of file dcSwitch.cxx.
References get_value().
Referenced by get_case().
DCField * DCSwitch::get_field | ( | int | case_index, |
int | n | ||
) | const |
Returns the nth field in the indicated case.
Definition at line 191 of file dcSwitch.cxx.
References get_field_by_name().
Referenced by get_num_fields().
DCField * DCSwitch::get_field_by_name | ( | int | case_index, |
const 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 204 of file dcSwitch.cxx.
References is_field_valid().
Referenced by get_field().
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 106 of file dcSwitch.cxx.
References get_num_cases().
Referenced by get_name().
const string & DCSwitch::get_name | ( | ) | const |
Returns the name of this switch.
Definition at line 93 of file dcSwitch.cxx.
References get_key_parameter().
Referenced by DCFile::add_switch(), and DCSwitch().
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 118 of file dcSwitch.cxx.
References get_case_by_value().
Referenced by get_key_parameter().
int DCSwitch::get_num_fields | ( | int | case_index | ) | const |
Returns the number of fields in the indicated case.
Definition at line 180 of file dcSwitch.cxx.
References get_field().
Referenced by get_value().
string DCSwitch::get_value | ( | int | case_index | ) | const |
Returns the packed value associated with the indicated case.
Definition at line 169 of file dcSwitch.cxx.
References get_num_fields().
Referenced by get_default_case().
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 225 of file dcSwitch.cxx.
References add_case().
Referenced by get_field_by_name().
|
virtual |
Write a string representation of this instance to <out>.
Implements DCDeclaration.
Definition at line 360 of file dcSwitch.cxx.
References output_instance(), and write().
Referenced by apply_switch().
void DCSwitch::output_instance | ( | ostream & | out, |
bool | brief, | ||
const string & | prename, | ||
const string & | name, | ||
const string & | postname | ||
) | const |
Generates a parseable description of the object to the indicated output stream.
Definition at line 382 of file dcSwitch.cxx.
References DCField::format_data(), DCField::output(), and write_instance().
|
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 519 of file dcSwitch.cxx.
References DCPackData::append_data(), DCPacker::begin_pack(), do_check_match_switch(), DCPacker::end_pack(), DCPacker::get_data(), DCPacker::get_length(), DCPacker::pack_default_value(), and DCPacker::pack_literal_value().
Referenced by generate_hash().
|
virtual |
Generates a parseable description of the object to the indicated output stream.
Implements DCDeclaration.
Definition at line 371 of file dcSwitch.cxx.
References output_instance(), and write_instance().
Referenced by output().
void DCSwitch::write_instance | ( | ostream & | out, |
bool | brief, | ||
int | indent_level, | ||
const string & | prename, | ||
const string & | name, | ||
const string & | postname | ||
) | const |
Generates a parseable description of the object to the indicated output stream.
Definition at line 428 of file dcSwitch.cxx.
References DCField::format_data(), generate_hash(), and DCField::output().
Referenced by output_instance(), and write().