From 7c3dff4f02b7f3c712548b3436ff2b2652ffd3ed Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 25 May 2005 21:15:43 +0000 Subject: [PATCH] fix problem with arrays of switches --- direct/src/dcparser/dcSwitch.cxx | 11 +++++++++++ direct/src/dcparser/dcSwitch.h | 1 + direct/src/dcparser/dcSwitchParameter.cxx | 16 ++++++++++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/direct/src/dcparser/dcSwitch.cxx b/direct/src/dcparser/dcSwitch.cxx index 18923eff3d..790fd72d42 100644 --- a/direct/src/dcparser/dcSwitch.cxx +++ b/direct/src/dcparser/dcSwitch.cxx @@ -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 diff --git a/direct/src/dcparser/dcSwitch.h b/direct/src/dcparser/dcSwitch.h index 6228bb0df5..ac08d48eef 100644 --- a/direct/src/dcparser/dcSwitch.h +++ b/direct/src/dcparser/dcSwitch.h @@ -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; diff --git a/direct/src/dcparser/dcSwitchParameter.cxx b/direct/src/dcparser/dcSwitchParameter.cxx index e8b83167bb..6cc7a764cf 100755 --- a/direct/src/dcparser/dcSwitchParameter.cxx +++ b/direct/src/dcparser/dcSwitchParameter.cxx @@ -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; + } } ////////////////////////////////////////////////////////////////////