Panda3D
dcArrayParameter.h
1 // Filename: dcArrayParameter.h
2 // Created by: drose (17Jun04)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef DCARRAYPARAMETER_H
16 #define DCARRAYPARAMETER_H
17 
18 #include "dcbase.h"
19 #include "dcParameter.h"
20 #include "dcNumericRange.h"
21 
22 ////////////////////////////////////////////////////////////////////
23 // Class : DCArrayParameter
24 // Description : This represents an array of some other kind of
25 // object, meaning this parameter type accepts an
26 // arbitrary (or possibly fixed) number of nested
27 // fields, all of which are of the same type.
28 ////////////////////////////////////////////////////////////////////
29 class EXPCL_DIRECT DCArrayParameter : public DCParameter {
30 public:
31  DCArrayParameter(DCParameter *element_type,
32  const DCUnsignedIntRange &size = DCUnsignedIntRange());
34  virtual ~DCArrayParameter();
35 
36 PUBLISHED:
37  virtual DCArrayParameter *as_array_parameter();
38  virtual const DCArrayParameter *as_array_parameter() const;
39  virtual DCParameter *make_copy() const;
40  virtual bool is_valid() const;
41 
42  DCParameter *get_element_type() const;
43  int get_array_size() const;
44 
45 public:
47 
48  virtual int calc_num_nested_fields(size_t length_bytes) const;
49  virtual DCPackerInterface *get_nested_field(int n) const;
50  virtual bool validate_num_nested_fields(int num_nested_fields) const;
51 
52  virtual void output_instance(ostream &out, bool brief, const string &prename,
53  const string &name, const string &postname) const;
54  virtual void generate_hash(HashGenerator &hashgen) const;
55  virtual void pack_string(DCPackData &pack_data, const string &value,
56  bool &pack_error, bool &range_error) const;
57  virtual bool pack_default_value(DCPackData &pack_data, bool &pack_error) const;
58  virtual void unpack_string(const char *data, size_t length, size_t &p,
59  string &value, bool &pack_error, bool &range_error) const;
60 
61 protected:
62  virtual bool do_check_match(const DCPackerInterface *other) const;
63  virtual bool do_check_match_simple_parameter(const DCSimpleParameter *other) const;
64  virtual bool do_check_match_class_parameter(const DCClassParameter *other) const;
65  virtual bool do_check_match_array_parameter(const DCArrayParameter *other) const;
66 
67 private:
68  DCParameter *_element_type;
69  int _array_size;
70  DCUnsignedIntRange _array_size_range;
71 };
72 
73 #endif
virtual void generate_hash(HashGenerator &hashgen) const
Accumulates the properties of this type into the hash.
This is a block of data that receives the results of DCPacker.
Definition: dcPackData.h:25
virtual bool do_check_match_array_parameter(const DCArrayParameter *other) const
Returns true if this field matches the indicated array parameter, false otherwise.
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...
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...
Definition: dcField.cxx:552
virtual DCPackerInterface * get_nested_field(int n) const
Returns the DCPackerInterface object that represents the nth nested field.
virtual bool do_check_match_simple_parameter(const DCSimpleParameter *other) const
Returns true if this field matches the indicated simple parameter, false otherwise.
virtual DCParameter * append_array_specification(const DCUnsignedIntRange &size)
Returns the type represented by this_type[size].
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.
Represents the type specification for a single parameter within a field specification.
Definition: dcParameter.h:39
This represents an array of some other kind of object, meaning this parameter type accepts an arbitra...
This class generates an arbitrary hash number from a sequence of ints.
Definition: hashGenerator.h:26
virtual bool do_check_match_class_parameter(const DCClassParameter *other) const
Returns true if this field matches the indicated class parameter, false otherwise.
virtual int calc_num_nested_fields(size_t length_bytes) const
This flavor of get_num_nested_fields is used during unpacking.
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 validate_num_nested_fields(int num_nested_fields) const
After a number of fields have been packed via push()
This defines the internal interface for packing values into a DCField.