26 _element_type(element_type),
27 _array_size_range(size)
29 set_name(_element_type->get_name());
30 _element_type->set_name(
string());
33 if (_array_size_range.has_one_value()) {
34 _array_size = _array_size_range.get_one_value();
36 _has_range_limits =
true;
39 if (_array_size >= 0 && _element_type->has_fixed_byte_size()) {
40 _has_fixed_byte_size =
true;
41 _fixed_byte_size = _array_size * _element_type->get_fixed_byte_size();
42 _has_fixed_structure =
true;
47 _num_length_bytes = 2;
50 if (_element_type->has_range_limits()) {
51 _has_range_limits =
true;
54 if (_element_type->has_default_value()) {
55 _has_default_value =
true;
58 _has_nested_fields =
true;
59 _num_nested_fields = _array_size;
60 _pack_type = PT_array;
63 if (simple_type !=
nullptr) {
64 if (simple_type->
get_type() == ST_char) {
69 _pack_type = PT_string;
80 _element_type(copy._element_type->make_copy()),
81 _array_size(copy._array_size),
82 _array_size_range(copy._array_size_range)
98 as_array_parameter() {
106 as_array_parameter()
const {
124 return _element_type->is_valid();
132 return _element_type;
184 return _element_type;
195 bool range_error =
false;
196 _array_size_range.
validate(num_nested_fields, range_error);
207 const string &name,
const string &postname)
const {
212 std::ostringstream strm;
215 _array_size_range.output(strm);
218 _element_type->output_instance(out, brief, prename, name,
219 postname + strm.str());
230 _array_size_range.generate_hash(hashgen);
238 bool &pack_error,
bool &range_error)
const {
241 if (simple_type ==
nullptr) {
246 size_t string_length = value.length();
252 _array_size_range.
validate(string_length, range_error);
253 if (_num_length_bytes != 0) {
254 nassertv(_num_length_bytes == 2);
257 pack_data.
append_data(value.data(), string_length);
270 bool &pack_error,
bool &range_error)
const {
273 if (simple_type ==
nullptr) {
278 size_t blob_size = value.size();
284 _array_size_range.
validate(blob_size, range_error);
285 if (_num_length_bytes != 0) {
286 nassertv(_num_length_bytes == 2);
289 pack_data.
append_data((
const char *)value.data(), blob_size);
308 if (_has_default_value && !_default_value_stale) {
314 unsigned int minimum_length = 0;
315 if (!_array_size_range.
is_empty()) {
316 minimum_length = _array_size_range.
get_min(0);
322 for (
unsigned int i = 0; i < minimum_length; i++) {
339 unpack_string(
const char *data,
size_t length,
size_t &p,
string &value,
340 bool &pack_error,
bool &range_error)
const {
343 if (simple_type ==
nullptr) {
348 size_t string_length;
354 if (_num_length_bytes != 0) {
355 string_length = do_unpack_uint16(data + p);
358 nassertv(_array_size >= 0);
359 string_length = _array_size;
361 if (p + string_length > length) {
365 value.assign(data + p, string_length);
378 unpack_blob(
const char *data,
size_t length,
size_t &p, vector_uchar &value,
379 bool &pack_error,
bool &range_error)
const {
382 if (simple_type ==
nullptr) {
393 if (_num_length_bytes != 0) {
394 blob_size = do_unpack_uint16(data + p);
397 nassertv(_array_size >= 0);
398 blob_size = _array_size;
400 if (p + blob_size > length) {
404 value = vector_uchar((
const unsigned char *)data + p,
405 (
const unsigned char *)data + p + blob_size);
419 bool DCArrayParameter::
428 bool DCArrayParameter::
437 bool DCArrayParameter::
446 bool DCArrayParameter::
448 if (_array_size != other->_array_size) {
451 return _element_type->
check_match(other->_element_type);
This represents an array of some other kind of object, meaning this parameter type accepts an arbitra...
int get_array_size() const
Returns the fixed number of elements in this array, or -1 if the array may contain a variable number ...
virtual bool validate_num_nested_fields(int num_nested_fields) const
After a number of fields have been packed via push() .
virtual int calc_num_nested_fields(size_t length_bytes) const
This flavor of get_num_nested_fields is used during unpacking.
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...
virtual DCPackerInterface * get_nested_field(int n) const
Returns the DCPackerInterface object that represents the nth nested field.
virtual void generate_hash(HashGenerator &hashgen) const
Accumulates the properties of this type into the hash.
virtual void pack_string(DCPackData &pack_data, const std::string &value, bool &pack_error, bool &range_error) const
Packs the indicated numeric or string value into the stream.
virtual DCParameter * append_array_specification(const DCUnsignedIntRange &size)
Returns the type represented by this_type[size].
DCParameter * get_element_type() const
Returns the type of the individual elements of this array.
virtual void output_instance(std::ostream &out, bool brief, const std::string &prename, const std::string &name, const std::string &postname) const
Formats the parameter in the C++-like dc syntax as a typename and identifier.
virtual void pack_blob(DCPackData &pack_data, const std::vector< unsigned char > &value, bool &pack_error, bool &range_error) const
Packs the indicated numeric or string value into the stream.
virtual bool is_valid() const
Returns false if the type is an invalid type (e.g.
virtual void unpack_string(const char *data, size_t length, size_t &p, std::string &value, bool &pack_error, bool &range_error) const
Unpacks the current numeric or string value from the stream.
virtual void unpack_blob(const char *data, size_t length, size_t &p, std::vector< unsigned char > &value, bool &pack_error, bool &range_error) const
Unpacks the current numeric or string value from the stream.
This represents a class (or struct) object used as a parameter itself.
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...
Number get_min(int n) const
Returns the minimum value defined by the nth component.
void validate(Number num, bool &range_error) const
Convenience function to validate the indicated number.
bool is_empty() const
Returns true if the range contains no elements (and thus allows all numbers), false if it contains at...
This is a block of data that receives the results of DCPacker.
void append_data(const char *buffer, size_t size)
Adds the indicated bytes to the end of the data.
char * get_write_pointer(size_t size)
Adds the indicated number of bytes to the end of the data without initializing them,...
This defines the internal interface for packing values into a DCField.
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.
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.
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 do_check_match_array_parameter(const DCArrayParameter *other) const
Returns true if this field matches the indicated array parameter, false otherwise.
This class can be used for packing a series of numeric and string data into a binary stream,...
void push()
Marks the beginning of a nested series of fields.
void begin_pack(const DCPackerInterface *root)
Begins a packing session.
void pop()
Marks the end of a nested series of fields.
bool end_pack()
Finishes a packing session.
const char * get_data() const
Returns the beginning of the data buffer.
void pack_default_value()
Adds the default value for the current element into the stream.
size_t get_length() const
Returns the current length of the buffer.
Represents the type specification for a single parameter within a field specification.
virtual void generate_hash(HashGenerator &hashgen) const
Accumulates the properties of this type into the hash.
const DCTypedef * get_typedef() const
If this type has been referenced from a typedef, returns the DCTypedef instance, or NULL if the type ...
void output_typedef_name(std::ostream &out, bool brief, const std::string &prename, const std::string &name, const std::string &postname) const
Formats the instance like output_instance, but uses the typedef name instead.
virtual DCParameter * append_array_specification(const DCUnsignedIntRange &size)
Returns the type represented by this_type[size].
This is the most fundamental kind of parameter type: a single number or string, one of the DCSubatomi...
DCSubatomicType get_type() const
Returns the particular subatomic type represented by this instance.
This class generates an arbitrary hash number from a sequence of ints.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.