| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#ifndef GENERIC_MESSAGE_H |
| 18 |
#define GENERIC_MESSAGE_H |
| 19 |
|
| 20 |
#include <map> |
| 21 |
#include <string> |
| 22 |
|
| 23 |
using namespace std; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
class GenericMessage |
| 32 |
{ |
| 33 |
public: |
| 34 |
GenericMessage(); |
| 35 |
~GenericMessage(); |
| 36 |
|
| 37 |
enum { |
| 38 |
TYPE_VALUE32, |
| 39 |
TYPE_VALUE64, |
| 40 |
TYPE_MESSAGE, |
| 41 |
TYPE_STRING, |
| 42 |
TYPE_DATA |
| 43 |
}; |
| 44 |
|
| 45 |
struct Node { |
| 46 |
uint32_t type; |
| 47 |
union { |
| 48 |
uint32_t value32; |
| 49 |
uint64_t value64; |
| 50 |
GenericMessage* message; |
| 51 |
string* str; |
| 52 |
string* data; |
| 53 |
}; |
| 54 |
}; |
| 55 |
|
| 56 |
void addInt32(int32_t fieldId, uint32_t value); |
| 57 |
void addInt64(int32_t fieldId, uint64_t value); |
| 58 |
GenericMessage* addMessage(int32_t fieldId); |
| 59 |
void addString(int32_t fieldId, const string& value); |
| 60 |
|
| 61 |
typedef multimap<int32_t,Node>::const_iterator const_iterator; |
| 62 |
typedef pair<const_iterator,const_iterator> const_iterator_pair; |
| 63 |
|
| 64 |
const_iterator_pair find(int fieldId) const; |
| 65 |
|
| 66 |
private: |
| 67 |
multimap<int,Node> mNodes; |
| 68 |
}; |
| 69 |
|
| 70 |
#endif |
| 71 |
|