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

This commit is contained in:
David Rose 2005-01-14 22:27:17 +00:00
parent 634ed836a1
commit 98aabb1568
10 changed files with 114 additions and 36 deletions

View File

@ -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:"<<n<<" _fields.size():"<<(int)_fields.size()<<endl;
cerr << *this << " "
<< "n:" << n << " _fields.size():"
<< (int)_fields.size() << endl;
// __asm { int 3 }
}
#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
// <out>.
////////////////////////////////////////////////////////////////////
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
// <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
@ -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
// <out>.
////////////////////////////////////////////////////////////////////
void DCClass::
output(ostream &out, bool brief) const {
output_instance(out, brief, "", "", "");
}
////////////////////////////////////////////////////////////////////
// Function: DCClass::write
// Access: Public, Virtual

View File

@ -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;

View File

@ -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
// <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);
}

View File

@ -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

View File

@ -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
// <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
////////////////////////////////////////////////////////////////////
// Function: DCField::pack_args

View File

@ -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

View File

@ -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
// <out>.
////////////////////////////////////////////////////////////////////
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.

View File

@ -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;

View File

@ -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
// <out>.
////////////////////////////////////////////////////////////////////
void DCTypedef::
output(ostream &out, bool brief) const {
out << "typedef ";
_parameter->output(out, false);
}
////////////////////////////////////////////////////////////////////
// Function: DCTypedef::write
// Access: Public, Virtual

View File

@ -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: