15 #include "dcArrayParameter.h"
16 #include "dcSimpleParameter.h"
17 #include "dcClassParameter.h"
18 #include "hashGenerator.h"
27 _element_type(element_type),
28 _array_size_range(size)
30 set_name(_element_type->get_name());
31 _element_type->set_name(
string());
34 if (_array_size_range.has_one_value()) {
35 _array_size = _array_size_range.get_one_value();
37 _has_range_limits =
true;
40 if (_array_size >= 0 && _element_type->has_fixed_byte_size()) {
41 _has_fixed_byte_size =
true;
42 _fixed_byte_size = _array_size * _element_type->get_fixed_byte_size();
43 _has_fixed_structure =
true;
48 _num_length_bytes = 2;
51 if (_element_type->has_range_limits()) {
52 _has_range_limits =
true;
55 if (_element_type->has_default_value()) {
56 _has_default_value =
true;
59 _has_nested_fields =
true;
60 _num_nested_fields = _array_size;
61 _pack_type = PT_array;
65 if (simple_type->
get_type() == ST_char) {
70 _pack_type = PT_string;
83 _element_type(copy._element_type->make_copy()),
84 _array_size(copy._array_size),
85 _array_size_range(copy._array_size_range)
105 as_array_parameter() {
115 as_array_parameter()
const {
138 return _element_type->is_valid();
149 return _element_type;
214 return _element_type;
229 bool range_error =
false;
230 _array_size_range.
validate(num_nested_fields, range_error);
243 const string &name,
const string &postname)
const {
251 _array_size_range.output(strm);
254 _element_type->output_instance(out, brief, prename, name,
255 postname + strm.str());
269 _array_size_range.generate_hash(hashgen);
280 bool &pack_error,
bool &range_error)
const {
289 size_t string_length = value.length();
295 _array_size_range.
validate(string_length, range_error);
296 if (_num_length_bytes != 0) {
297 nassertv(_num_length_bytes == 2);
300 pack_data.
append_data(value.data(), string_length);
323 if (_has_default_value && !_default_value_stale) {
329 unsigned int minimum_length = 0;
330 if (!_array_size_range.
is_empty()) {
331 minimum_length = _array_size_range.
get_min(0);
337 for (
unsigned int i = 0; i < minimum_length; i++) {
358 bool &pack_error,
bool &range_error)
const {
367 size_t string_length;
373 if (_num_length_bytes != 0) {
374 string_length = do_unpack_uint16(data + p);
377 nassertv(_array_size >= 0);
378 string_length = _array_size;
380 if (p + string_length > length) {
384 value.assign(data + p, string_length);
401 bool DCArrayParameter::
412 bool DCArrayParameter::
423 bool DCArrayParameter::
434 bool DCArrayParameter::
436 if (_array_size != other->_array_size) {
439 return _element_type->
check_match(other->_element_type);
DCSubatomicType get_type() const
Returns the particular subatomic type represented by this instance.
char * get_write_pointer(size_t size)
Adds the indicated number of bytes to the end of the data without initializing them, and returns a pointer to the beginning of the new data.
This represents a single typedef declaration in the dc file.
This is a block of data that receives the results of DCPacker.
virtual bool pack_default_value(DCPackData &pack_data, bool &pack_error) const
Packs the field's specified default value (or a sensible default if no value is specified) into the s...
void append_data(const char *buffer, size_t size)
Adds the indicated bytes to the end of the data.
This represents a class (or struct) object used as a parameter itself.
This is the most fundamental kind of parameter type: a single number or string, one of the DCSubatomi...
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...
virtual DCParameter * append_array_specification(const DCUnsignedIntRange &size)
Returns the type represented by this_type[size].
bool is_empty() const
Returns true if the range contains no elements (and thus allows all numbers), false if it contains at...
const DCTypedef * get_typedef() const
If this type has been referenced from a typedef, returns the DCTypedef instance, or NULL if the type ...
size_t get_length() const
Returns the current length of the buffer.
virtual void pack_string(DCPackData &pack_data, const string &value, bool &pack_error, bool &range_error) const
Packs the indicated numeric or string value into the stream.
virtual void unpack_string(const char *data, size_t length, size_t &p, string &value, bool &pack_error, bool &range_error) const
Unpacks the current numeric or string value from the stream.
virtual bool do_check_match_array_parameter(const DCArrayParameter *other) const
Returns true if this field matches the indicated array parameter, false otherwise.
virtual void generate_hash(HashGenerator &hashgen) const
Accumulates the properties of this type into the hash.
Represents the type specification for a single parameter within a field specification.
void pack_default_value()
Adds the default value for the current element into the stream.
virtual DCParameter * append_array_specification(const DCUnsignedIntRange &size)
Returns the type represented by this_type[size].
This represents an array of some other kind of object, meaning this parameter type accepts an arbitra...
void push()
Marks the beginning of a nested series of fields.
Number get_min(int n) const
Returns the minimum value defined by the nth component.
This class generates an arbitrary hash number from a sequence of ints.
virtual bool pack_default_value(DCPackData &pack_data, bool &pack_error) const
Packs the arrayParameter's specified default value (or a sensible default if no value is specified) i...
void output_typedef_name(ostream &out, bool brief, const string &prename, const string &name, const string &postname) const
Formats the instance like output_instance, but uses the typedef name instead.
void begin_pack(const DCPackerInterface *root)
Begins a packing session.
const char * get_data() const
Returns the beginning of the data buffer.
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 ...
virtual bool validate_num_nested_fields(int num_nested_fields) const
After a number of fields have been packed via push()
virtual bool is_valid() const
Returns false if the type is an invalid type (e.g.
virtual void generate_hash(HashGenerator &hashgen) const
Accumulates the properties of this type into the hash.
This class can be used for packing a series of numeric and string data into a binary stream...
virtual int calc_num_nested_fields(size_t length_bytes) const
This flavor of get_num_nested_fields is used during unpacking.
void validate(Number num, bool &range_error) const
Convenience function to validate the indicated number.
virtual DCPackerInterface * get_nested_field(int n) const
Returns the DCPackerInterface object that represents the nth nested field.
DCParameter * get_element_type() const
Returns the type of the individual elements of this array.
int get_array_size() const
Returns the fixed number of elements in this array, or -1 if the array may contain a variable number ...
bool end_pack()
Finishes a packing session.
virtual void output_instance(ostream &out, bool brief, const string &prename, const string &name, const string &postname) const
Formats the parameter in the C++-like dc syntax as a typename and identifier.
void pop()
Marks the end of a nested series of fields.
This defines the internal interface for packing values into a DCField.
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...