Panda3D
 All Classes Functions Variables Enumerations
dcSimpleParameter.h
1 // Filename: dcSimpleParameter.h
2 // Created by: drose (15Jun04)
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 DCSIMPLEPARAMETER_H
16 #define DCSIMPLEPARAMETER_H
17 
18 #include "dcbase.h"
19 #include "dcParameter.h"
20 #include "dcSubatomicType.h"
21 #include "dcNumericRange.h"
22 
23 ////////////////////////////////////////////////////////////////////
24 // Class : DCSimpleParameter
25 // Description : This is the most fundamental kind of parameter type:
26 // a single number or string, one of the DCSubatomicType
27 // elements. It may also optionally have a divisor,
28 // which is meaningful only for the numeric type
29 // elements (and represents a fixed-point numeric
30 // convention).
31 ////////////////////////////////////////////////////////////////////
32 class EXPCL_DIRECT DCSimpleParameter : public DCParameter {
33 public:
34  DCSimpleParameter(DCSubatomicType type, unsigned int divisor = 1);
36 
37 PUBLISHED:
38  virtual DCSimpleParameter *as_simple_parameter();
39  virtual const DCSimpleParameter *as_simple_parameter() const;
40  virtual DCParameter *make_copy() const;
41  virtual bool is_valid() const;
42 
43  DCSubatomicType get_type() const;
44  bool has_modulus() const;
45  double get_modulus() const;
46  int get_divisor() const;
47 
48 public:
49  bool is_numeric_type() const;
50  bool set_modulus(double modulus);
51  bool set_divisor(unsigned int divisor);
52  bool set_range(const DCDoubleRange &range);
53 
54  virtual int calc_num_nested_fields(size_t length_bytes) const;
55  virtual DCPackerInterface *get_nested_field(int n) const;
56 
57  virtual void pack_double(DCPackData &pack_data, double value,
58  bool &pack_error, bool &range_error) const;
59  virtual void pack_int(DCPackData &pack_data, int value,
60  bool &pack_error, bool &range_error) const;
61  virtual void pack_uint(DCPackData &pack_data, unsigned int value,
62  bool &pack_error, bool &range_error) const;
63  virtual void pack_int64(DCPackData &pack_data, PN_int64 value,
64  bool &pack_error, bool &range_error) const;
65  virtual void pack_uint64(DCPackData &pack_data, PN_uint64 value,
66  bool &pack_error, bool &range_error) const;
67  virtual void pack_string(DCPackData &pack_data, const string &value,
68  bool &pack_error, bool &range_error) const;
69  virtual bool pack_default_value(DCPackData &pack_data, bool &pack_error) const;
70 
71  virtual void unpack_double(const char *data, size_t length, size_t &p,
72  double &value, bool &pack_error, bool &range_error) const;
73  virtual void unpack_int(const char *data, size_t length, size_t &p,
74  int &value, bool &pack_error, bool &range_error) const;
75  virtual void unpack_uint(const char *data, size_t length, size_t &p,
76  unsigned int &value, bool &pack_error, bool &range_error) const;
77  virtual void unpack_int64(const char *data, size_t length, size_t &p,
78  PN_int64 &value, bool &pack_error, bool &range_error) const;
79  virtual void unpack_uint64(const char *data, size_t length, size_t &p,
80  PN_uint64 &value, bool &pack_error, bool &range_error) const;
81  virtual void unpack_string(const char *data, size_t length, size_t &p,
82  string &value, bool &pack_error, bool &range_error) const;
83  virtual bool unpack_validate(const char *data, size_t length, size_t &p,
84  bool &pack_error, bool &range_error) const;
85  virtual bool unpack_skip(const char *data, size_t length, size_t &p,
86  bool &pack_error) const;
87 
88  virtual void output_instance(ostream &out, bool brief, const string &prename,
89  const string &name, const string &postname) const;
90  virtual void generate_hash(HashGenerator &hashgen) const;
91 
92 protected:
93  virtual bool do_check_match(const DCPackerInterface *other) const;
94  virtual bool do_check_match_simple_parameter(const DCSimpleParameter *other) const;
95  virtual bool do_check_match_array_parameter(const DCArrayParameter *other) const;
96 
97 private:
98  static DCSimpleParameter *create_nested_field(DCSubatomicType type,
99  unsigned int divisor);
100  static DCPackerInterface *create_uint32uint8_type();
101 
102 private:
103  DCSubatomicType _type;
104  unsigned int _divisor;
105 
106  DCSubatomicType _nested_type;
107  DCPackerInterface *_nested_field;
108  size_t _bytes_per_element;
109 
110  // The rest of this is to maintain the static list of
111  // DCPackerInterface objects for _nested_field, above. We allocate
112  // each possible object once, and don't delete it.
113  typedef pmap<unsigned int, DCSimpleParameter *> DivisorMap;
114  typedef pmap<DCSubatomicType, DivisorMap> NestedFieldMap;
115  static NestedFieldMap _nested_field_map;
116 
117  // These are the range and modulus values as specified by the user,
118  // unscaled by the divisor.
119  DCDoubleRange _orig_range;
120  bool _has_modulus;
121  double _orig_modulus;
122 
123  // Only the range appropriate to this type will be filled in.
124  DCIntRange _int_range;
125  DCUnsignedIntRange _uint_range;
126  DCInt64Range _int64_range;
127  DCUnsignedInt64Range _uint64_range;
128  DCDoubleRange _double_range;
129 
130  // All of these modulus values will be filled in, regardless of the
131  // type.
132  unsigned int _uint_modulus;
133  PN_uint64 _uint64_modulus;
134  double _double_modulus;
135 
136  static DCClassParameter *_uint32uint8_type;
137 };
138 
139 #endif
virtual int calc_num_nested_fields(size_t length_bytes) const
This flavor of get_num_nested_fields is used during unpacking.
This is our own Panda specialization on the default STL map.
Definition: pmap.h:52
This is a block of data that receives the results of DCPacker.
Definition: dcPackData.h:25
virtual bool pack_default_value(DCPackData &pack_data, bool &pack_error) const
Packs the field&#39;s specified default value (or a sensible default if no value is specified) into the s...
Definition: dcField.cxx:548
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.
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 void pack_uint(DCPackData &pack_data, unsigned int value, bool &pack_error, bool &range_error) const
Packs the indicated numeric or string value into the stream.
virtual void unpack_uint(const char *data, size_t length, size_t &p, unsigned int &value, bool &pack_error, bool &range_error) const
Unpacks the current numeric or string value from the stream.
virtual void pack_double(DCPackData &pack_data, double value, bool &pack_error, bool &range_error) const
Packs the indicated numeric or string value into the stream.
virtual void pack_uint64(DCPackData &pack_data, PN_uint64 value, bool &pack_error, bool &range_error) const
Packs the indicated numeric or string value into the stream.
virtual void unpack_int64(const char *data, size_t length, size_t &p, PN_int64 &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.
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 void unpack_uint64(const char *data, size_t length, size_t &p, PN_uint64 &value, bool &pack_error, bool &range_error) const
Unpacks the current numeric or string value from the stream.
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 pack_int(DCPackData &pack_data, int value, bool &pack_error, bool &range_error) const
Packs the indicated numeric or string value into the stream.
virtual void unpack_int(const char *data, size_t length, size_t &p, int &value, bool &pack_error, bool &range_error) const
Unpacks the current numeric or string value from the stream.
virtual bool unpack_skip(const char *data, size_t length, size_t &p, bool &pack_error) const
Increments p to the end of the current field without actually unpacking any data or performing any ra...
virtual void unpack_double(const char *data, size_t length, size_t &p, double &value, bool &pack_error, bool &range_error) const
Unpacks the current numeric or string value from 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 void pack_int64(DCPackData &pack_data, PN_int64 value, bool &pack_error, bool &range_error) const
Packs the indicated numeric or string value into the stream.
This defines the internal interface for packing values into a DCField.
virtual bool unpack_validate(const char *data, size_t length, size_t &p, bool &pack_error, bool &range_error) const
Internally unpacks the current numeric or string value and validates it against the type range limits...