Browse Source

regularize output() and write() and make more consistent with other Panda conventions

David Rose 21 years ago
parent
commit
98aabb1568

+ 24 - 32
direct/src/dcparser/dcClass.cxx

@@ -189,8 +189,9 @@ DCField *DCClass::
 get_field(int n) const {
 get_field(int n) const {
   #ifndef NDEBUG //[
   #ifndef NDEBUG //[
   if (n < 0 || n >= (int)_fields.size()) {
   if (n < 0 || n >= (int)_fields.size()) {
-    write(cerr, 0);
-    cerr<<"n:"<<n<<" _fields.size():"<<(int)_fields.size()<<endl;
+    cerr << *this << " "
+         << "n:" << n << " _fields.size():"
+         << (int)_fields.size() << endl;
     // __asm { int 3 }
     // __asm { int 3 }
   }
   }
   #endif //]
   #endif //]
@@ -268,41 +269,21 @@ get_inherited_field(int n) const {
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function : output
-//       Access : Published
+//     Function : DCClass::output
+//       Access : Published, Virtual
 //  Description : Write a string representation of this instance to
 //  Description : Write a string representation of this instance to
 //                <out>.
 //                <out>.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void DCClass::
 void DCClass::
 output(ostream &out) const {
 output(ostream &out) const {
-  #ifndef NDEBUG //[
-  out<<""<<"DCClass";
-  #endif //] NDEBUG
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function : write
-//       Access : Published
-//  Description : Write a string representation of this instance to
-//                <out>.
-////////////////////////////////////////////////////////////////////
-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<DCClass *> Parents;
-  //Parents _parents;
-  //typedef pvector<DCField *> Fields;
-  //Fields _fields;
-  //typedef pmap<string, DCField *> FieldsByName;
-  //FieldsByName _fields_by_name;
-  #endif //] NDEBUG
+  if (_is_struct) {
+    out << "struct";
+  } else {
+    out << "dclass";
+  }
+  if (!_name.empty()) {
+    out << " " << _name;
+  }
 }
 }
 
 
 #ifdef HAVE_PYTHON
 #ifdef HAVE_PYTHON
@@ -820,6 +801,17 @@ ai_format_generate(PyObject *distobj, int do_id,
 }
 }
 #endif  // HAVE_PYTHON
 #endif  // HAVE_PYTHON
 
 
+////////////////////////////////////////////////////////////////////
+//     Function : DCClass::output
+//       Access : Public, Virtual
+//  Description : Write a string representation of this instance to
+//                <out>.
+////////////////////////////////////////////////////////////////////
+void DCClass::
+output(ostream &out, bool brief) const {
+  output_instance(out, brief, "", "", "");
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: DCClass::write
 //     Function: DCClass::write
 //       Access: Public, Virtual
 //       Access: Public, Virtual

+ 3 - 3
direct/src/dcparser/dcClass.h

@@ -66,10 +66,9 @@ PUBLISHED:
 
 
   INLINE void start_generate();
   INLINE void start_generate();
   INLINE void stop_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
 #ifdef HAVE_PYTHON
   bool has_class_def() const;
   bool has_class_def() const;
   void set_class_def(PyObject *class_def);
   void set_class_def(PyObject *class_def);
@@ -101,6 +100,7 @@ PUBLISHED:
 #endif 
 #endif 
 
 
 public:
 public:
+  virtual void output(ostream &out, bool brief) const;
   virtual void write(ostream &out, bool brief, int indent_level) const;
   virtual void write(ostream &out, bool brief, int indent_level) const;
   void output_instance(ostream &out, bool brief, const string &prename, 
   void output_instance(ostream &out, bool brief, const string &prename, 
                        const string &name, const string &postname) const;
                        const string &name, const string &postname) const;

+ 22 - 0
direct/src/dcparser/dcDeclaration.cxx

@@ -67,3 +67,25 @@ const DCSwitch *DCDeclaration::
 as_switch() const {
 as_switch() const {
   return (DCSwitch *)NULL;
   return (DCSwitch *)NULL;
 }
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function : DCDeclaration::output
+//       Access : Published, Virtual
+//  Description : Write a string representation of this instance to
+//                <out>.
+////////////////////////////////////////////////////////////////////
+void DCDeclaration::
+output(ostream &out) const {
+  output(out, true);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function : DCDeclaration::
+//       Access : Published
+//  Description : Write a string representation of this instance to
+//                <out>.
+////////////////////////////////////////////////////////////////////
+void DCDeclaration::
+write(ostream &out, int indent_level) const {
+  write(out, false, indent_level);
+}

+ 9 - 0
direct/src/dcparser/dcDeclaration.h

@@ -44,9 +44,18 @@ PUBLISHED:
   virtual DCSwitch *as_switch();
   virtual DCSwitch *as_switch();
   virtual const DCSwitch *as_switch() const;
   virtual const DCSwitch *as_switch() const;
 
 
+  virtual void output(ostream &out) const;
+  void write(ostream &out, int indent_level) const;
+
 public:
 public:
+  virtual void output(ostream &out, bool brief) const=0;
   virtual void write(ostream &out, bool brief, int indent_level) 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
 #endif
 
 

+ 22 - 0
direct/src/dcparser/dcField.cxx

@@ -391,6 +391,28 @@ compare_flags(const DCField &other) const {
   return _flags == other._flags;
   return _flags == other._flags;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function : DCField::output
+//       Access : Published
+//  Description : Write a string representation of this instance to
+//                <out>.
+////////////////////////////////////////////////////////////////////
+void DCField::
+output(ostream &out) const {
+  output(out, true);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function : DCField::
+//       Access : Published
+//  Description : Write a string representation of this instance to
+//                <out>.
+////////////////////////////////////////////////////////////////////
+void DCField::
+write(ostream &out, int indent_level) const {
+  write(out, false, indent_level);
+}
+
 #ifdef HAVE_PYTHON
 #ifdef HAVE_PYTHON
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: DCField::pack_args
 //     Function: DCField::pack_args

+ 8 - 0
direct/src/dcparser/dcField.h

@@ -78,6 +78,9 @@ PUBLISHED:
 
 
   bool compare_flags(const DCField &other) const;
   bool compare_flags(const DCField &other) const;
 
 
+  void output(ostream &out) const;
+  void write(ostream &out, int indent_level) const;
+
 #ifdef HAVE_PYTHON
 #ifdef HAVE_PYTHON
   bool pack_args(DCPacker &packer, PyObject *sequence) const;
   bool pack_args(DCPacker &packer, PyObject *sequence) const;
   PyObject *unpack_args(DCPacker &packer) const;
   PyObject *unpack_args(DCPacker &packer) const;
@@ -139,4 +142,9 @@ private:
 #endif
 #endif
 };
 };
 
 
+INLINE ostream &operator << (ostream &out, const DCField &field) {
+  field.output(out);
+  return out;
+}
+
 #endif
 #endif

+ 12 - 1
direct/src/dcparser/dcSwitch.cxx

@@ -253,6 +253,17 @@ apply_switch(const char *value_data, size_t length) const {
   return NULL;
   return NULL;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function : DCSwitch::output
+//       Access : Public, Virtual
+//  Description : Write a string representation of this instance to
+//                <out>.
+////////////////////////////////////////////////////////////////////
+void DCSwitch::
+output(ostream &out, bool brief) const {
+  output_instance(out, brief, "", "", "");
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: DCSwitch::write
 //     Function: DCSwitch::write
 //       Access: Public, Virtual
 //       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
 //       Access: Public
 //  Description: Generates a parseable description of the object to
 //  Description: Generates a parseable description of the object to
 //               the indicated output stream.
 //               the indicated output stream.

+ 1 - 0
direct/src/dcparser/dcSwitch.h

@@ -61,6 +61,7 @@ public:
 
 
   const DCPackerInterface *apply_switch(const char *value_data, size_t length) const;
   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;
   virtual void write(ostream &out, bool brief, int indent_level) const;
   void output_instance(ostream &out, bool brief, const string &prename, 
   void output_instance(ostream &out, bool brief, const string &prename, 
                        const string &name, const string &postname) const;
                        const string &name, const string &postname) const;

+ 12 - 0
direct/src/dcparser/dcTypedef.cxx

@@ -149,6 +149,18 @@ set_number(int number) {
   _number = number;
   _number = number;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function : DCTypedef::output
+//       Access : Public, Virtual
+//  Description : Write a string representation of this instance to
+//                <out>.
+////////////////////////////////////////////////////////////////////
+void DCTypedef::
+output(ostream &out, bool brief) const {
+  out << "typedef ";
+  _parameter->output(out, false);
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: DCTypedef::write
 //     Function: DCTypedef::write
 //       Access: Public, Virtual
 //       Access: Public, Virtual

+ 1 - 0
direct/src/dcparser/dcTypedef.h

@@ -48,6 +48,7 @@ public:
   DCParameter *make_new_parameter() const;
   DCParameter *make_new_parameter() const;
 
 
   void set_number(int number);
   void set_number(int number);
+  virtual void output(ostream &out, bool brief) const;
   virtual void write(ostream &out, bool brief, int indent_level) const;
   virtual void write(ostream &out, bool brief, int indent_level) const;
 
 
 private:
 private: