My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
NetUnion.h
1 // $Id: NetUnion.h,v 1.1.1.1 2009/07/06 23:57:26 eml Exp $
2 
3 #ifndef GCP_UTIL_NETUNION_H
4 #define GCP_UTIL_NETUNION_H
5 
15 #include <map>
16 #include "gcp/util/common/DataType.h"
17 
18 #include "gcp/util/common/NetDat.h"
19 
20 namespace gcp {
21  namespace util {
22 
23  class NetUnion : public NetDat {
24  public:
25 
26  static const unsigned NETUNION_UNKNOWN = 0;
27 
31  NetUnion();
32 
36  NetUnion(const NetUnion& netUnion);
37  NetUnion(NetUnion& netUnion);
38  NetUnion& operator=(const NetUnion& netUnion);
39  NetUnion& operator=(NetUnion& netUnion);
40 
44  virtual ~NetUnion();
45 
49  void addMember(unsigned id, NetDat* member=0, bool alloc=false);
50 
54  void addVar(unsigned id, gcp::util::DataType::Type type,
55  void* vPtr, unsigned nEl);
56 
60  void addCase(unsigned id);
61 
65  NetDat* const findMember(unsigned id);
66 
67  bool memberIsValid(unsigned id);
68 
72  NetDat* const getMember(unsigned id);
73 
77  void setTo(unsigned id);
78 
82  unsigned getType();
83 
87  unsigned sizeOf(unsigned id);
88 
92  unsigned size();
93 
97  void deserialize(const std::vector<unsigned char>& bytes);
98  void deserialize(const unsigned char* bytes);
99 
100  private:
101 
102  // A map of members contained in this class
103 
104  std::map<unsigned int, NetDat::Info> members_;
105 
106  // The member currently selected
107 
108  unsigned int id_;
109 
113  void checkSize(const std::vector<unsigned char>& bytes);
114 
118  void checkSize(const std::vector<unsigned char>& bytes, unsigned id);
119 
123  void resize(unsigned size);
124 
128  void serialize();
129 
130  }; // End class NetUnion
131 
132  } // End namespace util
133 } // End namespace gcp
134 
135 #define NETUNION_UCHAR(id, name) \
136 addVar(id, gcp::util::DataType::UCHAR, (void*)&name, 1)
137 
138 #define NETUNION_UCHAR_ARR(id, name, nEl) \
139 addVar(id, gcp::util::DataType::UCHAR, (void*)name, nEl)
140 
141 #define NETUNION_CHAR(id, name) \
142 addVar(id, gcp::util::DataType::CHAR, (void*)&name, 1)
143 
144 #define NETUNION_CHAR_ARR(id, name, nEl) \
145 addVar(id, gcp::util::DataType::CHAR, (void*)name, nEl)
146 
147 #define NETUNION_BOOL(id, name) \
148 addVar(id, gcp::util::DataType::BOOL, (void*)&name, 1)
149 
150 #define NETUNION_BOOL_ARR(id, name, nEl) \
151 addVar(id, gcp::util::DataType::BOOL, (void*)name, nEl)
152 
153 #define NETUNION_USHORT(id, name) \
154 addVar(id, gcp::util::DataType::USHORT, (void*)&name, 1)
155 
156 #define NETUNION_USHORT_ARR(id, name, nEl) \
157 addVar(id, gcp::util::DataType::USHORT, (void*)name, nEl)
158 
159 #define NETUNION_SHORT(id, name) \
160 addVar(id, gcp::util::DataType::SHORT, (void*)&name, 1)
161 
162 #define NETUNION_SHORT_ARR(id, name, nEl) \
163 addVar(id, gcp::util::DataType::SHORT, (void*)name, nEl)
164 
165 #define NETUNION_UINT(id, name) \
166 addVar(id, gcp::util::DataType::UINT, (void*)&name, 1)
167 
168 #define NETUNION_UINT_ARR(id, name, nEl) \
169 addVar(id, gcp::util::DataType::UINT, (void*)name, nEl)
170 
171 #define NETUNION_INT(id, name) \
172 addVar(id, gcp::util::DataType::INT, (void*)&name, 1)
173 
174 #define NETUNION_INT_ARR(id, name, nEl) \
175 addVar(id, gcp::util::DataType::INT, (void*)name, nEl)
176 
177 #define NETUNION_ULONG(id, name) \
178 addVar(id, gcp::util::DataType::ULONG, (void*)&name, 1)
179 
180 #define NETUNION_ULONG_ARR(id, name, nEl) \
181 addVar(id, gcp::util::DataType::ULONG, (void*)name, nEl)
182 
183 #define NETUNION_LONG(id, name) \
184 addVar(id, gcp::util::DataType::LONG, (void*)&name, 1)
185 
186 #define NETUNION_LONG_ARR(id, name, nEl) \
187 addVar(id, gcp::util::DataType::LONG, (void*)name, nEl)
188 
189 #define NETUNION_FLOAT(id, name) \
190 addVar(id, gcp::util::DataType::FLOAT, (void*)&name, 1)
191 
192 #define NETUNION_FLOAT_ARR(id, name, nEl) \
193 addVar(id, gcp::util::DataType::FLOAT, (void*)name, nEl)
194 
195 #define NETUNION_DOUBLE(id, name) \
196 addVar(id, gcp::util::DataType::DOUBLE, (void*)&name, 1)
197 
198 #define NETUNION_DOUBLE_ARR(id, name, nEl) \
199 addVar(id, gcp::util::DataType::DOUBLE, (void*)name, nEl)
200 
201 #endif // End #ifndef GCP_UTIL_NETUNION_H
void deserialize(const std::vector< unsigned char > &bytes)
Definition: NetUnion.cc:238
Definition: compress.c:1548
NetUnion & operator=(const NetUnion &netUnion)
Definition: NetUnion.cc:54
void setTo(unsigned id)
Definition: NetUnion.cc:184
unsigned size()
Definition: NetUnion.cc:198
NetUnion()
Definition: NetUnion.cc:14
bool memberIsValid(unsigned id)
Definition: NetUnion.cc:158
void addMember(unsigned id, NetDat *member=0, bool alloc=false)
Definition: NetUnion.cc:117
unsigned getType()
Definition: NetUnion.cc:314
void addCase(unsigned id)
Definition: NetUnion.cc:306
unsigned sizeOf(unsigned id)
Definition: NetUnion.cc:286
Definition: NetDat.h:23
NetDat *const getMember(unsigned id)
Definition: NetUnion.cc:171
NetDat *const findMember(unsigned id)
Definition: NetUnion.cc:145
Definition: NetUnion.h:23
void addVar(unsigned id, gcp::util::DataType::Type type, void *vPtr, unsigned nEl)
Definition: NetUnion.cc:296
virtual ~NetUnion()
Definition: NetUnion.cc:89