event_value.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 */
28
29
30 #pragma once
31
32 #include "../../Core/System/databuffer.h"
33
34 namespace clan
35 {
38
40 class NetGameEventValue
41 {
42 public:
43 enum Type
44 {
45 null,
46 integer,
47 uinteger,
48 character,
49 ucharacter,
50 string,
51 boolean,
52 number,
53 complex,
54 binary
55 };
56
57 NetGameEventValue();
58
62 NetGameEventValue(int value);
63
67 NetGameEventValue(unsigned int value);
68
72 NetGameEventValue(char value);
73
77 NetGameEventValue(unsigned char value);
78
82 NetGameEventValue(float value);
83
87 NetGameEventValue(const std::string &value);
88
92 NetGameEventValue(const char *str);
93
97 NetGameEventValue(const wchar_t *str);
98
102 explicit NetGameEventValue(bool value);
103
107 NetGameEventValue(const DataBuffer &value);
108
112 NetGameEventValue(Type type);
113
117 Type get_type() const;
118
122 bool is_null() const;
123
127 bool is_uinteger() const;
128
132 bool is_integer() const;
133
137 bool is_ucharacter() const;
138
142 bool is_character() const;
143
147 bool is_number() const;
148
152 bool is_string() const;
153
157 bool is_boolean() const;
158
162 bool is_binary() const;
163
167 bool is_complex() const;
168
169 unsigned int get_member_count() const;
170 const NetGameEventValue &get_member(unsigned int index) const;
171
175 void add_member(const NetGameEventValue &value);
176
181 void set_member(unsigned int index, const NetGameEventValue &value);
182
186 unsigned int get_uinteger() const;
187
191 int get_integer() const;
192
196 unsigned int get_ucharacter() const;
197
201 int get_character() const;
202
206 float get_number() const;
207
211 std::string get_string() const;
212
216 bool get_boolean() const;
217
221 DataBuffer get_binary() const;
222
223 inline operator unsigned int() const { return get_uinteger(); }
224 inline operator int() const { return get_integer(); }
225 inline operator unsigned char() const { return get_ucharacter(); }
226 inline operator float() const { return get_number(); }
227 inline operator std::string() const { return get_string(); }
228 inline operator bool() const { return get_boolean(); }
229 inline operator DataBuffer() const { return get_binary(); }
230
232 static std::string to_string(const NetGameEventValue &);
233
234 private:
236 void throw_if_not_complex() const;
237
238 Type type;
239 union
240 {
241 int value_int;
242 unsigned int value_uint;
243 char value_char;
244 unsigned char value_uchar;
245 float value_float;
246 bool value_bool;
247 };
248 std::string value_string;
249 DataBuffer value_binary;
250 std::vector<NetGameEventValue> value_complex;
251 };
252
253 }
254
256
clan::NetGameEventValue::NetGameEventValue
NetGameEventValue()
clan
Definition: clanapp.h:35
clan::NetGameEventValue::is_binary
bool is_binary() const
Is Binary.
clan::NetGameEventValue::number
Definition: event_value.h:52
clan::NetGameEventValue::is_number
bool is_number() const
Is Number.
clan::NetGameEventValue::is_string
bool is_string() const
Is String.
clan::NetGameEventValue::uinteger
Definition: event_value.h:47
clan::NetGameEventValue::is_integer
bool is_integer() const
Is Integer.
clan::NetGameEventValue::is_null
bool is_null() const
Is Null.
clan::NetGameEventValue::@25::value_char
char value_char
Definition: event_value.h:243
clan::NetGameEventValue::binary
Definition: event_value.h:54
clan::NetGameEventValue::integer
Definition: event_value.h:46
clan::NetGameEventValue::get_type
Type get_type() const
Get Type.
clan::NetGameEventValue::null
Definition: event_value.h:45
clan::NetGameEventValue::is_boolean
bool is_boolean() const
Is Boolean.
clan::NetGameEventValue::is_ucharacter
bool is_ucharacter() const
Is Ucharacter.
clan::StyleTokenType::string
@ keyword
clan::NetGameEventValue::Type
Type
Definition: event_value.h:43
clan::NetGameEventValue::character
Definition: event_value.h:48
clan::NetGameEventValue::string
Definition: event_value.h:50
clan::NetGameEventValue::get_character
int get_character() const
To character.
clan::NetGameEventValue::@25::value_bool
bool value_bool
Definition: event_value.h:246
clan::NetGameEventValue::get_uinteger
unsigned int get_uinteger() const
To unsigned integer.
clan::NetGameEventValue::get_boolean
bool get_boolean() const
To boolean.
clan::NetGameEventValue::@25::value_float
float value_float
Definition: event_value.h:245
clan::NetGameEventValue::get_string
std::string get_string() const
To string.
clan::NetGameEventValue::@25::value_uchar
unsigned char value_uchar
Definition: event_value.h:244
clan::NetGameEventValue::is_uinteger
bool is_uinteger() const
Is Uinteger.
clan::NetGameEventValue::get_number
float get_number() const
To number.
clan::NetGameEventValue::get_integer
int get_integer() const
To integer.
clan::NetGameEventValue::is_complex
bool is_complex() const
Is Complex.
clan::NetGameEventValue
NetGameEventValue.
Definition: event_value.h:40
clan::NetGameEventValue::boolean
Definition: event_value.h:51
clan::NetGameEventValue::@25::value_uint
unsigned int value_uint
Definition: event_value.h:242
clan::NetGameEventValue::set_member
void set_member(unsigned int index, const NetGameEventValue &value)
Set member.
clan::NetGameEventValue::to_string
static std::string to_string(const NetGameEventValue &)
Helper function to obtain a string representation of an EventValue object.
clan::NetGameEventValue::get_member
const NetGameEventValue & get_member(unsigned int index) const
clan::NetGameEventValue::is_character
bool is_character() const
Is Character.
clan::NetGameEventValue::@25::value_int
int value_int
Definition: event_value.h:241
clan::DataBuffer
General purpose data buffer.
Definition: databuffer.h:42
clan::NetGameEventValue::add_member
void add_member(const NetGameEventValue &value)
Add member.
clan::NetGameEventValue::get_ucharacter
unsigned int get_ucharacter() const
To unsigned character.
clan::NetGameEventValue::get_member_count
unsigned int get_member_count() const
clan::NetGameEventValue::ucharacter
Definition: event_value.h:49
clan::NetGameEventValue::complex
Definition: event_value.h:53
clan::NetGameEventValue::get_binary
DataBuffer get_binary() const
To binary.