event_value.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2013 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 "../api_network.h"
33 #include "../../Core/System/databuffer.h"
34 
35 namespace clan
36 {
39 
41 class CL_API_NETWORK NetGameEventValue
42 {
43 public:
44  enum Type
45  {
55  binary
56  };
57 
59 
63  NetGameEventValue(int value);
64 
68  NetGameEventValue(unsigned int value);
69 
73  NetGameEventValue(char value);
74 
78  NetGameEventValue(unsigned char value);
79 
83  NetGameEventValue(float value);
84 
88  NetGameEventValue(const std::string &value);
89 
93  NetGameEventValue(const char *str);
94 
98  NetGameEventValue(const wchar_t *str);
99 
103  explicit NetGameEventValue(bool value);
104 
108  NetGameEventValue(const DataBuffer &value);
109 
113  NetGameEventValue(Type type);
114 
118  Type get_type() const;
119 
123  bool is_null() const;
124 
128  bool is_uinteger() const;
129 
133  bool is_integer() const;
134 
138  bool is_ucharacter() const;
139 
143  bool is_character() const;
144 
148  bool is_number() const;
149 
153  bool is_string() const;
154 
158  bool is_boolean() const;
159 
163  bool is_binary() const;
164 
168  bool is_complex() const;
169 
170  unsigned int get_member_count() const;
171  const NetGameEventValue &get_member(unsigned int index) const;
172 
176  void add_member(const NetGameEventValue &value);
177 
182  void set_member(unsigned int index, const NetGameEventValue &value);
183 
187  unsigned int to_uinteger() const;
188 
192  int to_integer() const;
193 
197  unsigned int to_ucharacter() const;
198 
202  int to_character() const;
203 
207  float to_number() const;
208 
212  std::string to_string() const;
213 
217  bool to_boolean() const;
218 
222  DataBuffer to_binary() const;
223 
224  inline operator unsigned int() const { return to_uinteger(); }
225  inline operator int() const { return to_integer(); }
226  inline operator unsigned char() const { return to_ucharacter(); }
227  inline operator float() const { return to_number(); }
228  inline operator std::string() const { return to_string(); }
229  inline operator bool() const { return to_boolean(); }
230  inline operator DataBuffer() const { return to_binary(); }
231 
232 private:
233 
235  void throw_if_not_complex() const;
236 
237  Type type;
238  union
239  {
241  unsigned int value_uint;
243  unsigned char value_uchar;
244  float value_float;
246  };
247  std::string value_string;
248  DataBuffer value_binary;
249  std::vector<NetGameEventValue> value_complex;
250 };
251 
252 }
253 
255 
Definition: event_value.h:53
Definition: event_value.h:48
char value_char
Definition: event_value.h:242
Definition: event_value.h:47
Definition: event_value.h:46
Type
Definition: event_value.h:44
Definition: event_value.h:49
Definition: event_value.h:51
bool value_bool
Definition: event_value.h:245
float value_float
Definition: event_value.h:244
unsigned char value_uchar
Definition: event_value.h:243
NetGameEventValue.
Definition: event_value.h:41
Definition: event_value.h:52
unsigned int value_uint
Definition: event_value.h:241
int value_int
Definition: event_value.h:240
General purpose data buffer.
Definition: databuffer.h:43
Definition: event_value.h:50
Definition: event_value.h:54