15 #include "dcAtomicField.h" 16 #include "hashGenerator.h" 18 #include "dcSimpleParameter.h" 29 DCAtomicField(
const string &name,
DCClass *dclass,
33 _bogus_field = bogus_field;
43 Elements::iterator ei;
44 for (ei = _elements.begin(); ei != _elements.end(); ++ei) {
82 return _elements.size();
93 nassertr(n >= 0 && n < (
int)_elements.size(), NULL);
114 nassertr(n >= 0 && n < (
int)_elements.size(), string());
115 return _elements[n]->get_default_value();
128 nassertr(n >= 0 && n < (
int)_elements.size(),
false);
129 return _elements[n]->has_default_value();
145 nassertr(n >= 0 && n < (
int)_elements.size(), string());
146 return _elements[n]->get_name();
158 nassertr(n >= 0 && n < (
int)_elements.size(), ST_invalid);
161 return simple_parameter->get_type();
178 nassertr(n >= 0 && n < (
int)_elements.size(), 1);
181 return simple_parameter->get_divisor();
190 output(ostream &out,
bool brief)
const {
193 if (!_elements.empty()) {
194 Elements::const_iterator ei = _elements.begin();
195 output_element(out, brief, *ei);
197 while (ei != _elements.end()) {
199 output_element(out, brief, *ei);
205 output_keywords(out);
215 write(ostream &out,
bool brief,
int indent_level)
const {
216 indent(out, indent_level);
219 if (!brief && _number >= 0) {
220 out <<
" // field " << _number;
235 hashgen.
add_int(_elements.size());
236 Elements::const_iterator ei;
237 for (ei = _elements.begin(); ei != _elements.end(); ++ei) {
238 (*ei)->generate_hash(hashgen);
254 nassertr(n >= 0 && n < (
int)_elements.size(), NULL);
268 _elements.push_back(element);
269 _num_nested_fields = (int)_elements.size();
272 if (_has_fixed_byte_size) {
276 if (_has_fixed_structure) {
279 if (!_has_range_limits) {
282 if (!_has_default_value) {
285 _default_value_stale =
true;
308 do_check_match_atomic_field(
const DCAtomicField *other)
const {
309 if (_elements.size() != other->_elements.size()) {
312 for (
size_t i = 0; i < _elements.size(); i++) {
313 if (!_elements[i]->
check_match(other->_elements[i])) {
327 output_element(ostream &out,
bool brief,
DCParameter *element)
const {
328 element->output(out, brief);
virtual void generate_hash(HashGenerator &hashgen) const
Accumulates the properties of this field into the hash.
virtual DCAtomicField * as_atomic_field()
Returns the same field pointer converted to an atomic field pointer, if this is in fact an atomic fie...
const string & get_default_value() const
Returns the default value for this field.
bool has_fixed_structure() const
Returns true if this field type always has the same structure regardless of the data in the stream...
void add_int(int num)
Adds another integer to the hash so far.
A single field of a Distributed Class, either atomic or molecular.
DCParameter * get_element(int n) const
Returns the parameter object describing the nth element.
This is the most fundamental kind of parameter type: a single number or string, one of the DCSubatomi...
bool has_fixed_byte_size() const
Returns true if this field type always packs to the same number of bytes, false if it is variable...
Defines a particular DistributedClass as read from an input .dc file.
A single atomic field of a Distributed Class, as read from a .dc file.
virtual void generate_hash(HashGenerator &hashgen) const
Accumulates the properties of this field into the hash.
size_t get_fixed_byte_size() const
If has_fixed_byte_size() returns true, this returns the number of bytes this field type will use...
void add_element(DCParameter *element)
Adds a new element (parameter) to the field.
bool has_range_limits() const
Returns true if this field, or any sub-field of this field, has a limit imposed in the DC file on its...
virtual void write(ostream &out, bool brief, int indent_level) const
Generates a parseable description of the object to the indicated output stream.
int get_num_elements() const
Returns the number of elements (parameters) of the atomic field.
Represents the type specification for a single parameter within a field specification.
DCSubatomicType get_element_type(int n) const
Returns the numeric type of the nth element of the field.
bool check_match(const DCPackerInterface *other) const
Returns true if the other interface is bitwise the same as this oneāthat is, a uint32 only matches a...
bool has_default_value() const
Returns true if a default value has been explicitly established for this field, false otherwise...
This class generates an arbitrary hash number from a sequence of ints.
string unpack_and_format(bool show_field_names=true)
Unpacks an object and formats its value into a syntax suitable for parsing in the dc file (e...
virtual bool do_check_match_atomic_field(const DCAtomicField *other) const
Returns true if this field matches the indicated atomic field, false otherwise.
void generate_hash(HashGenerator &hashgen) const
Accumulates the properties of these keywords into the hash.
This class can be used for packing a series of numeric and string data into a binary stream...
int get_element_divisor(int n) const
Returns the divisor associated with the nth element of the field.
void set_unpack_data(const string &data)
Sets up the unpack_data pointer.
string get_element_default(int n) const
Returns the pre-formatted default value associated with the nth element of the field.
This defines the internal interface for packing values into a DCField.
bool has_element_default(int n) const
Returns true if the nth element of the field has a default value specified, false otherwise...
string get_element_name(int n) const
Returns the name of the nth element of the field.
void begin_unpack(const DCPackerInterface *root)
Begins an unpacking session.
bool end_unpack()
Finishes the unpacking session.
virtual DCPackerInterface * get_nested_field(int n) const
Returns the DCPackerInterface object that represents the nth nested field.