00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef DCSIMPLEPARAMETER_H
00016 #define DCSIMPLEPARAMETER_H
00017
00018 #include "dcbase.h"
00019 #include "dcParameter.h"
00020 #include "dcSubatomicType.h"
00021 #include "dcNumericRange.h"
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 class EXPCL_DIRECT DCSimpleParameter : public DCParameter {
00033 public:
00034 DCSimpleParameter(DCSubatomicType type, unsigned int divisor = 1);
00035 DCSimpleParameter(const DCSimpleParameter ©);
00036
00037 PUBLISHED:
00038 virtual DCSimpleParameter *as_simple_parameter();
00039 virtual const DCSimpleParameter *as_simple_parameter() const;
00040 virtual DCParameter *make_copy() const;
00041 virtual bool is_valid() const;
00042
00043 DCSubatomicType get_type() const;
00044 bool has_modulus() const;
00045 double get_modulus() const;
00046 int get_divisor() const;
00047
00048 public:
00049 bool is_numeric_type() const;
00050 bool set_modulus(double modulus);
00051 bool set_divisor(unsigned int divisor);
00052 bool set_range(const DCDoubleRange &range);
00053
00054 virtual int calc_num_nested_fields(size_t length_bytes) const;
00055 virtual DCPackerInterface *get_nested_field(int n) const;
00056
00057 virtual void pack_double(DCPackData &pack_data, double value,
00058 bool &pack_error, bool &range_error) const;
00059 virtual void pack_int(DCPackData &pack_data, int value,
00060 bool &pack_error, bool &range_error) const;
00061 virtual void pack_uint(DCPackData &pack_data, unsigned int value,
00062 bool &pack_error, bool &range_error) const;
00063 virtual void pack_int64(DCPackData &pack_data, PN_int64 value,
00064 bool &pack_error, bool &range_error) const;
00065 virtual void pack_uint64(DCPackData &pack_data, PN_uint64 value,
00066 bool &pack_error, bool &range_error) const;
00067 virtual void pack_string(DCPackData &pack_data, const string &value,
00068 bool &pack_error, bool &range_error) const;
00069 virtual bool pack_default_value(DCPackData &pack_data, bool &pack_error) const;
00070
00071 virtual void unpack_double(const char *data, size_t length, size_t &p,
00072 double &value, bool &pack_error, bool &range_error) const;
00073 virtual void unpack_int(const char *data, size_t length, size_t &p,
00074 int &value, bool &pack_error, bool &range_error) const;
00075 virtual void unpack_uint(const char *data, size_t length, size_t &p,
00076 unsigned int &value, bool &pack_error, bool &range_error) const;
00077 virtual void unpack_int64(const char *data, size_t length, size_t &p,
00078 PN_int64 &value, bool &pack_error, bool &range_error) const;
00079 virtual void unpack_uint64(const char *data, size_t length, size_t &p,
00080 PN_uint64 &value, bool &pack_error, bool &range_error) const;
00081 virtual void unpack_string(const char *data, size_t length, size_t &p,
00082 string &value, bool &pack_error, bool &range_error) const;
00083 virtual bool unpack_validate(const char *data, size_t length, size_t &p,
00084 bool &pack_error, bool &range_error) const;
00085 virtual bool unpack_skip(const char *data, size_t length, size_t &p,
00086 bool &pack_error) const;
00087
00088 virtual void output_instance(ostream &out, bool brief, const string &prename,
00089 const string &name, const string &postname) const;
00090 virtual void generate_hash(HashGenerator &hashgen) const;
00091
00092 protected:
00093 virtual bool do_check_match(const DCPackerInterface *other) const;
00094 virtual bool do_check_match_simple_parameter(const DCSimpleParameter *other) const;
00095 virtual bool do_check_match_array_parameter(const DCArrayParameter *other) const;
00096
00097 private:
00098 static DCSimpleParameter *create_nested_field(DCSubatomicType type,
00099 unsigned int divisor);
00100 static DCPackerInterface *create_uint32uint8_type();
00101
00102 private:
00103 DCSubatomicType _type;
00104 unsigned int _divisor;
00105
00106 DCSubatomicType _nested_type;
00107 DCPackerInterface *_nested_field;
00108 size_t _bytes_per_element;
00109
00110
00111
00112
00113 typedef pmap<unsigned int, DCSimpleParameter *> DivisorMap;
00114 typedef pmap<DCSubatomicType, DivisorMap> NestedFieldMap;
00115 static NestedFieldMap _nested_field_map;
00116
00117
00118
00119 DCDoubleRange _orig_range;
00120 bool _has_modulus;
00121 double _orig_modulus;
00122
00123
00124 DCIntRange _int_range;
00125 DCUnsignedIntRange _uint_range;
00126 DCInt64Range _int64_range;
00127 DCUnsignedInt64Range _uint64_range;
00128 DCDoubleRange _double_range;
00129
00130
00131
00132 unsigned int _uint_modulus;
00133 PN_uint64 _uint64_modulus;
00134 double _double_modulus;
00135
00136 static DCClassParameter *_uint32uint8_type;
00137 };
00138
00139 #endif