CARMA C++
NetDat.h
Go to the documentation of this file.
1 // $Id: NetDat.h,v 1.2 2011/06/08 18:40:13 eml Exp $
2 
3 #ifndef SZA_UTIL_NETDAT_H
4 #define SZA_UTIL_NETDAT_H
5 
15 #include <vector>
16 
17 namespace sza {
18  namespace util {
19 
20  class NetStruct;
21  class NetUnion;
22 
23  class NetDat {
24  public:
25 
26  struct Info {
27  NetDat* datPtr_;
28  bool alloc_;
29 
30  Info() {
31  datPtr_ = 0;
32  alloc_ = false;
33  };
34 
35  Info(NetDat* datPtr, bool alloc) {
36  datPtr_ = datPtr;
37  alloc_ = alloc;
38  };
39 
40  Info(const Info& info) {
41  datPtr_ = info.datPtr_;
42  alloc_ = info.alloc_;
43  };
44  };
45 
49  NetDat();
50 
54  NetDat(const NetDat& netDat);
55  NetDat(NetDat& netDat);
56  NetDat& operator=(const NetDat& netDat);
57  NetDat& operator=(NetDat& netDat);
58 
62  virtual ~NetDat();
63 
67  virtual unsigned size();
68 
72  virtual std::vector<unsigned char>& getSerializedData();
73  virtual std::vector<unsigned char>& getSerializedDataNoResize();
74 
78  virtual void packSerializedData(unsigned char* bytes);
79 
83  virtual void deserialize(const std::vector<unsigned char>& bytes);
84 
88  unsigned maxSize();
89 
90  protected:
91 
92  friend class NetStruct;
93  friend class NetUnion;
94 
98  std::vector<unsigned char> bytes_;
99 
103  unsigned size_;
104 
108  virtual void resize(unsigned size);
109 
110  // Recalculate the size of the underlying byte array and resize
111 
112  virtual void resize();
113 
117  unsigned char* const getSerializedDataPtr();
118 
122  virtual void serialize();
123 
127  virtual void deserialize(const unsigned char* bytes)=0;
128 
132  virtual void checkSize(const std::vector<unsigned char>& bytes);
133 
134  }; // End class NetDat
135 
136  } // End namespace util
137 } // End namespace sza
138 
139 
140 
141 #endif // End #ifndef SZA_UTIL_NETDAT_H