-
Notifications
You must be signed in to change notification settings - Fork 6
/
csdm_message.cpp
133 lines (100 loc) · 1.91 KB
/
csdm_message.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "csdm_message.h"
Message::Message()
{
m_CurParams = 0;
}
Message::~Message()
{
unsigned int c = m_Params.size();
unsigned int i;
for (i=0; i<c; i++)
{
delete m_Params[i];
m_Params[i] = NULL;
}
m_Params.clear();
}
void Message::AddParam(const char *szData)
{
msgprm_s *pMsg;
if (m_CurParams == m_Params.size())
{
pMsg = new msgprm_s;
m_Params.push_back(pMsg);
} else {
pMsg = m_Params[m_CurParams];
}
pMsg->szData.assign(szData);
pMsg->type = Msg_String;
m_CurParams++;
}
void Message::AddParam(float fdata)
{
msgprm_s *pMsg;
if (m_CurParams == m_Params.size())
{
pMsg = new msgprm_s;
m_Params.push_back(pMsg);
} else {
pMsg = m_Params[m_CurParams];
}
pMsg->v.fData = fdata;
pMsg->type = Msg_Float;
m_CurParams++;
}
void Message::AddParam(int idata)
{
msgprm_s *pMsg;
if (m_CurParams == m_Params.size())
{
pMsg = new msgprm_s;
m_Params.push_back(pMsg);
} else {
pMsg = m_Params[m_CurParams];
}
pMsg->v.iData = idata;
pMsg->type = Msg_Int;
m_CurParams++;
}
int Message::GetParamInt(unsigned int index)
{
if (index < 0 || index >= m_CurParams)
return 0;
msgprm_s *pMsg = m_Params[index];
if (pMsg->type != Msg_Int)
return 0;
return pMsg->v.iData;
}
float Message::GetParamFloat(unsigned int index)
{
if (index < 0 || index >= m_CurParams)
return 0;
msgprm_s *pMsg = m_Params[index];
if (pMsg->type != Msg_Float)
return 0;
return pMsg->v.fData;
}
const char *Message::GetParamString(unsigned int index)
{
if (index < 0 || index >= m_CurParams)
return 0;
msgprm_s *pMsg = m_Params[index];
if (pMsg->type != Msg_String)
return 0;
return pMsg->szData.c_str();
}
MsgType Message::GetParamType(unsigned int index)
{
if (index < 0 || index >= m_CurParams)
return static_cast<MsgType>(0);
msgprm_s *pMsg = m_Params[index];
return pMsg->type;
}
size_t Message::Parameters()
{
return m_CurParams;
}
void Message::Reset()
{
m_CurParams = 0;
}