event_value.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2016 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 #pragma once
30 
31 #include "../../Core/System/databuffer.h"
32 
33 namespace clan
34 {
37 
40  {
41  public:
42  enum Type
43  {
54  };
55 
57 
61  NetGameEventValue(int value);
62 
66  NetGameEventValue(unsigned int value);
67 
71  NetGameEventValue(char value);
72 
76  NetGameEventValue(unsigned char value);
77 
81  NetGameEventValue(float value);
82 
86  NetGameEventValue(const std::string &value);
87 
91  NetGameEventValue(const char *str);
92 
96  NetGameEventValue(const wchar_t *str);
97 
101  explicit NetGameEventValue(bool value);
102 
106  NetGameEventValue(const DataBuffer &value);
107 
111  NetGameEventValue(Type type);
112 
116  Type get_type() const;
117 
121  bool is_null() const;
122 
126  bool is_uinteger() const;
127 
131  bool is_integer() const;
132 
136  bool is_ucharacter() const;
137 
141  bool is_character() const;
142 
146  bool is_number() const;
147 
151  bool is_string() const;
152 
156  bool is_boolean() const;
157 
161  bool is_binary() const;
162 
166  bool is_complex() const;
167 
168  unsigned int get_member_count() const;
169  const NetGameEventValue &get_member(unsigned int index) const;
170 
174  void add_member(const NetGameEventValue &value);
175 
180  void set_member(unsigned int index, const NetGameEventValue &value);
181 
185  unsigned int get_uinteger() const;
186 
190  int get_integer() const;
191 
195  unsigned int get_ucharacter() const;
196 
200  int get_character() const;
201 
205  float get_number() const;
206 
210  std::string get_string() const;
211 
215  bool get_boolean() const;
216 
220  DataBuffer get_binary() const;
221 
222  inline operator unsigned int() const { return get_uinteger(); }
223  inline operator int() const { return get_integer(); }
224  inline operator unsigned char() const { return get_ucharacter(); }
225  inline operator float() const { return get_number(); }
226  inline operator std::string() const { return get_string(); }
227  inline operator bool() const { return get_boolean(); }
228  inline operator DataBuffer() const { return get_binary(); }
229 
231  static std::string to_string(const NetGameEventValue &);
232 
233  private:
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 
253 }
254 
int get_integer() const
To integer.
float get_number() const
To number.
Definition: clanapp.h:35
Definition: event_value.h:51
static std::string to_string(const NetGameEventValue &)
Helper function to obtain a string representation of an EventValue object.
bool is_complex() const
Is Complex.
bool is_number() const
Is Number.
Definition: event_value.h:46
unsigned int get_ucharacter() const
To unsigned character.
Definition: event_value.h:53
const NetGameEventValue & get_member(unsigned int index) const
char value_char
Definition: event_value.h:242
Definition: event_value.h:45
bool is_boolean() const
Is Boolean.
Definition: event_value.h:44
std::string get_string() const
To string.
void add_member(const NetGameEventValue &value)
Add member.
int get_character() const
To character.
void set_member(unsigned int index, const NetGameEventValue &value)
Set member.
unsigned char value_uchar
Definition: event_value.h:243
float value_float
Definition: event_value.h:244
Type
Definition: event_value.h:42
Definition: event_value.h:47
Definition: event_value.h:49
unsigned int get_member_count() const
bool is_ucharacter() const
Is Ucharacter.
bool is_character() const
Is Character.
unsigned int get_uinteger() const
To unsigned integer.
bool is_string() const
Is String.
bool get_boolean() const
To boolean.
bool is_null() const
Is Null.
DataBuffer get_binary() const
To binary.
Type get_type() const
Get Type.
NetGameEventValue.
Definition: event_value.h:39
Definition: event_value.h:50
bool is_uinteger() const
Is Uinteger.
int value_int
Definition: event_value.h:240
bool value_bool
Definition: event_value.h:245
unsigned int value_uint
Definition: event_value.h:241
General purpose data buffer.
Definition: databuffer.h:41
bool is_binary() const
Is Binary.
bool is_integer() const
Is Integer.
Definition: event_value.h:48
Definition: event_value.h:52