From 439d1b200e4af4702493d9f4e64639b1ea4e15c6 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 17 Jun 2004 19:18:07 +0000 Subject: [PATCH] DCType -> DCParameter, also parsing and formatting of values --- direct/src/dcparser/Sources.pp | 4 +- direct/src/dcparser/dcAtomicField.cxx | 97 ++++++------ direct/src/dcparser/dcAtomicField.h | 13 +- direct/src/dcparser/dcClass.cxx | 14 +- direct/src/dcparser/dcClass.h | 5 +- direct/src/dcparser/dcField.cxx | 12 +- direct/src/dcparser/dcField.h | 2 - direct/src/dcparser/dcLexer.lxx | 17 ++ direct/src/dcparser/dcLexerDefs.h | 1 + direct/src/dcparser/dcMolecularField.h | 2 +- direct/src/dcparser/dcPacker.cxx | 130 +++++++++++++++- direct/src/dcparser/dcPacker.h | 5 + direct/src/dcparser/dcPackerInterface.cxx | 32 ++++ direct/src/dcparser/dcPackerInterface.h | 9 ++ .../dcparser/{dcType.cxx => dcParameter.cxx} | 58 +++---- .../src/dcparser/{dcType.h => dcParameter.h} | 37 ++--- direct/src/dcparser/dcParser.cxx.prebuilt | 6 +- direct/src/dcparser/dcParser.h.prebuilt | 2 + direct/src/dcparser/dcParser.yxx | 145 +++++++++++------ direct/src/dcparser/dcParserDefs.h | 5 + ...dcSimpleType.cxx => dcSimpleParameter.cxx} | 146 +++++++++--------- .../{dcSimpleType.h => dcSimpleParameter.h} | 29 ++-- direct/src/dcparser/dcparser_composite2.cxx | 4 +- 23 files changed, 492 insertions(+), 283 deletions(-) rename direct/src/dcparser/{dcType.cxx => dcParameter.cxx} (68%) mode change 100755 => 100644 rename direct/src/dcparser/{dcType.h => dcParameter.h} (72%) mode change 100755 => 100644 rename direct/src/dcparser/{dcSimpleType.cxx => dcSimpleParameter.cxx} (90%) mode change 100755 => 100644 rename direct/src/dcparser/{dcSimpleType.h => dcSimpleParameter.h} (83%) mode change 100755 => 100644 diff --git a/direct/src/dcparser/Sources.pp b/direct/src/dcparser/Sources.pp index 8d8d638a8f..8b207cc405 100644 --- a/direct/src/dcparser/Sources.pp +++ b/direct/src/dcparser/Sources.pp @@ -21,7 +21,7 @@ dcPackData.h dcPackData.I \ dcPacker.h dcPacker.I \ dcPackerInterface.h \ - dcType.h dcSimpleType.h \ + dcParameter.h dcSimpleParameter.h \ dcbase.h dcindent.h hashGenerator.h \ primeNumberGenerator.h @@ -31,7 +31,7 @@ dcPackData.cxx \ dcPacker.cxx \ dcPackerInterface.cxx \ - dcType.cxx dcSimpleType.cxx \ + dcParameter.cxx dcSimpleParameter.cxx \ dcindent.cxx \ hashGenerator.cxx primeNumberGenerator.cxx diff --git a/direct/src/dcparser/dcAtomicField.cxx b/direct/src/dcparser/dcAtomicField.cxx index e1c1c0c66e..0403ffe0e3 100644 --- a/direct/src/dcparser/dcAtomicField.cxx +++ b/direct/src/dcparser/dcAtomicField.cxx @@ -19,20 +19,21 @@ #include "dcAtomicField.h" #include "hashGenerator.h" #include "dcindent.h" -#include "dcSimpleType.h" +#include "dcSimpleParameter.h" +#include "dcPacker.h" #include //////////////////////////////////////////////////////////////////// // Function: DCAtomicField::ElementType::Constructor // Access: Public -// Description: The type parameter should be a newly-allocated DCType +// Description: The type parameter should be a newly-allocated DCParameter // object; it will eventually be freed with delete when // this object destructs. //////////////////////////////////////////////////////////////////// DCAtomicField::ElementType:: -ElementType(DCType *type) { - _type = type; +ElementType(DCParameter *param) { + _param = param; _has_default_value = false; } @@ -43,8 +44,7 @@ ElementType(DCType *type) { //////////////////////////////////////////////////////////////////// DCAtomicField::ElementType:: ElementType(const DCAtomicField::ElementType ©) : - _type(copy._type->make_copy()), - _name(copy._name), + _param(copy._param->make_copy()), _default_value(copy._default_value), _has_default_value(copy._has_default_value) { @@ -57,9 +57,8 @@ ElementType(const DCAtomicField::ElementType ©) : //////////////////////////////////////////////////////////////////// void DCAtomicField::ElementType:: operator = (const DCAtomicField::ElementType ©) { - delete _type; - _type = copy._type->make_copy(); - _name = copy._name; + delete _param; + _param = copy._param->make_copy(); _default_value = copy._default_value; _has_default_value = copy._has_default_value; } @@ -71,7 +70,7 @@ operator = (const DCAtomicField::ElementType ©) { //////////////////////////////////////////////////////////////////// DCAtomicField::ElementType:: ~ElementType() { - delete _type; + delete _param; } //////////////////////////////////////////////////////////////////// @@ -92,15 +91,14 @@ set_default_value(const string &default_value) { //////////////////////////////////////////////////////////////////// void DCAtomicField::ElementType:: output(ostream &out, bool brief) const { - _type->output(out, _name, brief); + _param->output(out, brief); if (!brief && _has_default_value) { - out << " = <" << hex; - string::const_iterator si; - for (si = _default_value.begin(); si != _default_value.end(); ++si) { - out << setw(2) << setfill('0') << (int)(unsigned char)(*si); - } - out << dec << ">"; + out << " = "; + DCPacker packer; + packer.begin_unpack(_default_value, _param); + packer.unpack_and_format(out); + packer.end_unpack(); } } @@ -128,29 +126,15 @@ get_num_elements() const { } //////////////////////////////////////////////////////////////////// -// Function: DCAtomicField::get_element_type +// Function: DCAtomicField::get_element // Access: Public -// Description: Returns the type object describing the type of the -// nth element (parameter). +// Description: Returns the parameter object describing the +// nth element. //////////////////////////////////////////////////////////////////// -DCType *DCAtomicField:: -get_element_type_obj(int n) const { +DCParameter *DCAtomicField:: +get_element(int n) const { nassertr(n >= 0 && n < (int)_elements.size(), NULL); - return _elements[n]._type; -} - -//////////////////////////////////////////////////////////////////// -// Function: DCAtomicField::get_element_name -// Access: Public -// Description: Returns the name of the nth element of the field. -// This name is strictly for documentary purposes; it -// does not generally affect operation. If a name is -// not specified, this will be the empty string. -//////////////////////////////////////////////////////////////////// -string DCAtomicField:: -get_element_name(int n) const { - nassertr(n >= 0 && n < (int)_elements.size(), string()); - return _elements[n]._name; + return _elements[n]._param; } //////////////////////////////////////////////////////////////////// @@ -186,19 +170,36 @@ has_element_default(int n) const { return _elements[n]._has_default_value; } +//////////////////////////////////////////////////////////////////// +// Function: DCAtomicField::get_element_name +// Access: Public +// Description: Returns the name of the nth element of the field. +// This name is strictly for documentary purposes; it +// does not generally affect operation. If a name is +// not specified, this will be the empty string. +// +// This method is deprecated; use +// get_element()->get_name() instead. +//////////////////////////////////////////////////////////////////// +string DCAtomicField:: +get_element_name(int n) const { + nassertr(n >= 0 && n < (int)_elements.size(), string()); + return _elements[n]._param->get_name(); +} + //////////////////////////////////////////////////////////////////// // Function: DCAtomicField::get_element_type // Access: Public // Description: Returns the numeric type of the nth element of the // field. This method is deprecated; use -// get_element_type_obj() instead. +// get_element() instead. //////////////////////////////////////////////////////////////////// DCSubatomicType DCAtomicField:: get_element_type(int n) const { nassertr(n >= 0 && n < (int)_elements.size(), ST_invalid); - DCSimpleType *simple_type = _elements[n]._type->as_simple_type(); - nassertr(simple_type != (DCSimpleType *)NULL, ST_invalid); - return simple_type->get_type(); + DCSimpleParameter *simple_parameter = _elements[n]._param->as_simple_parameter(); + nassertr(simple_parameter != (DCSimpleParameter *)NULL, ST_invalid); + return simple_parameter->get_type(); } //////////////////////////////////////////////////////////////////// @@ -210,15 +211,15 @@ get_element_type(int n) const { // multiplied by this value before encoding into a // packet, and divided by this number after decoding. // -// This method is deprecated; use get_element_type_obj() -// instead. +// This method is deprecated; use +// get_element()->get_divisor() instead. //////////////////////////////////////////////////////////////////// int DCAtomicField:: get_element_divisor(int n) const { nassertr(n >= 0 && n < (int)_elements.size(), 1); - DCSimpleType *simple_type = _elements[n]._type->as_simple_type(); - nassertr(simple_type != (DCSimpleType *)NULL, 1); - return simple_type->get_divisor(); + DCSimpleParameter *simple_parameter = _elements[n]._param->as_simple_parameter(); + nassertr(simple_parameter != (DCSimpleParameter *)NULL, 1); + return simple_parameter->get_divisor(); } //////////////////////////////////////////////////////////////////// @@ -402,7 +403,7 @@ generate_hash(HashGenerator &hashgen) const { Elements::const_iterator ei; for (ei = _elements.begin(); ei != _elements.end(); ++ei) { const ElementType &element = (*ei); - element._type->generate_hash(hashgen); + element._param->generate_hash(hashgen); } hashgen.add_int(_flags); } @@ -431,5 +432,5 @@ get_num_nested_fields() const { DCPackerInterface *DCAtomicField:: get_nested_field(int n) const { nassertr(n >= 0 && n < (int)_elements.size(), NULL); - return _elements[n]._type; + return _elements[n]._param; } diff --git a/direct/src/dcparser/dcAtomicField.h b/direct/src/dcparser/dcAtomicField.h index bb323382db..17d6c99819 100644 --- a/direct/src/dcparser/dcAtomicField.h +++ b/direct/src/dcparser/dcAtomicField.h @@ -22,7 +22,7 @@ #include "dcbase.h" #include "dcField.h" #include "dcSubatomicType.h" -#include "dcType.h" +#include "dcParameter.h" // Must use math.h instead of cmath.h so this can compile outside of // Panda. @@ -40,12 +40,12 @@ PUBLISHED: virtual DCAtomicField *as_atomic_field(); int get_num_elements() const; - DCType *get_element_type_obj(int n) const; - string get_element_name(int n) const; + DCParameter *get_element(int n) const; string get_element_default(int n) const; bool has_element_default(int n) const; - // These two methods are deprecated and will be removed soon. + // These three methods are deprecated and will be removed soon. + string get_element_name(int n) const; DCSubatomicType get_element_type(int n) const; int get_element_divisor(int n) const; @@ -72,7 +72,7 @@ public: // definition as read from the file. class ElementType { public: - ElementType(DCType *type); + ElementType(DCParameter *param); ElementType(const ElementType ©); void operator = (const ElementType ©); ~ElementType(); @@ -81,8 +81,7 @@ public: void output(ostream &out, bool brief) const; - DCType *_type; - string _name; + DCParameter *_param; string _default_value; bool _has_default_value; }; diff --git a/direct/src/dcparser/dcClass.cxx b/direct/src/dcparser/dcClass.cxx index 71cee7e64d..4ecb9ef696 100644 --- a/direct/src/dcparser/dcClass.cxx +++ b/direct/src/dcparser/dcClass.cxx @@ -33,16 +33,6 @@ get_number() const { return _number; } -//////////////////////////////////////////////////////////////////// -// Function: DCClass::get_name -// Access: Published -// Description: Returns the name of this class. -//////////////////////////////////////////////////////////////////// -string DCClass:: -get_name() const { - return _name; -} - //////////////////////////////////////////////////////////////////// // Function: DCClass::has_parent // Access: Published @@ -534,8 +524,8 @@ ai_format_generate(PyObject *distobj, int do_id, //////////////////////////////////////////////////////////////////// DCClass:: DCClass(const string &name, bool bogus_class) : - _bogus_class(bogus_class), - _name(name) + DCPackerInterface(name), + _bogus_class(bogus_class) { #ifdef HAVE_PYTHON _class_def = NULL; diff --git a/direct/src/dcparser/dcClass.h b/direct/src/dcparser/dcClass.h index 1a39e76aa6..6b49cd3112 100644 --- a/direct/src/dcparser/dcClass.h +++ b/direct/src/dcparser/dcClass.h @@ -21,6 +21,7 @@ #include "dcbase.h" #include "dcField.h" +#include "dcPackerInterface.h" class HashGenerator; @@ -29,10 +30,9 @@ class HashGenerator; // Description : Defines a particular DistributedClass as read from an // input .dc file. //////////////////////////////////////////////////////////////////// -class EXPCL_DIRECT DCClass { +class EXPCL_DIRECT DCClass : public DCPackerInterface { PUBLISHED: int get_number() const; - string get_name() const; bool has_parent() const; DCClass *get_parent() const; @@ -87,7 +87,6 @@ private: // class as read from the file. bool _bogus_class; int _number; - string _name; typedef pvector Parents; Parents _parents; diff --git a/direct/src/dcparser/dcField.cxx b/direct/src/dcparser/dcField.cxx index 2106ef39c4..6c2c70087f 100644 --- a/direct/src/dcparser/dcField.cxx +++ b/direct/src/dcparser/dcField.cxx @@ -33,16 +33,6 @@ get_number() const { return _number; } -//////////////////////////////////////////////////////////////////// -// Function: DCField::get_name -// Access: Published -// Description: Returns the name of this field. -//////////////////////////////////////////////////////////////////// -const string &DCField:: -get_name() const { - return _name; -} - //////////////////////////////////////////////////////////////////// // Function: DCField::as_atomic_field // Access: Published, Virtual @@ -219,7 +209,7 @@ ai_format_update(int do_id, int to_id, int from_id, PyObject *args) const { // Description: //////////////////////////////////////////////////////////////////// DCField:: -DCField(const string &name) : _name(name) { +DCField(const string &name) : DCPackerInterface(name) { _number = 0; } diff --git a/direct/src/dcparser/dcField.h b/direct/src/dcparser/dcField.h index a1f3fbd5cd..f275c6cc1c 100644 --- a/direct/src/dcparser/dcField.h +++ b/direct/src/dcparser/dcField.h @@ -45,7 +45,6 @@ class HashGenerator; class EXPCL_DIRECT DCField : public DCPackerInterface { PUBLISHED: int get_number() const; - const string &get_name() const; virtual DCAtomicField *as_atomic_field(); virtual DCMolecularField *as_molecular_field(); @@ -71,7 +70,6 @@ public: protected: int _number; - string _name; friend class DCClass; }; diff --git a/direct/src/dcparser/dcLexer.lxx b/direct/src/dcparser/dcLexer.lxx index d3e6e28983..a3bc507750 100644 --- a/direct/src/dcparser/dcLexer.lxx +++ b/direct/src/dcparser/dcLexer.lxx @@ -39,6 +39,10 @@ static istream *inp = NULL; // can print it out for error messages. static string dc_filename; +// This is the initial token state returned by the lexer. It allows +// the yacc grammar to start from initial points. +static int initial_token; + //////////////////////////////////////////////////////////////////// // Defining the interface to the lexer. @@ -52,6 +56,14 @@ dc_init_lexer(istream &in, const string &filename) { col_number = 0; error_count = 0; warning_count = 0; + initial_token = START_DC; +} + +void +dc_start_parameter_value() { + /* Set the initial state to begin parsing a parameter value, instead + of at the beginning of the dc file. */ + initial_token = START_PARAMETER_VALUE; } int @@ -295,6 +307,11 @@ REALNUM ([+-]?(([0-9]+[.])|([0-9]*[.][0-9]+))([eE][+-]?[0-9]+)?) %% %{ + if (initial_token != 0) { + int t = initial_token; + initial_token = 0; + return t; + } %} \n.* { diff --git a/direct/src/dcparser/dcLexerDefs.h b/direct/src/dcparser/dcLexerDefs.h index c49afd6e2e..0ee8c98735 100644 --- a/direct/src/dcparser/dcLexerDefs.h +++ b/direct/src/dcparser/dcLexerDefs.h @@ -22,6 +22,7 @@ #include "dcbase.h" void dc_init_lexer(istream &in, const string &filename); +void dc_start_parameter_value(); int dc_error_count(); int dc_warning_count(); diff --git a/direct/src/dcparser/dcMolecularField.h b/direct/src/dcparser/dcMolecularField.h index bd7add5f9c..517bc11652 100644 --- a/direct/src/dcparser/dcMolecularField.h +++ b/direct/src/dcparser/dcMolecularField.h @@ -55,7 +55,7 @@ private: typedef pvector Fields; Fields _fields; - DCType *get_next_pack_element(); + DCParameter *get_next_pack_element(); typedef pvector NestedFields; NestedFields _nested_fields; diff --git a/direct/src/dcparser/dcPacker.cxx b/direct/src/dcparser/dcPacker.cxx index 92e01d5d32..aaf8711436 100755 --- a/direct/src/dcparser/dcPacker.cxx +++ b/direct/src/dcparser/dcPacker.cxx @@ -17,6 +17,8 @@ //////////////////////////////////////////////////////////////////// #include "dcPacker.h" +#include "dcParserDefs.h" +#include "dcLexerDefs.h" //////////////////////////////////////////////////////////////////// // Function: DCPacker::Constructor @@ -50,7 +52,7 @@ DCPacker:: // Access: Published // Description: Begins a packing session. The parameter is the DC // object that describes the packing format; it may be a -// DCType or DCField. +// DCParameter or DCField. //////////////////////////////////////////////////////////////////// void DCPacker:: begin_pack(const DCPackerInterface *root) { @@ -419,3 +421,129 @@ unpack_object() { return object; } #endif // HAVE_PYTHON + + +//////////////////////////////////////////////////////////////////// +// Function: DCPacker::parse_and_pack +// Access: Published +// Description: Parses an object's value according to the DC file +// syntax (e.g. as a default value string) and packs it. +// Returns true on success, false on a parse error. +//////////////////////////////////////////////////////////////////// +bool DCPacker:: +parse_and_pack(const string &formatted_object) { + istringstream strm(formatted_object); + return parse_and_pack(strm); +} + +//////////////////////////////////////////////////////////////////// +// Function: DCPacker::parse_and_pack +// Access: Published +// Description: Parses an object's value according to the DC file +// syntax (e.g. as a default value string) and packs it. +// Returns true on success, false on a parse error. +//////////////////////////////////////////////////////////////////// +bool DCPacker:: +parse_and_pack(istream &in) { + dc_init_parser_parameter_value(in, "parse_and_pack", *this); + dcyyparse(); + dc_cleanup_parser(); + + return (dc_error_count() == 0); +} + +//////////////////////////////////////////////////////////////////// +// Function: DCPacker::unpack_and_format +// Access: Published +// Description: Unpacks an object and formats its value into a syntax +// suitable for parsing in the dc file (e.g. as a +// default value), or as an input to parse_object. +//////////////////////////////////////////////////////////////////// +string DCPacker:: +unpack_and_format() { + ostringstream strm; + unpack_and_format(strm); + return strm.str(); +} + +//////////////////////////////////////////////////////////////////// +// Function: DCPacker::unpack_and_format +// Access: Published +// Description: Unpacks an object and formats its value into a syntax +// suitable for parsing in the dc file (e.g. as a +// default value), or as an input to parse_object. +//////////////////////////////////////////////////////////////////// +void DCPacker:: +unpack_and_format(ostream &out) { + DCPackType pack_type = get_pack_type(); + + switch (pack_type) { + case PT_double: + { + out << unpack_double(); + } + break; + + case PT_int: + { + out << unpack_int(); + } + break; + + case PT_int64: + { + out << unpack_int64(); + } + break; + + case PT_string: + { + out << '"' << unpack_string() << '"'; + } + break; + + default: + { + switch (pack_type) { + case PT_array: + out << '['; + break; + + case PT_field: + out << '('; + break; + + case PT_struct: + default: + out << '{'; + break; + } + + push(); + while (more_nested_fields()) { + unpack_and_format(out); + + if (more_nested_fields()) { + out << ", "; + } + } + pop(); + + switch (pack_type) { + case PT_array: + out << ']'; + break; + + case PT_field: + out << ')'; + break; + + case PT_struct: + default: + out << '}'; + break; + } + } + break; + } +} diff --git a/direct/src/dcparser/dcPacker.h b/direct/src/dcparser/dcPacker.h index 825cca1881..7e584cea7c 100755 --- a/direct/src/dcparser/dcPacker.h +++ b/direct/src/dcparser/dcPacker.h @@ -70,6 +70,11 @@ PUBLISHED: PyObject *unpack_object(); #endif + bool parse_and_pack(const string &formatted_object); + bool parse_and_pack(istream &in); + string unpack_and_format(); + void unpack_and_format(ostream &out); + INLINE bool had_pack_error() const; INLINE size_t get_num_unpacked_bytes() const; diff --git a/direct/src/dcparser/dcPackerInterface.cxx b/direct/src/dcparser/dcPackerInterface.cxx index 2890225d08..3845702477 100755 --- a/direct/src/dcparser/dcPackerInterface.cxx +++ b/direct/src/dcparser/dcPackerInterface.cxx @@ -18,6 +18,17 @@ #include "dcPackerInterface.h" +//////////////////////////////////////////////////////////////////// +// Function: DCPackerInterface::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +DCPackerInterface:: +DCPackerInterface(const string &name) : + _name(name) +{ +} + //////////////////////////////////////////////////////////////////// // Function: DCPackerInterface::Destructor // Access: Public, Virtual @@ -27,6 +38,27 @@ DCPackerInterface:: ~DCPackerInterface() { } +//////////////////////////////////////////////////////////////////// +// Function: DCPackerInterface::get_name +// Access: Published +// Description: Returns the name of this field, or empty string +// if the field is unnamed. +//////////////////////////////////////////////////////////////////// +const string &DCPackerInterface:: +get_name() const { + return _name; +} + +//////////////////////////////////////////////////////////////////// +// Function: DCPackerInterface::set_name +// Access: Published +// Description: Sets the name of this field. +//////////////////////////////////////////////////////////////////// +void DCPackerInterface:: +set_name(const string &name) { + _name = name; +} + //////////////////////////////////////////////////////////////////// // Function: DCPackerInterface::has_nested_fields // Access: Public, Virtual diff --git a/direct/src/dcparser/dcPackerInterface.h b/direct/src/dcparser/dcPackerInterface.h index edf29871b7..17377513d2 100755 --- a/direct/src/dcparser/dcPackerInterface.h +++ b/direct/src/dcparser/dcPackerInterface.h @@ -60,8 +60,14 @@ END_PUBLISH //////////////////////////////////////////////////////////////////// class EXPCL_DIRECT DCPackerInterface { public: + DCPackerInterface(const string &name = string()); virtual ~DCPackerInterface(); +PUBLISHED: + const string &get_name() const; + void set_name(const string &name); + +public: virtual bool has_nested_fields() const; virtual int get_num_nested_fields() const; virtual int get_num_nested_fields(size_t length_bytes) const; @@ -78,6 +84,9 @@ public: virtual bool unpack_int(const char *data, size_t length, size_t &p, int &value) const; virtual bool unpack_int64(const char *data, size_t length, size_t &p, PN_int64 &value) const; virtual bool unpack_string(const char *data, size_t length, size_t &p, string &value) const; + +protected: + string _name; }; #endif diff --git a/direct/src/dcparser/dcType.cxx b/direct/src/dcparser/dcParameter.cxx old mode 100755 new mode 100644 similarity index 68% rename from direct/src/dcparser/dcType.cxx rename to direct/src/dcparser/dcParameter.cxx index 48c42bdff3..1fd03726e8 --- a/direct/src/dcparser/dcType.cxx +++ b/direct/src/dcparser/dcParameter.cxx @@ -1,4 +1,4 @@ -// Filename: dcType.cxx +// Filename: dcParameter.cxx // Created by: drose (15Jun04) // //////////////////////////////////////////////////////////////////// @@ -16,88 +16,74 @@ // //////////////////////////////////////////////////////////////////// -#include "dcType.h" +#include "dcParameter.h" #include "hashGenerator.h" //////////////////////////////////////////////////////////////////// -// Function: DCType::Constructor +// Function: DCParameter::Constructor // Access: Protected // Description: //////////////////////////////////////////////////////////////////// -DCType:: -DCType() { +DCParameter:: +DCParameter() { } //////////////////////////////////////////////////////////////////// -// Function: DCType::Destructor +// Function: DCParameter::Destructor // Access: Public, Virtual // Description: //////////////////////////////////////////////////////////////////// -DCType:: -~DCType() { +DCParameter:: +~DCParameter() { } //////////////////////////////////////////////////////////////////// -// Function: DCType::get_name -// Access: Published, Virtual -// Description: Returns a string that uniquely describes this type. -//////////////////////////////////////////////////////////////////// -string DCType:: -get_name() const { - // The default get_name() implementation simply returns the result - // of output(). - ostringstream result; - output(result, "", true); - return result.str(); -} - -//////////////////////////////////////////////////////////////////// -// Function: DCType::as_simple_type +// Function: DCParameter::as_simple_parameter // Access: Published, Virtual // Description: //////////////////////////////////////////////////////////////////// -DCSimpleType *DCType:: -as_simple_type() { +DCSimpleParameter *DCParameter:: +as_simple_parameter() { return NULL; } //////////////////////////////////////////////////////////////////// -// Function: DCType::as_class_type +// Function: DCParameter::as_class_parameter // Access: Published, Virtual // Description: //////////////////////////////////////////////////////////////////// -DCClassType *DCType:: -as_class_type() { +DCClassParameter *DCParameter:: +as_class_parameter() { return NULL; } //////////////////////////////////////////////////////////////////// -// Function: DCType::as_array_type +// Function: DCParameter::as_array_parameter // Access: Published, Virtual // Description: //////////////////////////////////////////////////////////////////// -DCArrayType *DCType:: -as_array_type() { +DCArrayParameter *DCParameter:: +as_array_parameter() { return NULL; } //////////////////////////////////////////////////////////////////// -// Function: DCType::as_typedef_type +// Function: DCParameter::as_typedef_parameter // Access: Published, Virtual // Description: //////////////////////////////////////////////////////////////////// -DCTypedefType *DCType:: -as_typedef_type() { +DCTypedefParameter *DCParameter:: +as_typedef_parameter() { return NULL; } //////////////////////////////////////////////////////////////////// -// Function: DCType::generate_hash +// Function: DCParameter::generate_hash // Access: Public, Virtual // Description: Accumulates the properties of this type into the // hash. //////////////////////////////////////////////////////////////////// -void DCType:: +void DCParameter:: generate_hash(HashGenerator &) const { } diff --git a/direct/src/dcparser/dcType.h b/direct/src/dcparser/dcParameter.h old mode 100755 new mode 100644 similarity index 72% rename from direct/src/dcparser/dcType.h rename to direct/src/dcparser/dcParameter.h index 505aa374bf..822d66434f --- a/direct/src/dcparser/dcType.h +++ b/direct/src/dcparser/dcParameter.h @@ -1,4 +1,4 @@ -// Filename: dcType.h +// Filename: dcParameter.h // Created by: drose (15Jun04) // //////////////////////////////////////////////////////////////////// @@ -16,8 +16,8 @@ // //////////////////////////////////////////////////////////////////// -#ifndef DCTYPE_H -#define DCTYPE_H +#ifndef DCPARAMETER_H +#define DCPARAMETER_H #include "dcbase.h" #include "dcPackerInterface.h" @@ -33,14 +33,14 @@ #endif // HAVE_PYTHON -class DCSimpleType; -class DCClassType; -class DCArrayType; -class DCTypedefType; +class DCSimpleParameter; +class DCClassParameter; +class DCArrayParameter; +class DCTypedefParameter; class HashGenerator; //////////////////////////////////////////////////////////////////// -// Class : DCType +// Class : DCParameter // Description : Represents the type specification for a single // parameter within a field specification. This may be // a simple type, or it may be a class or an array @@ -50,25 +50,22 @@ class HashGenerator; // which has the same properties as the referenced type, // but a different name. //////////////////////////////////////////////////////////////////// -class EXPCL_DIRECT DCType : public DCPackerInterface { +class EXPCL_DIRECT DCParameter : public DCPackerInterface { protected: - DCType(); + DCParameter(); public: - virtual ~DCType(); + virtual ~DCParameter(); PUBLISHED: - virtual string get_name() const; + virtual DCSimpleParameter *as_simple_parameter(); + virtual DCClassParameter *as_class_parameter(); + virtual DCArrayParameter *as_array_parameter(); + virtual DCTypedefParameter *as_typedef_parameter(); - virtual DCSimpleType *as_simple_type(); - virtual DCClassType *as_class_type(); - virtual DCArrayType *as_array_type(); - virtual DCTypedefType *as_typedef_type(); - - virtual DCType *make_copy() const=0; + virtual DCParameter *make_copy() const=0; public: - virtual void output(ostream &out, const string ¶meter_name, - bool brief) const=0; + virtual void output(ostream &out, bool brief) const=0; virtual void generate_hash(HashGenerator &hash) const; }; diff --git a/direct/src/dcparser/dcParser.cxx.prebuilt b/direct/src/dcparser/dcParser.cxx.prebuilt index 965bd4a7dd..de57efd846 100644 --- a/direct/src/dcparser/dcParser.cxx.prebuilt +++ b/direct/src/dcparser/dcParser.cxx.prebuilt @@ -56,7 +56,7 @@ #include "dcClass.h" #include "dcAtomicField.h" #include "dcMolecularField.h" -#include "dcSimpleType.h" +#include "dcSimpleParameter.h" #include "dcPacker.h" // Because our token type contains objects of type string, which @@ -71,7 +71,7 @@ static DCFile *dc_file = (DCFile *)NULL; static DCClass *current_class = (DCClass *)NULL; static DCAtomicField *current_atomic = (DCAtomicField *)NULL; static DCMolecularField *current_molecular = (DCMolecularField *)NULL; -static DCAtomicField::ElementType atomic_element(new DCSimpleType(ST_invalid)); +static DCAtomicField::ElementType atomic_element(new DCSimpleParameter(ST_invalid)); static DCPacker default_value_packer; //////////////////////////////////////////////////////////////////// @@ -1153,7 +1153,7 @@ case 29: case 34: #line 246 "dcParser.yxx" { - atomic_element = DCAtomicField::ElementType(new DCSimpleType(yyvsp[0].u.subatomic)); + atomic_element = DCAtomicField::ElementType(new DCSimpleParameter(yyvsp[0].u.subatomic)); } break; case 35: diff --git a/direct/src/dcparser/dcParser.h.prebuilt b/direct/src/dcparser/dcParser.h.prebuilt index 1c3a5372e6..5401afc333 100644 --- a/direct/src/dcparser/dcParser.h.prebuilt +++ b/direct/src/dcparser/dcParser.h.prebuilt @@ -38,6 +38,8 @@ # define KW_CLRECV 291 # define KW_OWNSEND 292 # define KW_AIRECV 293 +# define START_DC 294 +# define START_PARAMETER_VALUE 295 extern YYSTYPE dcyylval; diff --git a/direct/src/dcparser/dcParser.yxx b/direct/src/dcparser/dcParser.yxx index b682e8bbf8..1b455dfc74 100644 --- a/direct/src/dcparser/dcParser.yxx +++ b/direct/src/dcparser/dcParser.yxx @@ -10,7 +10,7 @@ #include "dcClass.h" #include "dcAtomicField.h" #include "dcMolecularField.h" -#include "dcSimpleType.h" +#include "dcSimpleParameter.h" #include "dcPacker.h" // Because our token type contains objects of type string, which @@ -25,8 +25,10 @@ static DCFile *dc_file = (DCFile *)NULL; static DCClass *current_class = (DCClass *)NULL; static DCAtomicField *current_atomic = (DCAtomicField *)NULL; static DCMolecularField *current_molecular = (DCMolecularField *)NULL; -static DCAtomicField::ElementType atomic_element(new DCSimpleType(ST_invalid)); -static DCPacker default_value_packer; +static DCAtomicField::ElementType atomic_element(new DCSimpleParameter(ST_invalid)); +static DCParameter *current_parameter = (DCParameter *)NULL; +static DCPacker default_packer; +static DCPacker *current_packer; //////////////////////////////////////////////////////////////////// // Defining the interface to the parser. @@ -38,6 +40,15 @@ dc_init_parser(istream &in, const string &filename, DCFile &file) { dc_init_lexer(in, filename); } +void +dc_init_parser_parameter_value(istream &in, const string &filename, + DCPacker &packer) { + dc_file = NULL; + current_packer = &packer; + dc_init_lexer(in, filename); + dc_start_parameter_value(); +} + void dc_cleanup_parser() { dc_file = (DCFile *)NULL; @@ -85,14 +96,26 @@ dc_cleanup_parser() { %token KW_OWNSEND %token KW_AIRECV +/* These special tokens are used to set the starting state of the + parser. The lexer places the appropriate one of these on the head + of the input stream. */ +%token START_DC +%token START_PARAMETER_VALUE + %type dclass_name %type atomic_name %type type_token +%type parameter %type import_identifier %type slash_identifier %% +grammar: + START_DC dc + | START_PARAMETER_VALUE parameter_value + ; + dc: empty | dc ';' @@ -242,94 +265,121 @@ nonempty_parameter_list: ; atomic_element: - type_token -{ - atomic_element = DCAtomicField::ElementType(new DCSimpleType($1)); -} - atomic_element_definition + parameter { + atomic_element = DCAtomicField::ElementType($1); current_atomic->_elements.push_back(atomic_element); } - ; - -atomic_element_definition: - empty - | atomic_element_definition '/' INTEGER + | parameter '=' { - if (atomic_element._type->as_simple_type() == NULL) { - yyerror("Invalid divisor on complex type"); - - } else { - atomic_element._type->as_simple_type()->set_divisor($3); - } + current_packer = &default_packer; + current_packer->begin_pack($1); } - | atomic_element_definition IDENTIFIER + parameter_value { - atomic_element._name = $2; -} - | atomic_element_definition '=' -{ - default_value_packer.begin_pack(atomic_element._type); -} - default_value -{ - if (!default_value_packer.end_pack()) { + if (!current_packer->end_pack()) { yyerror("Invalid default value for type"); } else { - atomic_element.set_default_value(default_value_packer.get_string()); + atomic_element = DCAtomicField::ElementType($1); + atomic_element.set_default_value(current_packer->get_string()); + current_atomic->_elements.push_back(atomic_element); } } ; -default_value: +parameter: + type_token +{ + current_parameter = new DCSimpleParameter($1); +} + parameter_definition +{ + $$ = current_parameter; +} + ; + +parameter_definition: + empty + | parameter_definition '/' INTEGER +{ + if (current_parameter->as_simple_parameter() == NULL) { + yyerror("Invalid divisor on complex type"); + + } else { + current_parameter->as_simple_parameter()->set_divisor($3); + } +} + | parameter_definition IDENTIFIER +{ + current_parameter->set_name($2); +} + ; + +parameter_value: INTEGER { - default_value_packer.pack_int($1); + current_packer->pack_int($1); } | REAL { - default_value_packer.pack_double($1); + current_packer->pack_double($1); } | STRING { - default_value_packer.pack_string($1); + current_packer->pack_string($1); } | HEX_STRING { - default_value_packer.pack_literal_value($1); + current_packer->pack_literal_value($1); } | '{' { - default_value_packer.push(); + current_packer->push(); } - default_array '}' + array '}' { - default_value_packer.pop(); + current_packer->pop(); +} + | '[' +{ + current_packer->push(); +} + array ']' +{ + current_packer->pop(); +} + | '(' +{ + current_packer->push(); +} + array ')' +{ + current_packer->pop(); } | INTEGER '*' INTEGER { for (int i = 0; i < $3; i++) { - default_value_packer.pack_int($1); + current_packer->pack_int($1); } } | REAL '*' INTEGER { for (int i = 0; i < $3; i++) { - default_value_packer.pack_double($1); + current_packer->pack_double($1); } } | HEX_STRING '*' INTEGER { for (int i = 0; i < $3; i++) { - default_value_packer.pack_literal_value($1); + current_packer->pack_literal_value($1); } } ; -default_array: - empty - | default_array_def maybe_comma +array: + maybe_comma + | array_def maybe_comma ; maybe_comma: @@ -337,9 +387,9 @@ maybe_comma: | ',' ; -default_array_def: - default_value - | default_array_def ',' default_value +array_def: + parameter_value + | array_def ',' parameter_value ; type_token: @@ -494,3 +544,4 @@ molecular_atom_list: empty: ; + diff --git a/direct/src/dcparser/dcParserDefs.h b/direct/src/dcparser/dcParserDefs.h index af70334d89..e7fe84f442 100644 --- a/direct/src/dcparser/dcParserDefs.h +++ b/direct/src/dcparser/dcParserDefs.h @@ -25,8 +25,12 @@ class DCFile; class DCClass; class DCAtomicField; +class DCParameter; +class DCPacker; void dc_init_parser(istream &in, const string &filename, DCFile &file); +void dc_init_parser_parameter_value(istream &in, const string &filename, + DCPacker &packer); void dc_cleanup_parser(); int dcyyparse(); @@ -45,6 +49,7 @@ public: DCClass *dclass; DCAtomicField *atomic; DCSubatomicType subatomic; + DCParameter *parameter; } u; string str; }; diff --git a/direct/src/dcparser/dcSimpleType.cxx b/direct/src/dcparser/dcSimpleParameter.cxx old mode 100755 new mode 100644 similarity index 90% rename from direct/src/dcparser/dcSimpleType.cxx rename to direct/src/dcparser/dcSimpleParameter.cxx index 3e5495b1b7..b879656255 --- a/direct/src/dcparser/dcSimpleType.cxx +++ b/direct/src/dcparser/dcSimpleParameter.cxx @@ -1,4 +1,4 @@ -// Filename: dcSimpleType.cxx +// Filename: dcSimpleParameter.cxx // Created by: drose (15Jun04) // //////////////////////////////////////////////////////////////////// @@ -16,20 +16,20 @@ // //////////////////////////////////////////////////////////////////// -#include "dcSimpleType.h" +#include "dcSimpleParameter.h" #include "dcPackData.h" #include "hashGenerator.h" -DCSimpleType::NestedFieldMap DCSimpleType::_nested_field_map; -DCSimpleType::Uint32Uint8Type *DCSimpleType::_uint32uint8_type = NULL; +DCSimpleParameter::NestedFieldMap DCSimpleParameter::_nested_field_map; +DCSimpleParameter::Uint32Uint8Type *DCSimpleParameter::_uint32uint8_type = NULL; //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::Constructor +// Function: DCSimpleParameter::Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// -DCSimpleType:: -DCSimpleType(DCSubatomicType type, int divisor) : +DCSimpleParameter:: +DCSimpleParameter(DCSubatomicType type, int divisor) : _type(type), _divisor(divisor) { @@ -184,38 +184,38 @@ DCSimpleType(DCSubatomicType type, int divisor) : } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::as_simple_type +// Function: DCSimpleParameter::as_simple_parameter // Access: Published, Virtual // Description: //////////////////////////////////////////////////////////////////// -DCSimpleType *DCSimpleType:: -as_simple_type() { +DCSimpleParameter *DCSimpleParameter:: +as_simple_parameter() { return this; } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::make_copy +// Function: DCSimpleParameter::make_copy // Access: Published, Virtual // Description: //////////////////////////////////////////////////////////////////// -DCType *DCSimpleType:: +DCParameter *DCSimpleParameter:: make_copy() const { - return new DCSimpleType(*this); + return new DCSimpleParameter(*this); } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::get_type +// Function: DCSimpleParameter::get_type // Access: Published // Description: Returns the particular subatomic type represented by // this instance. //////////////////////////////////////////////////////////////////// -DCSubatomicType DCSimpleType:: +DCSubatomicType DCSimpleParameter:: get_type() const { return _type; } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::get_divisor +// Function: DCSimpleParameter::get_divisor // Access: Published // Description: Returns the divisor associated with this type. This // is 1 by default, but if this is other than one it @@ -224,17 +224,17 @@ get_type() const { // in an integer field). It is only meaningful for // numeric-type fields. //////////////////////////////////////////////////////////////////// -int DCSimpleType:: +int DCSimpleParameter:: get_divisor() const { return _divisor; } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::set_divisor +// Function: DCSimpleParameter::set_divisor // Access: Published // Description: See get_divisor(). //////////////////////////////////////////////////////////////////// -void DCSimpleType:: +void DCSimpleParameter:: set_divisor(int divisor) { _divisor = divisor; if (_pack_type == PT_int || _pack_type == PT_int64) { @@ -243,7 +243,7 @@ set_divisor(int divisor) { } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::has_nested_fields +// Function: DCSimpleParameter::has_nested_fields // Access: Public, Virtual // Description: Returns true if this field type has any nested fields // (and thus expects a push() .. pop() interface to the @@ -251,26 +251,26 @@ set_divisor(int divisor) { // get_num_nested_fields() may be called to determine // how many nested fields are expected. //////////////////////////////////////////////////////////////////// -bool DCSimpleType:: +bool DCSimpleParameter:: has_nested_fields() const { return _is_array; } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::get_num_nested_fields +// Function: DCSimpleParameter::get_num_nested_fields // Access: Public, Virtual // Description: Returns the number of nested fields required by this // field type. These may be array elements or structure // elements. The return value may be -1 to indicate the // number of nested fields is variable. //////////////////////////////////////////////////////////////////// -int DCSimpleType:: +int DCSimpleParameter:: get_num_nested_fields() const { return _is_array ? -1 : 0; } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::get_num_nested_fields +// Function: DCSimpleParameter::get_num_nested_fields // Access: Public, Virtual // Description: This flavor of get_num_nested_fields is used during // unpacking. It returns the number of nested fields to @@ -279,7 +279,7 @@ get_num_nested_fields() const { // pack). This will only be called if // get_length_bytes() returns nonzero. //////////////////////////////////////////////////////////////////// -int DCSimpleType:: +int DCSimpleParameter:: get_num_nested_fields(size_t length_bytes) const { if (_is_array) { return length_bytes / _bytes_per_element; @@ -288,20 +288,20 @@ get_num_nested_fields(size_t length_bytes) const { } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::get_nested_field +// Function: DCSimpleParameter::get_nested_field // Access: Public, Virtual // Description: Returns the DCPackerInterface object that represents // the nth nested field. This may return NULL if there // is no such field (but it shouldn't do this if n is in // the range 0 <= n < get_num_nested_fields()). //////////////////////////////////////////////////////////////////// -DCPackerInterface *DCSimpleType:: +DCPackerInterface *DCSimpleParameter:: get_nested_field(int n) const { return _nested_field; } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::get_length_bytes +// Function: DCSimpleParameter::get_length_bytes // Access: Public, Virtual // Description: If has_nested_fields() returns true, this should // return either 0, 2, or 4, indicating the number of @@ -309,28 +309,28 @@ get_nested_field(int n) const { // record its length. This is respected by push() and // pop(). //////////////////////////////////////////////////////////////////// -size_t DCSimpleType:: +size_t DCSimpleParameter:: get_length_bytes() const { return _type == ST_blob32 ? 4 : 2; } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::get_pack_type +// Function: DCSimpleParameter::get_pack_type // Access: Public, Virtual // Description: Returns the type of value expected by this field. //////////////////////////////////////////////////////////////////// -DCPackType DCSimpleType:: +DCPackType DCSimpleParameter:: get_pack_type() const { return _pack_type; } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::pack_double +// Function: DCSimpleParameter::pack_double // Access: Published, Virtual // Description: Packs the indicated numeric or string value into the // stream. Returns true on success, false on failure. //////////////////////////////////////////////////////////////////// -bool DCSimpleType:: +bool DCSimpleParameter:: pack_double(DCPackData &pack_data, double value) const { double real_value = value * _divisor; int int_value = (int)floor(real_value + 0.5); @@ -399,12 +399,12 @@ pack_double(DCPackData &pack_data, double value) const { } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::pack_int +// Function: DCSimpleParameter::pack_int // Access: Published, Virtual // Description: Packs the indicated numeric or string value into the // stream. Returns true on success, false on failure. //////////////////////////////////////////////////////////////////// -bool DCSimpleType:: +bool DCSimpleParameter:: pack_int(DCPackData &pack_data, int value) const { int int_value = value * _divisor; @@ -482,12 +482,12 @@ pack_int(DCPackData &pack_data, int value) const { } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::pack_int64 +// Function: DCSimpleParameter::pack_int64 // Access: Published, Virtual // Description: Packs the indicated numeric or string value into the // stream. Returns true on success, false on failure. //////////////////////////////////////////////////////////////////// -bool DCSimpleType:: +bool DCSimpleParameter:: pack_int64(DCPackData &pack_data, PN_int64 value) const { PN_int64 int_value = value * _divisor; @@ -558,12 +558,12 @@ pack_int64(DCPackData &pack_data, PN_int64 value) const { } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::pack_string +// Function: DCSimpleParameter::pack_string // Access: Published, Virtual // Description: Packs the indicated numeric or string value into the // stream. Returns true on success, false on failure. //////////////////////////////////////////////////////////////////// -bool DCSimpleType:: +bool DCSimpleParameter:: pack_string(DCPackData &pack_data, const string &value) const { char buffer[4]; @@ -599,12 +599,12 @@ pack_string(DCPackData &pack_data, const string &value) const { } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::unpack_double +// Function: DCSimpleParameter::unpack_double // Access: Public, Virtual // Description: Unpacks the current numeric or string value from the // stream. Returns true on success, false on failure. //////////////////////////////////////////////////////////////////// -bool DCSimpleType:: +bool DCSimpleParameter:: unpack_double(const char *data, size_t length, size_t &p, double &value) const { switch (_type) { case ST_int8: @@ -727,12 +727,12 @@ unpack_double(const char *data, size_t length, size_t &p, double &value) const { } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::unpack_int +// Function: DCSimpleParameter::unpack_int // Access: Public, Virtual // Description: Unpacks the current numeric or string value from the // stream. Returns true on success, false on failure. //////////////////////////////////////////////////////////////////// -bool DCSimpleType:: +bool DCSimpleParameter:: unpack_int(const char *data, size_t length, size_t &p, int &value) const { switch (_type) { case ST_int8: @@ -847,12 +847,12 @@ unpack_int(const char *data, size_t length, size_t &p, int &value) const { } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::unpack_int64 +// Function: DCSimpleParameter::unpack_int64 // Access: Public, Virtual // Description: Unpacks the current numeric or string value from the // stream. Returns true on success, false on failure. //////////////////////////////////////////////////////////////////// -bool DCSimpleType:: +bool DCSimpleParameter:: unpack_int64(const char *data, size_t length, size_t &p, PN_int64 &value) const { switch (_type) { case ST_int8: @@ -975,12 +975,12 @@ unpack_int64(const char *data, size_t length, size_t &p, PN_int64 &value) const } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::unpack_string +// Function: DCSimpleParameter::unpack_string // Access: Public, Virtual // Description: Unpacks the current numeric or string value from the // stream. Returns true on success, false on failure. //////////////////////////////////////////////////////////////////// -bool DCSimpleType:: +bool DCSimpleParameter:: unpack_string(const char *data, size_t length, size_t &p, string &value) const { size_t string_length; @@ -1020,43 +1020,43 @@ unpack_string(const char *data, size_t length, size_t &p, string &value) const { } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::output +// Function: DCSimpleParameter::output // Access: Public, Virtual // Description: //////////////////////////////////////////////////////////////////// -void DCSimpleType:: -output(ostream &out, const string ¶meter_name, bool brief) const { +void DCSimpleParameter:: +output(ostream &out, bool brief) const { out << _type; if (_divisor != 1) { out << " / " << _divisor; } - if (!brief && !parameter_name.empty()) { - out << " " << parameter_name; + if (!brief && !_name.empty()) { + out << " " << _name; } } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::generate_hash +// Function: DCSimpleParameter::generate_hash // Access: Public, Virtual // Description: Accumulates the properties of this type into the // hash. //////////////////////////////////////////////////////////////////// -void DCSimpleType:: +void DCSimpleParameter:: generate_hash(HashGenerator &hashgen) const { - DCType::generate_hash(hashgen); + DCParameter::generate_hash(hashgen); hashgen.add_int(_type); hashgen.add_int(_divisor); } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::create_nested_field +// Function: DCSimpleParameter::create_nested_field // Access: Private, Static -// Description: Creates the one instance of the DCSimpleType +// Description: Creates the one instance of the DCSimpleParameter // corresponding to this combination of type and divisor // if it is not already created. //////////////////////////////////////////////////////////////////// -DCSimpleType *DCSimpleType:: +DCSimpleParameter *DCSimpleParameter:: create_nested_field(DCSubatomicType type, int divisor) { DivisorMap divisor_map = _nested_field_map[type]; DivisorMap::iterator di; @@ -1065,18 +1065,18 @@ create_nested_field(DCSubatomicType type, int divisor) { return (*di).second; } - DCSimpleType *nested_field = new DCSimpleType(type, divisor); + DCSimpleParameter *nested_field = new DCSimpleParameter(type, divisor); divisor_map[divisor] = nested_field; return nested_field; } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::create_uint32uint8_type +// Function: DCSimpleParameter::create_uint32uint8_type // Access: Private, Static // Description: Creates the one instance of the Uint32Uint8Type // object if it is not already created. //////////////////////////////////////////////////////////////////// -DCPackerInterface *DCSimpleType:: +DCPackerInterface *DCSimpleParameter:: create_uint32uint8_type() { if (_uint32uint8_type == NULL) { _uint32uint8_type = new Uint32Uint8Type; @@ -1085,45 +1085,45 @@ create_uint32uint8_type() { } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::Uint32Uint8Type::Constructor +// Function: DCSimpleParameter::Uint32Uint8Type::Constructor // Access: Public // Description: This special packer interface is provided just to // implement uint32uint8array, which is a special kind // of array that consists of nested pairs of (uint32, // uint8) values. //////////////////////////////////////////////////////////////////// -DCSimpleType::Uint32Uint8Type:: +DCSimpleParameter::Uint32Uint8Type:: Uint32Uint8Type() { - _uint32_type = new DCSimpleType(ST_uint32); - _uint8_type = new DCSimpleType(ST_uint8); + _uint32_type = new DCSimpleParameter(ST_uint32); + _uint8_type = new DCSimpleParameter(ST_uint8); } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::Uint32Uint8Type::has_nested_fields +// Function: DCSimpleParameter::Uint32Uint8Type::has_nested_fields // Access: Public, Virtual // Description: //////////////////////////////////////////////////////////////////// -bool DCSimpleType::Uint32Uint8Type:: +bool DCSimpleParameter::Uint32Uint8Type:: has_nested_fields() const { return true; } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::Uint32Uint8Type::get_num_nested_fields +// Function: DCSimpleParameter::Uint32Uint8Type::get_num_nested_fields // Access: Public, Virtual // Description: //////////////////////////////////////////////////////////////////// -int DCSimpleType::Uint32Uint8Type:: +int DCSimpleParameter::Uint32Uint8Type:: get_num_nested_fields() const { return 2; } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::Uint32Uint8Type::get_nested_field +// Function: DCSimpleParameter::Uint32Uint8Type::get_nested_field // Access: Public, Virtual // Description: //////////////////////////////////////////////////////////////////// -DCPackerInterface *DCSimpleType::Uint32Uint8Type:: +DCPackerInterface *DCSimpleParameter::Uint32Uint8Type:: get_nested_field(int n) const { switch (n) { case 0: @@ -1138,11 +1138,11 @@ get_nested_field(int n) const { } //////////////////////////////////////////////////////////////////// -// Function: DCSimpleType::Uint32Uint8Type::get_pack_type +// Function: DCSimpleParameter::Uint32Uint8Type::get_pack_type // Access: Public, Virtual // Description: //////////////////////////////////////////////////////////////////// -DCPackType DCSimpleType::Uint32Uint8Type:: +DCPackType DCSimpleParameter::Uint32Uint8Type:: get_pack_type() const { return PT_struct; } diff --git a/direct/src/dcparser/dcSimpleType.h b/direct/src/dcparser/dcSimpleParameter.h old mode 100755 new mode 100644 similarity index 83% rename from direct/src/dcparser/dcSimpleType.h rename to direct/src/dcparser/dcSimpleParameter.h index d39864ba04..3ff1320820 --- a/direct/src/dcparser/dcSimpleType.h +++ b/direct/src/dcparser/dcSimpleParameter.h @@ -1,4 +1,4 @@ -// Filename: dcSimpleType.h +// Filename: dcSimpleParameter.h // Created by: drose (15Jun04) // //////////////////////////////////////////////////////////////////// @@ -16,15 +16,15 @@ // //////////////////////////////////////////////////////////////////// -#ifndef DCSIMPLETYPE_H -#define DCSIMPLETYPE_H +#ifndef DCSIMPLEPARAMETER_H +#define DCSIMPLEPARAMETER_H #include "dcbase.h" -#include "dcType.h" +#include "dcParameter.h" #include "dcSubatomicType.h" //////////////////////////////////////////////////////////////////// -// Class : DCSimpleType +// Class : DCSimpleParameter // Description : This is the most fundamental kind of parameter type: // a single number or string, one of the DCSubatomicType // elements. It may also optionally have a divisor, @@ -32,13 +32,13 @@ // elements (and represents a fixed-point numeric // convention). //////////////////////////////////////////////////////////////////// -class EXPCL_DIRECT DCSimpleType : public DCType { +class EXPCL_DIRECT DCSimpleParameter : public DCParameter { public: - DCSimpleType(DCSubatomicType type, int divisor = 1); + DCSimpleParameter(DCSubatomicType type, int divisor = 1); PUBLISHED: - virtual DCSimpleType *as_simple_type(); - virtual DCType *make_copy() const; + virtual DCSimpleParameter *as_simple_parameter(); + virtual DCParameter *make_copy() const; DCSubatomicType get_type() const; int get_divisor() const; @@ -62,12 +62,11 @@ public: virtual bool unpack_int64(const char *data, size_t length, size_t &p, PN_int64 &value) const; virtual bool unpack_string(const char *data, size_t length, size_t &p, string &value) const; - virtual void output(ostream &out, const string ¶meter_name, - bool brief) const; + virtual void output(ostream &out, bool brief) const; virtual void generate_hash(HashGenerator &hash) const; private: - static DCSimpleType *create_nested_field(DCSubatomicType type, int divisor); + static DCSimpleParameter *create_nested_field(DCSubatomicType type, int divisor); static DCPackerInterface *create_uint32uint8_type(); private: @@ -83,7 +82,7 @@ private: // The rest of this is to maintain the static list of // DCPackerInterface objects for _nested_field, above. We allocate // each possible object once, and don't delete it. - typedef pmap DivisorMap; + typedef pmap DivisorMap; typedef pmap NestedFieldMap; static NestedFieldMap _nested_field_map; @@ -95,8 +94,8 @@ private: virtual DCPackerInterface *get_nested_field(int n) const; virtual DCPackType get_pack_type() const; - DCSimpleType *_uint32_type; - DCSimpleType *_uint8_type; + DCSimpleParameter *_uint32_type; + DCSimpleParameter *_uint8_type; }; static Uint32Uint8Type *_uint32uint8_type; diff --git a/direct/src/dcparser/dcparser_composite2.cxx b/direct/src/dcparser/dcparser_composite2.cxx index 64727e9966..4c11994d3b 100644 --- a/direct/src/dcparser/dcparser_composite2.cxx +++ b/direct/src/dcparser/dcparser_composite2.cxx @@ -1,6 +1,6 @@ -#include "dcType.cxx" -#include "dcSimpleType.cxx" +#include "dcParameter.cxx" +#include "dcSimpleParameter.cxx" #include "dcField.cxx" #include "dcFile.cxx" #include "dcMolecularField.cxx"