fix problem with arrays of switches

This commit is contained in:
David Rose 2005-05-25 21:15:43 +00:00
parent 98196002ed
commit 7c3dff4f02
3 changed files with 26 additions and 2 deletions

View File

@ -152,6 +152,17 @@ get_case(int n) const {
return _cases[n]->_fields;
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::get_default_case
// Access: Published
// Description: Returns the DCPackerInterface that packs the default
// case, or NULL if there is no default case.
////////////////////////////////////////////////////////////////////
DCPackerInterface *DCSwitch::
get_default_case() const {
return _default_case;
}
////////////////////////////////////////////////////////////////////
// Function: DCSwitch::get_value
// Access: Published

View File

@ -49,6 +49,7 @@ PUBLISHED:
int get_num_cases() const;
int get_case_by_value(const string &case_value) const;
DCPackerInterface *get_case(int n) const;
DCPackerInterface *get_default_case() const;
string get_value(int case_index) const;
int get_num_fields(int case_index) const;

View File

@ -52,7 +52,8 @@ DCSwitchParameter(const DCSwitch *dswitch) :
int num_cases = _dswitch->get_num_cases();
if (num_cases > 0) {
_fixed_byte_size = _dswitch->get_case(0)->get_fixed_byte_size();
// Consider each case for fixed size, etc.
for (int i = 0; i < num_cases; i++) {
const DCSwitch::SwitchFields *fields =
(const DCSwitch::SwitchFields *)_dswitch->get_case(i);
@ -69,7 +70,18 @@ DCSwitchParameter(const DCSwitch *dswitch) :
}
}
_fixed_byte_size += key_parameter->get_fixed_byte_size();
// Also consider the default case, if there is one.
const DCSwitch::SwitchFields *fields =
(DCSwitch::SwitchFields *)_dswitch->get_default_case();
if (fields != (DCSwitch::SwitchFields *)NULL) {
if (!fields->has_fixed_byte_size() ||
fields->get_fixed_byte_size() != _fixed_byte_size) {
_has_fixed_byte_size = false;
}
_has_range_limits = _has_range_limits || fields->has_range_limits();
_has_default_value = _has_default_value || fields->_has_default_value;
}
}
////////////////////////////////////////////////////////////////////