From 98aabb1568385b9cb3246c6423b3414765f14d19 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 14 Jan 2005 22:27:17 +0000 Subject: [PATCH] regularize output() and write() and make more consistent with other Panda conventions --- direct/src/dcparser/dcClass.cxx | 56 ++++++++++++--------------- direct/src/dcparser/dcClass.h | 6 +-- direct/src/dcparser/dcDeclaration.cxx | 22 +++++++++++ direct/src/dcparser/dcDeclaration.h | 9 +++++ direct/src/dcparser/dcField.cxx | 22 +++++++++++ direct/src/dcparser/dcField.h | 8 ++++ direct/src/dcparser/dcSwitch.cxx | 13 ++++++- direct/src/dcparser/dcSwitch.h | 1 + direct/src/dcparser/dcTypedef.cxx | 12 ++++++ direct/src/dcparser/dcTypedef.h | 1 + 10 files changed, 114 insertions(+), 36 deletions(-) diff --git a/direct/src/dcparser/dcClass.cxx b/direct/src/dcparser/dcClass.cxx index 4f5d508d5b..7e5b67a429 100644 --- a/direct/src/dcparser/dcClass.cxx +++ b/direct/src/dcparser/dcClass.cxx @@ -189,8 +189,9 @@ DCField *DCClass:: get_field(int n) const { #ifndef NDEBUG //[ if (n < 0 || n >= (int)_fields.size()) { - write(cerr, 0); - cerr<<"n:"<. //////////////////////////////////////////////////////////////////// void DCClass:: output(ostream &out) const { - #ifndef NDEBUG //[ - out<<""<<"DCClass"; - #endif //] NDEBUG -} - -//////////////////////////////////////////////////////////////////// -// Function : write -// Access : Published -// Description : Write a string representation of this instance to -// . -//////////////////////////////////////////////////////////////////// -void DCClass:: -write(ostream &out, unsigned int indent) const { - #ifndef NDEBUG //[ - out.width(indent); out<<""<<"DCClass:\n"; - - out.width(indent+2); out<<""<<"_name "<<_name<<"\n"; - out.width(indent+2); out<<""<<"_is_struct "<<_is_struct<<"\n"; - out.width(indent+2); out<<""<<"_bogus_class "<<_bogus_class<<"\n"; - out.width(indent+2); out<<""<<"_number "<<_number<<"\n"; - - //typedef pvector Parents; - //Parents _parents; - //typedef pvector Fields; - //Fields _fields; - //typedef pmap FieldsByName; - //FieldsByName _fields_by_name; - #endif //] NDEBUG + if (_is_struct) { + out << "struct"; + } else { + out << "dclass"; + } + if (!_name.empty()) { + out << " " << _name; + } } #ifdef HAVE_PYTHON @@ -820,6 +801,17 @@ ai_format_generate(PyObject *distobj, int do_id, } #endif // HAVE_PYTHON +//////////////////////////////////////////////////////////////////// +// Function : DCClass::output +// Access : Public, Virtual +// Description : Write a string representation of this instance to +// . +//////////////////////////////////////////////////////////////////// +void DCClass:: +output(ostream &out, bool brief) const { + output_instance(out, brief, "", "", ""); +} + //////////////////////////////////////////////////////////////////// // Function: DCClass::write // Access: Public, Virtual diff --git a/direct/src/dcparser/dcClass.h b/direct/src/dcparser/dcClass.h index 76aad7e38a..2c85da9459 100644 --- a/direct/src/dcparser/dcClass.h +++ b/direct/src/dcparser/dcClass.h @@ -66,10 +66,9 @@ PUBLISHED: INLINE void start_generate(); INLINE void stop_generate(); - - virtual void output(ostream &out) const; - virtual void write(ostream &out, unsigned int indent=0) const; + virtual void output(ostream &out) const; + #ifdef HAVE_PYTHON bool has_class_def() const; void set_class_def(PyObject *class_def); @@ -101,6 +100,7 @@ PUBLISHED: #endif public: + virtual void output(ostream &out, bool brief) const; virtual void write(ostream &out, bool brief, int indent_level) const; void output_instance(ostream &out, bool brief, const string &prename, const string &name, const string &postname) const; diff --git a/direct/src/dcparser/dcDeclaration.cxx b/direct/src/dcparser/dcDeclaration.cxx index 70bfa03da2..cf30bddb06 100644 --- a/direct/src/dcparser/dcDeclaration.cxx +++ b/direct/src/dcparser/dcDeclaration.cxx @@ -67,3 +67,25 @@ const DCSwitch *DCDeclaration:: as_switch() const { return (DCSwitch *)NULL; } + +//////////////////////////////////////////////////////////////////// +// Function : DCDeclaration::output +// Access : Published, Virtual +// Description : Write a string representation of this instance to +// . +//////////////////////////////////////////////////////////////////// +void DCDeclaration:: +output(ostream &out) const { + output(out, true); +} + +//////////////////////////////////////////////////////////////////// +// Function : DCDeclaration:: +// Access : Published +// Description : Write a string representation of this instance to +// . +//////////////////////////////////////////////////////////////////// +void DCDeclaration:: +write(ostream &out, int indent_level) const { + write(out, false, indent_level); +} diff --git a/direct/src/dcparser/dcDeclaration.h b/direct/src/dcparser/dcDeclaration.h index fd0c224205..977e766d10 100644 --- a/direct/src/dcparser/dcDeclaration.h +++ b/direct/src/dcparser/dcDeclaration.h @@ -44,9 +44,18 @@ PUBLISHED: virtual DCSwitch *as_switch(); virtual const DCSwitch *as_switch() const; + virtual void output(ostream &out) const; + void write(ostream &out, int indent_level) const; + public: + virtual void output(ostream &out, bool brief) const=0; virtual void write(ostream &out, bool brief, int indent_level) const=0; }; +INLINE ostream &operator << (ostream &out, const DCDeclaration &decl) { + decl.output(out); + return out; +} + #endif diff --git a/direct/src/dcparser/dcField.cxx b/direct/src/dcparser/dcField.cxx index 3701007f0d..a0cf71c0ac 100644 --- a/direct/src/dcparser/dcField.cxx +++ b/direct/src/dcparser/dcField.cxx @@ -391,6 +391,28 @@ compare_flags(const DCField &other) const { return _flags == other._flags; } +//////////////////////////////////////////////////////////////////// +// Function : DCField::output +// Access : Published +// Description : Write a string representation of this instance to +// . +//////////////////////////////////////////////////////////////////// +void DCField:: +output(ostream &out) const { + output(out, true); +} + +//////////////////////////////////////////////////////////////////// +// Function : DCField:: +// Access : Published +// Description : Write a string representation of this instance to +// . +//////////////////////////////////////////////////////////////////// +void DCField:: +write(ostream &out, int indent_level) const { + write(out, false, indent_level); +} + #ifdef HAVE_PYTHON //////////////////////////////////////////////////////////////////// // Function: DCField::pack_args diff --git a/direct/src/dcparser/dcField.h b/direct/src/dcparser/dcField.h index c85585e4ce..26fd8d8f73 100644 --- a/direct/src/dcparser/dcField.h +++ b/direct/src/dcparser/dcField.h @@ -78,6 +78,9 @@ PUBLISHED: bool compare_flags(const DCField &other) const; + void output(ostream &out) const; + void write(ostream &out, int indent_level) const; + #ifdef HAVE_PYTHON bool pack_args(DCPacker &packer, PyObject *sequence) const; PyObject *unpack_args(DCPacker &packer) const; @@ -139,4 +142,9 @@ private: #endif }; +INLINE ostream &operator << (ostream &out, const DCField &field) { + field.output(out); + return out; +} + #endif diff --git a/direct/src/dcparser/dcSwitch.cxx b/direct/src/dcparser/dcSwitch.cxx index af7de7a46f..909f4d009e 100644 --- a/direct/src/dcparser/dcSwitch.cxx +++ b/direct/src/dcparser/dcSwitch.cxx @@ -253,6 +253,17 @@ apply_switch(const char *value_data, size_t length) const { return NULL; } +//////////////////////////////////////////////////////////////////// +// Function : DCSwitch::output +// Access : Public, Virtual +// Description : Write a string representation of this instance to +// . +//////////////////////////////////////////////////////////////////// +void DCSwitch:: +output(ostream &out, bool brief) const { + output_instance(out, brief, "", "", ""); +} + //////////////////////////////////////////////////////////////////// // Function: DCSwitch::write // Access: Public, Virtual @@ -265,7 +276,7 @@ write(ostream &out, bool brief, int indent_level) const { } //////////////////////////////////////////////////////////////////// -// Function: DCClass::output_instance +// Function: DCSwitch::output_instance // Access: Public // Description: Generates a parseable description of the object to // the indicated output stream. diff --git a/direct/src/dcparser/dcSwitch.h b/direct/src/dcparser/dcSwitch.h index b20f1cd063..7d1e638337 100644 --- a/direct/src/dcparser/dcSwitch.h +++ b/direct/src/dcparser/dcSwitch.h @@ -61,6 +61,7 @@ public: const DCPackerInterface *apply_switch(const char *value_data, size_t length) const; + virtual void output(ostream &out, bool brief) const; virtual void write(ostream &out, bool brief, int indent_level) const; void output_instance(ostream &out, bool brief, const string &prename, const string &name, const string &postname) const; diff --git a/direct/src/dcparser/dcTypedef.cxx b/direct/src/dcparser/dcTypedef.cxx index 6465b82de2..60590a70ee 100644 --- a/direct/src/dcparser/dcTypedef.cxx +++ b/direct/src/dcparser/dcTypedef.cxx @@ -149,6 +149,18 @@ set_number(int number) { _number = number; } +//////////////////////////////////////////////////////////////////// +// Function : DCTypedef::output +// Access : Public, Virtual +// Description : Write a string representation of this instance to +// . +//////////////////////////////////////////////////////////////////// +void DCTypedef:: +output(ostream &out, bool brief) const { + out << "typedef "; + _parameter->output(out, false); +} + //////////////////////////////////////////////////////////////////// // Function: DCTypedef::write // Access: Public, Virtual diff --git a/direct/src/dcparser/dcTypedef.h b/direct/src/dcparser/dcTypedef.h index 418611f14c..df151a4b6e 100644 --- a/direct/src/dcparser/dcTypedef.h +++ b/direct/src/dcparser/dcTypedef.h @@ -48,6 +48,7 @@ public: DCParameter *make_new_parameter() const; void set_number(int number); + virtual void output(ostream &out, bool brief) const; virtual void write(ostream &out, bool brief, int indent_level) const; private: