Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef WAVEPACKET_DATAHASH_H__
00036 #define WAVEPACKET_DATAHASH_H__
00037
00038
00039
00040 #include "common/common.h"
00041 #include "threadsafe/smart_ptr.h"
00042 #include "threadsafe/threadsafe_multimap.h"
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 bool isValidHashKeyName(IN const char * key_name) throw();
00062
00063
00064 void validateHashKeyName(IN const char * key_name);
00065
00066
00067 enum eHashDataType {
00068 eHashDataType_String = 1,
00069 eHashDataType_Hash = 2,
00070
00071
00072 eHashDataType_Invalid = 0
00073 };
00074
00075
00076 class Datahash;
00077
00078
00079 struct hash_value_t {
00080
00081 hash_value_t(IN const char * txt);
00082 hash_value_t(IN const std::string& s);
00083 hash_value_t(IN smart_ptr<Datahash>& h);
00084 hash_value_t(void) throw() { this->clear(); }
00085
00086 void clear(void) throw();
00087
00088
00089 eHashDataType type;
00090 std::string text;
00091 smart_ptr<Datahash> hash;
00092 };
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 class Datahash : public threadsafe_multimap<std::string, hash_value_t> {
00107 private:
00108 typedef threadsafe_multimap<std::string, hash_value_t> base_map_t;
00109
00110 public:
00111
00112 void insert(IN const char * key, IN const hash_value_t& hv) {
00113 validateHashKeyName(key);
00114 base_map_t::insert(key, hv);
00115 }
00116
00117 void insert(IN const std::string& key, IN const hash_value_t& hv) {
00118 validateHashKeyName(key.c_str());
00119 base_map_t::insert(key, hv);
00120 }
00121
00122
00123 void insert(IN const char * key, IN const char * value) {
00124 hash_value_t hv;
00125 hv.type = eHashDataType_String;
00126 hv.text = value;
00127 this->insert(key, hv);
00128 }
00129
00130 void insert(IN const char * key, IN smart_ptr<Datahash>& subHash) {
00131 hash_value_t hv;
00132 hv.type = eHashDataType_Hash;
00133 hv.hash = subHash;
00134 this->insert(key, hv);
00135 }
00136
00137
00138 int count(IN const char * key) const throw() {
00139 return nonConst()->count(key);
00140 }
00141
00142 void getIterator(OUT iterator_t& i) const throw() {
00143 nonConst()->getIterator(i);
00144 }
00145
00146 void getIterator(IN const char * key, OUT iterator_t& i) const throw() {
00147 nonConst()->getIterator(key, i);
00148 }
00149
00150 const hash_value_t * getNextElementUnsafe(IO iterator_t& i,
00151 OUT std::string& key) const throw() {
00152 return nonConst()->getNextElementUnsafe(i, key);
00153 }
00154
00155 const hash_value_t * getNextElementUnsafe(IO iterator_t& i) const throw() {
00156 std::string key;
00157 return nonConst()->getNextElementUnsafe(i, key);
00158 }
00159
00160
00161 static smart_ptr<Datahash> create(void) { return new Datahash; }
00162
00163 private:
00164
00165
00166
00167
00168
00169
00170
00171 threadsafe_multimap<std::string, hash_value_t> * nonConst(void) const throw() {
00172 return (Datahash *) this;
00173 }
00174 };
00175
00176
00177
00178
00179
00180 #endif // WAVEPACKET_DATAHASH_H__
00181