mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 01:07:51 -04:00
integrate class fields and parameters
This commit is contained in:
parent
7f1efe3c04
commit
d52e9cc184
@ -25,81 +25,13 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: DCAtomicField::ElementType::Constructor
|
// Function: DCAtomicField::Constructor
|
||||||
// Access: Public
|
|
||||||
// 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(DCParameter *param) {
|
|
||||||
_param = param;
|
|
||||||
_has_default_value = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: DCAtomicField::ElementType::Copy Constructor
|
|
||||||
// Access: Public
|
// Access: Public
|
||||||
// Description:
|
// Description:
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
DCAtomicField::ElementType::
|
DCAtomicField::
|
||||||
ElementType(const DCAtomicField::ElementType ©) :
|
DCAtomicField(const string &name) : DCField(name) {
|
||||||
_param(copy._param->make_copy()),
|
_flags = 0;
|
||||||
_default_value(copy._default_value),
|
|
||||||
_has_default_value(copy._has_default_value)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: DCAtomicField::ElementType::Copy Assignment Operator
|
|
||||||
// Access: Public
|
|
||||||
// Description:
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
void DCAtomicField::ElementType::
|
|
||||||
operator = (const DCAtomicField::ElementType ©) {
|
|
||||||
delete _param;
|
|
||||||
_param = copy._param->make_copy();
|
|
||||||
_default_value = copy._default_value;
|
|
||||||
_has_default_value = copy._has_default_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: DCAtomicField::ElementType::Destructor
|
|
||||||
// Access: Public
|
|
||||||
// Description:
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
DCAtomicField::ElementType::
|
|
||||||
~ElementType() {
|
|
||||||
delete _param;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: DCAtomicField::ElementType::set_default_value
|
|
||||||
// Access: Public
|
|
||||||
// Description:
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
void DCAtomicField::ElementType::
|
|
||||||
set_default_value(const string &default_value) {
|
|
||||||
_default_value = default_value;
|
|
||||||
_has_default_value = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: DCAtomicField::ElementType::output
|
|
||||||
// Access: Public
|
|
||||||
// Description:
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
void DCAtomicField::ElementType::
|
|
||||||
output(ostream &out, bool brief) const {
|
|
||||||
_param->output(out, brief);
|
|
||||||
|
|
||||||
if (!brief && _has_default_value) {
|
|
||||||
out << " = ";
|
|
||||||
DCPacker packer;
|
|
||||||
packer.begin_unpack(_default_value, _param);
|
|
||||||
packer.unpack_and_format(out);
|
|
||||||
packer.end_unpack();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -333,16 +265,6 @@ compare_flags(const DCAtomicField &other) const {
|
|||||||
return _flags == other._flags;
|
return _flags == other._flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: DCAtomicField::Constructor
|
|
||||||
// Access: Public
|
|
||||||
// Description:
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
DCAtomicField::
|
|
||||||
DCAtomicField(const string &name) : DCField(name) {
|
|
||||||
_flags = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: DCAtomicField::write
|
// Function: DCAtomicField::write
|
||||||
// Access: Public, Virtual
|
// Access: Public, Virtual
|
||||||
@ -461,3 +383,81 @@ void DCAtomicField::
|
|||||||
add_flag(enum Flags flag) {
|
add_flag(enum Flags flag) {
|
||||||
_flags |= flag;
|
_flags |= flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: DCAtomicField::ElementType::Constructor
|
||||||
|
// Access: Public
|
||||||
|
// 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(DCParameter *param) {
|
||||||
|
_param = param;
|
||||||
|
_has_default_value = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: DCAtomicField::ElementType::Copy Constructor
|
||||||
|
// Access: Public
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
DCAtomicField::ElementType::
|
||||||
|
ElementType(const DCAtomicField::ElementType ©) :
|
||||||
|
_param(copy._param->make_copy()),
|
||||||
|
_default_value(copy._default_value),
|
||||||
|
_has_default_value(copy._has_default_value)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: DCAtomicField::ElementType::Copy Assignment Operator
|
||||||
|
// Access: Public
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void DCAtomicField::ElementType::
|
||||||
|
operator = (const DCAtomicField::ElementType ©) {
|
||||||
|
delete _param;
|
||||||
|
_param = copy._param->make_copy();
|
||||||
|
_default_value = copy._default_value;
|
||||||
|
_has_default_value = copy._has_default_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: DCAtomicField::ElementType::Destructor
|
||||||
|
// Access: Public
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
DCAtomicField::ElementType::
|
||||||
|
~ElementType() {
|
||||||
|
delete _param;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: DCAtomicField::ElementType::set_default_value
|
||||||
|
// Access: Public
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void DCAtomicField::ElementType::
|
||||||
|
set_default_value(const string &default_value) {
|
||||||
|
_default_value = default_value;
|
||||||
|
_has_default_value = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: DCAtomicField::ElementType::output
|
||||||
|
// Access: Public
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void DCAtomicField::ElementType::
|
||||||
|
output(ostream &out, bool brief) const {
|
||||||
|
_param->output(out, brief);
|
||||||
|
|
||||||
|
if (!brief && _has_default_value) {
|
||||||
|
out << " = ";
|
||||||
|
DCPacker packer;
|
||||||
|
packer.begin_unpack(_default_value, _param);
|
||||||
|
packer.unpack_and_format(out);
|
||||||
|
packer.end_unpack();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -36,6 +36,9 @@
|
|||||||
// remote procedure method.
|
// remote procedure method.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
class EXPCL_DIRECT DCAtomicField : public DCField {
|
class EXPCL_DIRECT DCAtomicField : public DCField {
|
||||||
|
public:
|
||||||
|
DCAtomicField(const string &name);
|
||||||
|
|
||||||
PUBLISHED:
|
PUBLISHED:
|
||||||
virtual DCAtomicField *as_atomic_field();
|
virtual DCAtomicField *as_atomic_field();
|
||||||
|
|
||||||
@ -62,7 +65,6 @@ PUBLISHED:
|
|||||||
bool compare_flags(const DCAtomicField &other) const;
|
bool compare_flags(const DCAtomicField &other) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DCAtomicField(const string &name);
|
|
||||||
virtual void write(ostream &out, bool brief, int indent_level) const;
|
virtual void write(ostream &out, bool brief, int indent_level) const;
|
||||||
virtual void generate_hash(HashGenerator &hashgen) const;
|
virtual void generate_hash(HashGenerator &hashgen) const;
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
#include "dcClass.h"
|
#include "dcClass.h"
|
||||||
#include "dcAtomicField.h"
|
#include "dcAtomicField.h"
|
||||||
#include "dcParameter.h"
|
|
||||||
#include "hashGenerator.h"
|
#include "hashGenerator.h"
|
||||||
#include "dcindent.h"
|
#include "dcindent.h"
|
||||||
#include "dcmsgtypes.h"
|
#include "dcmsgtypes.h"
|
||||||
@ -163,97 +162,6 @@ get_inherited_field(int n) const {
|
|||||||
return get_field(n);
|
return get_field(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: DCClass::get_num_parameters
|
|
||||||
// Access: Published
|
|
||||||
// Description: Returns the number of parameters defined directly in
|
|
||||||
// this class, ignoring inheritance.
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
int DCClass::
|
|
||||||
get_num_parameters() const {
|
|
||||||
return _parameters.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: DCClass::get_parameter
|
|
||||||
// Access: Published
|
|
||||||
// Description: Returns the nth parameter in the class. This is not
|
|
||||||
// necessarily the parameter with index n; this is the
|
|
||||||
// nth parameter defined in the class directly, ignoring
|
|
||||||
// inheritance.
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
DCParameter *DCClass::
|
|
||||||
get_parameter(int n) const {
|
|
||||||
nassertr_always(n >= 0 && n < (int)_parameters.size(), NULL);
|
|
||||||
return _parameters[n];
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: DCClass::get_parameter_by_name
|
|
||||||
// Access: Published
|
|
||||||
// Description: Returns a pointer to the DCParameter that shares the
|
|
||||||
// indicated name. If the named parameter is not found
|
|
||||||
// in the current class, the parent classes will be
|
|
||||||
// searched, so the value returned may not actually be a
|
|
||||||
// parameter within this class. Returns NULL if there
|
|
||||||
// is no such parameter defined.
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
DCParameter *DCClass::
|
|
||||||
get_parameter_by_name(const string &name) const {
|
|
||||||
ParametersByName::const_iterator ni;
|
|
||||||
ni = _parameters_by_name.find(name);
|
|
||||||
if (ni != _parameters_by_name.end()) {
|
|
||||||
return (*ni).second;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We didn't have such a parameter, so check our parents.
|
|
||||||
Parents::const_iterator pi;
|
|
||||||
for (pi = _parents.begin(); pi != _parents.end(); ++pi) {
|
|
||||||
DCParameter *result = (*pi)->get_parameter_by_name(name);
|
|
||||||
if (result != (DCParameter *)NULL) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Nobody knew what this parameter is.
|
|
||||||
return (DCParameter *)NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: DCClass::get_num_inherited_parameters
|
|
||||||
// Access: Published
|
|
||||||
// Description: Returns the total number of parameters defined in
|
|
||||||
// this class and all ancestor classes.
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
int DCClass::
|
|
||||||
get_num_inherited_parameters() const {
|
|
||||||
if (!_parents.empty()) {
|
|
||||||
// This won't work for multiple dclass inheritance.
|
|
||||||
return _parents.front()->get_num_inherited_parameters() + get_num_parameters();
|
|
||||||
}
|
|
||||||
return get_num_parameters();
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: DCClass::get_inherited_parameter
|
|
||||||
// Access: Published
|
|
||||||
// Description: Returns the nth parameter parameter in the class and
|
|
||||||
// all of its ancestors.
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
DCParameter *DCClass::
|
|
||||||
get_inherited_parameter(int n) const {
|
|
||||||
if (!_parents.empty()) {
|
|
||||||
// This won't work for multiple dclass inheritance.
|
|
||||||
int psize = _parents.front()->get_num_inherited_parameters();
|
|
||||||
if (n < psize) {
|
|
||||||
return _parents.front()->get_inherited_parameter(n);
|
|
||||||
}
|
|
||||||
|
|
||||||
n -= psize;
|
|
||||||
}
|
|
||||||
return get_parameter(n);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: DCClass::is_struct
|
// Function: DCClass::is_struct
|
||||||
// Access: Public
|
// Access: Public
|
||||||
@ -701,15 +609,6 @@ write(ostream &out, bool brief, int indent_level) const {
|
|||||||
(*fi)->write(out, brief, indent_level + 2);
|
(*fi)->write(out, brief, indent_level + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_fields.empty() && !_parameters.empty()) {
|
|
||||||
out << "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
Parameters::const_iterator pi;
|
|
||||||
for (pi = _parameters.begin(); pi != _parameters.end(); ++pi) {
|
|
||||||
(*pi)->write(out, brief, indent_level + 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
indent(out, indent_level) << "};\n";
|
indent(out, indent_level) << "};\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -734,14 +633,6 @@ generate_hash(HashGenerator &hashgen) const {
|
|||||||
for (fi = _fields.begin(); fi != _fields.end(); ++fi) {
|
for (fi = _fields.begin(); fi != _fields.end(); ++fi) {
|
||||||
(*fi)->generate_hash(hashgen);
|
(*fi)->generate_hash(hashgen);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_parameters.empty()) {
|
|
||||||
hashgen.add_int(_parameters.size());
|
|
||||||
Parameters::const_iterator pi;
|
|
||||||
for (pi = _parameters.begin(); pi != _parameters.end(); ++pi) {
|
|
||||||
(*pi)->generate_hash(hashgen);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -767,32 +658,6 @@ add_field(DCField *field) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: DCClass::add_parameter
|
|
||||||
// Access: Public
|
|
||||||
// Description: Adds the newly-allocated parameter to the class. The
|
|
||||||
// class becomes the owner of the pointer and will
|
|
||||||
// delete it when it destructs.
|
|
||||||
//
|
|
||||||
// The parameters are only useful for classes that will
|
|
||||||
// themselves be used as parameters; DistributedObjects
|
|
||||||
// in their own right cannot use free parameters.
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
bool DCClass::
|
|
||||||
add_parameter(DCParameter *parameter) {
|
|
||||||
if (!parameter->get_name().empty()) {
|
|
||||||
bool inserted = _parameters_by_name.insert
|
|
||||||
(ParametersByName::value_type(parameter->get_name(), parameter)).second;
|
|
||||||
|
|
||||||
if (!inserted) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_parameters.push_back(parameter);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: DCClass::add_parent
|
// Function: DCClass::add_parent
|
||||||
// Access: Public
|
// Access: Public
|
||||||
|
@ -47,13 +47,6 @@ PUBLISHED:
|
|||||||
int get_num_inherited_fields() const;
|
int get_num_inherited_fields() const;
|
||||||
DCField *get_inherited_field(int n) const;
|
DCField *get_inherited_field(int n) const;
|
||||||
|
|
||||||
int get_num_parameters() const;
|
|
||||||
DCParameter *get_parameter(int n) const;
|
|
||||||
DCParameter *get_parameter_by_name(const string &name) const;
|
|
||||||
|
|
||||||
int get_num_inherited_parameters() const;
|
|
||||||
DCParameter *get_inherited_parameter(int n) const;
|
|
||||||
|
|
||||||
bool is_struct() const;
|
bool is_struct() const;
|
||||||
bool is_bogus_class() const;
|
bool is_bogus_class() const;
|
||||||
|
|
||||||
@ -90,7 +83,6 @@ public:
|
|||||||
void generate_hash(HashGenerator &hashgen) const;
|
void generate_hash(HashGenerator &hashgen) const;
|
||||||
|
|
||||||
bool add_field(DCField *field);
|
bool add_field(DCField *field);
|
||||||
bool add_parameter(DCParameter *parameter);
|
|
||||||
void add_parent(DCClass *parent);
|
void add_parent(DCClass *parent);
|
||||||
void set_number(int number);
|
void set_number(int number);
|
||||||
|
|
||||||
@ -109,12 +101,6 @@ private:
|
|||||||
typedef pmap<string, DCField *> FieldsByName;
|
typedef pmap<string, DCField *> FieldsByName;
|
||||||
FieldsByName _fields_by_name;
|
FieldsByName _fields_by_name;
|
||||||
|
|
||||||
typedef pvector<DCParameter *> Parameters;
|
|
||||||
Parameters _parameters;
|
|
||||||
|
|
||||||
typedef pmap<string, DCParameter *> ParametersByName;
|
|
||||||
ParametersByName _parameters_by_name;
|
|
||||||
|
|
||||||
#ifdef HAVE_PYTHON
|
#ifdef HAVE_PYTHON
|
||||||
PyObject *_class_def;
|
PyObject *_class_def;
|
||||||
#endif
|
#endif
|
||||||
|
@ -32,8 +32,7 @@ DCClassParameter(DCClass *dclass) :
|
|||||||
set_name(dclass->get_name());
|
set_name(dclass->get_name());
|
||||||
|
|
||||||
_has_nested_fields = true;
|
_has_nested_fields = true;
|
||||||
_num_fields = _dclass->get_num_inherited_fields();
|
_num_nested_fields = _dclass->get_num_inherited_fields();
|
||||||
_num_nested_fields = _num_fields + _dclass->get_num_inherited_parameters();
|
|
||||||
_pack_type = PT_class;
|
_pack_type = PT_class;
|
||||||
|
|
||||||
// If all of the nested fields have a fixed byte size, then so does
|
// If all of the nested fields have a fixed byte size, then so does
|
||||||
@ -56,8 +55,7 @@ DCClassParameter(DCClass *dclass) :
|
|||||||
DCClassParameter::
|
DCClassParameter::
|
||||||
DCClassParameter(const DCClassParameter ©) :
|
DCClassParameter(const DCClassParameter ©) :
|
||||||
DCParameter(copy),
|
DCParameter(copy),
|
||||||
_dclass(copy._dclass),
|
_dclass(copy._dclass)
|
||||||
_num_fields(copy._num_fields)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,11 +111,7 @@ get_class() const {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
DCPackerInterface *DCClassParameter::
|
DCPackerInterface *DCClassParameter::
|
||||||
get_nested_field(int n) const {
|
get_nested_field(int n) const {
|
||||||
if (n < _num_fields) {
|
return _dclass->get_inherited_field(n);
|
||||||
return _dclass->get_inherited_field(n);
|
|
||||||
} else {
|
|
||||||
return _dclass->get_inherited_parameter(n - _num_fields);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
@ -51,7 +51,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
DCClass *_dclass;
|
DCClass *_dclass;
|
||||||
int _num_fields;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -21,6 +21,31 @@
|
|||||||
#include "hashGenerator.h"
|
#include "hashGenerator.h"
|
||||||
#include "dcmsgtypes.h"
|
#include "dcmsgtypes.h"
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: DCField::Constructor
|
||||||
|
// Access: Public
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
DCField::
|
||||||
|
DCField(const string &name) : DCPackerInterface(name) {
|
||||||
|
_number = 0;
|
||||||
|
_has_nested_fields = true;
|
||||||
|
_num_nested_fields = 0;
|
||||||
|
_pack_type = PT_field;
|
||||||
|
|
||||||
|
_has_fixed_byte_size = true;
|
||||||
|
_fixed_byte_size = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: DCField::Destructor
|
||||||
|
// Access: Public, Virtual
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
DCField::
|
||||||
|
~DCField() {
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: DCField::get_number
|
// Function: DCField::get_number
|
||||||
// Access: Published
|
// Access: Published
|
||||||
@ -57,6 +82,16 @@ as_molecular_field() {
|
|||||||
return (DCMolecularField *)NULL;
|
return (DCMolecularField *)NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: DCField::as_parameter
|
||||||
|
// Access: Published, Virtual
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
DCParameter *DCField::
|
||||||
|
as_parameter() {
|
||||||
|
return (DCParameter *)NULL;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: DCField::format_data
|
// Function: DCField::format_data
|
||||||
// Access: Published
|
// Access: Published
|
||||||
@ -278,31 +313,6 @@ ai_format_update(int do_id, int to_id, int from_id, PyObject *args) const {
|
|||||||
#endif // HAVE_PYTHON
|
#endif // HAVE_PYTHON
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: DCField::Constructor
|
|
||||||
// Access: Public
|
|
||||||
// Description:
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
DCField::
|
|
||||||
DCField(const string &name) : DCPackerInterface(name) {
|
|
||||||
_number = 0;
|
|
||||||
_has_nested_fields = true;
|
|
||||||
_num_nested_fields = 0;
|
|
||||||
_pack_type = PT_field;
|
|
||||||
|
|
||||||
_has_fixed_byte_size = true;
|
|
||||||
_fixed_byte_size = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: DCField::Destructor
|
|
||||||
// Access: Public, Virtual
|
|
||||||
// Description:
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
DCField::
|
|
||||||
~DCField() {
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: DCField::generate_hash
|
// Function: DCField::generate_hash
|
||||||
// Access: Public, Virtual
|
// Access: Public, Virtual
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
class DCAtomicField;
|
class DCAtomicField;
|
||||||
class DCMolecularField;
|
class DCMolecularField;
|
||||||
|
class DCParameter;
|
||||||
class HashGenerator;
|
class HashGenerator;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -33,11 +34,16 @@ class HashGenerator;
|
|||||||
// or molecular.
|
// or molecular.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
class EXPCL_DIRECT DCField : public DCPackerInterface {
|
class EXPCL_DIRECT DCField : public DCPackerInterface {
|
||||||
|
public:
|
||||||
|
DCField(const string &name = string());
|
||||||
|
virtual ~DCField();
|
||||||
|
|
||||||
PUBLISHED:
|
PUBLISHED:
|
||||||
int get_number() const;
|
int get_number() const;
|
||||||
|
|
||||||
virtual DCAtomicField *as_atomic_field();
|
virtual DCAtomicField *as_atomic_field();
|
||||||
virtual DCMolecularField *as_molecular_field();
|
virtual DCMolecularField *as_molecular_field();
|
||||||
|
virtual DCParameter *as_parameter();
|
||||||
|
|
||||||
string format_data(const string &packed_data);
|
string format_data(const string &packed_data);
|
||||||
string parse_string(const string &formatted_string);
|
string parse_string(const string &formatted_string);
|
||||||
@ -55,8 +61,6 @@ PUBLISHED:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DCField(const string &name);
|
|
||||||
virtual ~DCField();
|
|
||||||
virtual void write(ostream &out, bool brief, int indent_level) const=0;
|
virtual void write(ostream &out, bool brief, int indent_level) const=0;
|
||||||
virtual void generate_hash(HashGenerator &hashgen) const;
|
virtual void generate_hash(HashGenerator &hashgen) const;
|
||||||
|
|
||||||
|
@ -23,9 +23,18 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: DCMolecularField::Constructor
|
||||||
|
// Access: Public
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
DCMolecularField::
|
||||||
|
DCMolecularField(const string &name) : DCField(name) {
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: DCMolecularField::as_molecular_field
|
// Function: DCMolecularField::as_molecular_field
|
||||||
// Access: Public, Virtual
|
// Access: Published, Virtual
|
||||||
// Description: Returns the same field pointer converted to a
|
// Description: Returns the same field pointer converted to a
|
||||||
// molecular field pointer, if this is in fact a
|
// molecular field pointer, if this is in fact a
|
||||||
// molecular field; otherwise, returns NULL.
|
// molecular field; otherwise, returns NULL.
|
||||||
@ -37,7 +46,7 @@ as_molecular_field() {
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: DCMolecularField::get_num_atomics
|
// Function: DCMolecularField::get_num_atomics
|
||||||
// Access: Public
|
// Access: Published
|
||||||
// Description: Returns the number of atomic fields that make up this
|
// Description: Returns the number of atomic fields that make up this
|
||||||
// molecular field.
|
// molecular field.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -48,7 +57,7 @@ get_num_atomics() const {
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: DCMolecularField::get_atomic
|
// Function: DCMolecularField::get_atomic
|
||||||
// Access: Public
|
// Access: Published
|
||||||
// Description: Returns the nth atomic field that makes up this
|
// Description: Returns the nth atomic field that makes up this
|
||||||
// molecular field. This may or may not be a field of
|
// molecular field. This may or may not be a field of
|
||||||
// this particular class; it might be defined in a
|
// this particular class; it might be defined in a
|
||||||
@ -60,15 +69,6 @@ get_atomic(int n) const {
|
|||||||
return _fields[n];
|
return _fields[n];
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: DCMolecularField::Constructor
|
|
||||||
// Access: Public
|
|
||||||
// Description:
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
DCMolecularField::
|
|
||||||
DCMolecularField(const string &name) : DCField(name) {
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: DCMolecularField::add_atomic
|
// Function: DCMolecularField::add_atomic
|
||||||
// Access: Public
|
// Access: Public
|
||||||
|
@ -33,6 +33,9 @@ class DCParameter;
|
|||||||
// be treated as a unit.
|
// be treated as a unit.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
class EXPCL_DIRECT DCMolecularField : public DCField {
|
class EXPCL_DIRECT DCMolecularField : public DCField {
|
||||||
|
public:
|
||||||
|
DCMolecularField(const string &name);
|
||||||
|
|
||||||
PUBLISHED:
|
PUBLISHED:
|
||||||
virtual DCMolecularField *as_molecular_field();
|
virtual DCMolecularField *as_molecular_field();
|
||||||
|
|
||||||
@ -40,8 +43,6 @@ PUBLISHED:
|
|||||||
DCAtomicField *get_atomic(int n) const;
|
DCAtomicField *get_atomic(int n) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DCMolecularField(const string &name);
|
|
||||||
|
|
||||||
void add_atomic(DCAtomicField *atomic);
|
void add_atomic(DCAtomicField *atomic);
|
||||||
|
|
||||||
virtual void write(ostream &out, bool brief, int indent_level) const;
|
virtual void write(ostream &out, bool brief, int indent_level) const;
|
||||||
|
@ -30,6 +30,8 @@
|
|||||||
DCParameter::
|
DCParameter::
|
||||||
DCParameter() {
|
DCParameter() {
|
||||||
_typedef = NULL;
|
_typedef = NULL;
|
||||||
|
_has_fixed_byte_size = false;
|
||||||
|
_num_nested_fields = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -39,7 +41,7 @@ DCParameter() {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
DCParameter::
|
DCParameter::
|
||||||
DCParameter(const DCParameter ©) :
|
DCParameter(const DCParameter ©) :
|
||||||
DCPackerInterface(copy),
|
DCField(copy),
|
||||||
_typedef(copy._typedef)
|
_typedef(copy._typedef)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -53,6 +55,16 @@ DCParameter::
|
|||||||
~DCParameter() {
|
~DCParameter() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: DCParameter::as_parameter
|
||||||
|
// Access: Published, Virtual
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
DCParameter *DCParameter::
|
||||||
|
as_parameter() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: DCParameter::as_simple_parameter
|
// Function: DCParameter::as_simple_parameter
|
||||||
// Access: Published, Virtual
|
// Access: Published, Virtual
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#define DCPARAMETER_H
|
#define DCPARAMETER_H
|
||||||
|
|
||||||
#include "dcbase.h"
|
#include "dcbase.h"
|
||||||
#include "dcPackerInterface.h"
|
#include "dcField.h"
|
||||||
|
|
||||||
class DCSimpleParameter;
|
class DCSimpleParameter;
|
||||||
class DCClassParameter;
|
class DCClassParameter;
|
||||||
@ -39,7 +39,7 @@ class HashGenerator;
|
|||||||
// which has the same properties as the referenced type,
|
// which has the same properties as the referenced type,
|
||||||
// but a different name.
|
// but a different name.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
class EXPCL_DIRECT DCParameter : public DCPackerInterface {
|
class EXPCL_DIRECT DCParameter : public DCField {
|
||||||
protected:
|
protected:
|
||||||
DCParameter();
|
DCParameter();
|
||||||
DCParameter(const DCParameter ©);
|
DCParameter(const DCParameter ©);
|
||||||
@ -47,6 +47,7 @@ public:
|
|||||||
virtual ~DCParameter();
|
virtual ~DCParameter();
|
||||||
|
|
||||||
PUBLISHED:
|
PUBLISHED:
|
||||||
|
virtual DCParameter *as_parameter();
|
||||||
virtual DCSimpleParameter *as_simple_parameter();
|
virtual DCSimpleParameter *as_simple_parameter();
|
||||||
virtual DCClassParameter *as_class_parameter();
|
virtual DCClassParameter *as_class_parameter();
|
||||||
virtual DCArrayParameter *as_array_parameter();
|
virtual DCArrayParameter *as_array_parameter();
|
||||||
@ -60,7 +61,7 @@ public:
|
|||||||
void set_typedef(const DCTypedef *dtypedef);
|
void set_typedef(const DCTypedef *dtypedef);
|
||||||
|
|
||||||
void output(ostream &out, bool brief) const;
|
void output(ostream &out, bool brief) const;
|
||||||
void write(ostream &out, bool brief, int indent_level) const;
|
virtual void write(ostream &out, bool brief, int indent_level) const;
|
||||||
virtual void output_instance(ostream &out, const string &prename,
|
virtual void output_instance(ostream &out, const string &prename,
|
||||||
const string &name, const string &postname) const=0;
|
const string &name, const string &postname) const=0;
|
||||||
void output_typedef_name(ostream &out, const string &prename,
|
void output_typedef_name(ostream &out, const string &prename,
|
||||||
|
@ -1240,14 +1240,14 @@ case 28:
|
|||||||
case 33:
|
case 33:
|
||||||
#line 269 "dcParser.yxx"
|
#line 269 "dcParser.yxx"
|
||||||
{
|
{
|
||||||
current_class->add_parameter(yyvsp[-1].u.parameter);
|
current_class->add_field(yyvsp[-1].u.parameter);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 34:
|
case 34:
|
||||||
#line 273 "dcParser.yxx"
|
#line 273 "dcParser.yxx"
|
||||||
{
|
{
|
||||||
if (!current_class->add_parameter(yyvsp[0].u.parameter)) {
|
if (!current_class->add_field(yyvsp[0].u.parameter)) {
|
||||||
yyerror("Duplicate parameter name: " + yyvsp[0].u.parameter->get_name());
|
yyerror("Duplicate field name: " + yyvsp[0].u.parameter->get_name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -267,12 +267,12 @@ dclass_fields:
|
|||||||
| dclass_fields molecular_field
|
| dclass_fields molecular_field
|
||||||
| dclass_fields unnamed_parameter ';'
|
| dclass_fields unnamed_parameter ';'
|
||||||
{
|
{
|
||||||
current_class->add_parameter($2);
|
current_class->add_field($2);
|
||||||
}
|
}
|
||||||
| dclass_fields named_parameter
|
| dclass_fields named_parameter
|
||||||
{
|
{
|
||||||
if (!current_class->add_parameter($2)) {
|
if (!current_class->add_field($2)) {
|
||||||
yyerror("Duplicate parameter name: " + $2->get_name());
|
yyerror("Duplicate field name: " + $2->get_name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
@ -1113,7 +1113,7 @@ unpack_int(const char *data, size_t length, size_t &p, int &value,
|
|||||||
PN_uint64 uint_value = do_unpack_uint64(data + p);
|
PN_uint64 uint_value = do_unpack_uint64(data + p);
|
||||||
_uint64_range.validate(uint_value, range_error);
|
_uint64_range.validate(uint_value, range_error);
|
||||||
value = (int)(unsigned int)uint_value;
|
value = (int)(unsigned int)uint_value;
|
||||||
if (value != uint_value || value < 0) {
|
if ((unsigned int)value != uint_value || value < 0) {
|
||||||
pack_error = true;
|
pack_error = true;
|
||||||
}
|
}
|
||||||
p += 8;
|
p += 8;
|
||||||
@ -1391,7 +1391,7 @@ unpack_int64(const char *data, size_t length, size_t &p, PN_int64 &value,
|
|||||||
PN_uint64 uint_value = do_unpack_uint64(data + p);
|
PN_uint64 uint_value = do_unpack_uint64(data + p);
|
||||||
_uint64_range.validate(uint_value, range_error);
|
_uint64_range.validate(uint_value, range_error);
|
||||||
value = (PN_int64)uint_value;
|
value = (PN_int64)uint_value;
|
||||||
if (value != uint_value) {
|
if (value < 0) {
|
||||||
pack_error = true;
|
pack_error = true;
|
||||||
}
|
}
|
||||||
p += 8;
|
p += 8;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user