Panda3D

Loading...
Searching...
No Matches
dcSimpleParameter.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file dcSimpleParameter.h
10 * @author drose
11 * @date 2004-06-15
12 */
13
14#ifndef DCSIMPLEPARAMETER_H
15#define DCSIMPLEPARAMETER_H
16
17#include "dcbase.h"
18#include "dcParameter.h"
19#include "dcSubatomicType.h"
20#include "dcNumericRange.h"
21
22/**
23 * This is the most fundamental kind of parameter type: a single number or
24 * string, one of the DCSubatomicType elements. It may also optionally have a
25 * divisor, which is meaningful only for the numeric type elements (and
26 * represents a fixed-point numeric convention).
27 */
28 class EXPCL_DIRECT_DCPARSER DCSimpleParameter : public DCParameter {
29 public:
30 DCSimpleParameter(DCSubatomicType type, unsigned int divisor = 1);
31 DCSimpleParameter(const DCSimpleParameter &copy);
32
33PUBLISHED:
34 virtual DCSimpleParameter *as_simple_parameter();
35 virtual const DCSimpleParameter *as_simple_parameter() const;
36 virtual DCParameter *make_copy() const;
37 virtual bool is_valid() const;
38
39 DCSubatomicType get_type() const;
40 bool has_modulus() const;
41 double get_modulus() const;
42 int get_divisor() const;
43
44 public:
45 bool is_numeric_type() const;
46 bool set_modulus(double modulus);
47 bool set_divisor(unsigned int divisor);
48 bool set_range(const DCDoubleRange &range);
49
50 virtual int calc_num_nested_fields(size_t length_bytes) const;
51 virtual DCPackerInterface *get_nested_field(int n) const;
52
53 virtual void pack_double(DCPackData &pack_data, double value,
54 bool &pack_error, bool &range_error) const;
55 virtual void pack_int(DCPackData &pack_data, int value,
56 bool &pack_error, bool &range_error) const;
57 virtual void pack_uint(DCPackData &pack_data, unsigned int value,
58 bool &pack_error, bool &range_error) const;
59 virtual void pack_int64(DCPackData &pack_data, int64_t value,
60 bool &pack_error, bool &range_error) const;
61 virtual void pack_uint64(DCPackData &pack_data, uint64_t value,
62 bool &pack_error, bool &range_error) const;
63 virtual void pack_string(DCPackData &pack_data, const std::string &value,
64 bool &pack_error, bool &range_error) const;
65 virtual void pack_blob(DCPackData &pack_data, const vector_uchar &value,
66 bool &pack_error, bool &range_error) const;
67 virtual bool pack_default_value(DCPackData &pack_data, bool &pack_error) const;
68
69 virtual void unpack_double(const char *data, size_t length, size_t &p,
70 double &value, bool &pack_error, bool &range_error) const;
71 virtual void unpack_int(const char *data, size_t length, size_t &p,
72 int &value, bool &pack_error, bool &range_error) const;
73 virtual void unpack_uint(const char *data, size_t length, size_t &p,
74 unsigned int &value, bool &pack_error, bool &range_error) const;
75 virtual void unpack_int64(const char *data, size_t length, size_t &p,
76 int64_t &value, bool &pack_error, bool &range_error) const;
77 virtual void unpack_uint64(const char *data, size_t length, size_t &p,
78 uint64_t &value, bool &pack_error, bool &range_error) const;
79 virtual void unpack_string(const char *data, size_t length, size_t &p,
80 std::string &value, bool &pack_error, bool &range_error) const;
81 virtual void unpack_blob(const char *data, size_t length, size_t &p,
82 vector_uchar &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(std::ostream &out, bool brief, const std::string &prename,
89 const std::string &name, const std::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 DCPackerInterface
111 // objects for _nested_field, above. We allocate each possible object once,
112 // 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, unscaled
118 // 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 type.
131 unsigned int _uint_modulus;
132 uint64_t _uint64_modulus;
133 double _double_modulus;
134
135 static DCClassParameter *_uint32uint8_type;
136};
137
138#endif
DCArrayParameter
This represents an array of some other kind of object, meaning this parameter type accepts an arbitra...
Definition dcArrayParameter.h:26
DCClassParameter
This represents a class (or struct) object used as a parameter itself.
Definition dcClassParameter.h:26
DCField::pack_default_value
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:487
DCPackData
This is a block of data that receives the results of DCPacker.
Definition dcPackData.h:22
DCPackerInterface::pack_int64
virtual void pack_int64(DCPackData &pack_data, int64_t value, bool &pack_error, bool &range_error) const
Packs the indicated numeric or string value into the stream.
Definition dcPackerInterface.cxx:231
DCPackerInterface::unpack_blob
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.
Definition dcPackerInterface.cxx:321
DCPackerInterface::pack_uint
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.
Definition dcPackerInterface.cxx:223
DCPackerInterface::unpack_uint64
virtual void unpack_uint64(const char *data, size_t length, size_t &p, uint64_t &value, bool &pack_error, bool &range_error) const
Unpacks the current numeric or string value from the stream.
Definition dcPackerInterface.cxx:305
DCPackerInterface::unpack_double
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.
Definition dcPackerInterface.cxx:273
DCPackerInterface::pack_uint64
virtual void pack_uint64(DCPackData &pack_data, uint64_t value, bool &pack_error, bool &range_error) const
Packs the indicated numeric or string value into the stream.
Definition dcPackerInterface.cxx:239
DCPackerInterface::unpack_validate
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...
Definition dcPackerInterface.cxx:332
DCPackerInterface::calc_num_nested_fields
virtual int calc_num_nested_fields(size_t length_bytes) const
This flavor of get_num_nested_fields is used during unpacking.
Definition dcPackerInterface.cxx:178
DCPackerInterface::do_check_match_simple_parameter
virtual bool do_check_match_simple_parameter(const DCSimpleParameter *other) const
Returns true if this field matches the indicated simple parameter, false otherwise.
Definition dcPackerInterface.cxx:399
DCPackerInterface::unpack_uint
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.
Definition dcPackerInterface.cxx:289
DCPackerInterface::pack_string
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.
Definition dcPackerInterface.cxx:247
DCPackerInterface::unpack_string
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.
Definition dcPackerInterface.cxx:313
DCPackerInterface::unpack_int
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.
Definition dcPackerInterface.cxx:281
DCPackerInterface::pack_int
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.
Definition dcPackerInterface.cxx:215
DCPackerInterface::pack_double
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.
Definition dcPackerInterface.cxx:207
DCPackerInterface::unpack_int64
virtual void unpack_int64(const char *data, size_t length, size_t &p, int64_t &value, bool &pack_error, bool &range_error) const
Unpacks the current numeric or string value from the stream.
Definition dcPackerInterface.cxx:297
DCPackerInterface::get_nested_field
virtual DCPackerInterface * get_nested_field(int n) const
Returns the DCPackerInterface object that represents the nth nested field.
Definition dcPackerInterface.cxx:188
DCPackerInterface::do_check_match_array_parameter
virtual bool do_check_match_array_parameter(const DCArrayParameter *other) const
Returns true if this field matches the indicated array parameter, false otherwise.
Definition dcPackerInterface.cxx:426
DCPackerInterface::pack_blob
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.
Definition dcPackerInterface.cxx:255
DCPackerInterface::unpack_skip
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...
Definition dcPackerInterface.cxx:346
DCParameter::generate_hash
virtual void generate_hash(HashGenerator &hashgen) const
Accumulates the properties of this type into the hash.
Definition dcParameter.cxx:238
DCSimpleParameter::get_type
DCSubatomicType get_type() const
Returns the particular subatomic type represented by this instance.
Definition dcSimpleParameter.cxx:256
DCSimpleParameter::set_range
bool set_range(const DCDoubleRange &range)
Sets the parameter with the indicated range.
Definition dcSimpleParameter.cxx:405
DCSimpleParameter::is_valid
virtual bool is_valid() const
Returns false if the type is an invalid type (e.g.
Definition dcSimpleParameter.cxx:248
DCSimpleParameter::output_instance
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.
Definition dcSimpleParameter.cxx:2295
DCSimpleParameter::get_modulus
double get_modulus() const
Returns the modulus associated with this type, if any.
Definition dcSimpleParameter.cxx:276
DCSimpleParameter::set_modulus
bool set_modulus(double modulus)
Assigns the indicated modulus to the simple type.
Definition dcSimpleParameter.cxx:308
DCSimpleParameter::has_modulus
bool has_modulus() const
Returns true if there is a modulus associated, false otherwise.,.
Definition dcSimpleParameter.cxx:264
DCSimpleParameter::set_divisor
bool set_divisor(unsigned int divisor)
Assigns the indicated divisor to the simple type.
Definition dcSimpleParameter.cxx:376
DCSimpleParameter::get_divisor
int get_divisor() const
Returns the divisor associated with this type.
Definition dcSimpleParameter.cxx:287
DCSimpleParameter::is_numeric_type
bool is_numeric_type() const
Returns true if the type is a numeric type (and therefore can accept a divisor and/or a modulus),...
Definition dcSimpleParameter.cxx:296
HashGenerator
This class generates an arbitrary hash number from a sequence of ints.
Definition hashGenerator.h:23
dcNumericRange.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
dcParameter.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
dcSubatomicType.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
DCSubatomicType
DCSubatomicType
This defines the numeric type of each element of a DCAtomicField; that is, the particular values that...
Definition dcSubatomicType.h:25
dcbase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.