event_value.h
1/*
2** ClanLib SDK
3** Copyright (c) 1997-2020 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
33namespace clan
34{
37
40 {
41 public:
42 enum class Type
43 {
44 null,
45 integer,
49 string,
50 boolean,
51 number,
52 complex,
53 binary
54 };
55
57
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
107
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
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;
246 };
247 std::string value_string;
248 DataBuffer value_binary;
249 std::vector<NetGameEventValue> value_complex;
250 };
251
253}
254
General purpose data buffer.
Definition databuffer.h:42
NetGameEventValue.
Definition event_value.h:40
void set_member(unsigned int index, const NetGameEventValue &value)
Set member.
int value_int
Definition event_value.h:240
NetGameEventValue(unsigned char value)
Constructs a NetGameEventValue.
NetGameEventValue(int value)
Constructs a NetGameEventValue.
NetGameEventValue(const char *str)
Constructs a NetGameEventValue.
NetGameEventValue(const std::string &value)
Constructs a NetGameEventValue.
NetGameEventValue(Type type)
Constructs a NetGameEventValue.
bool is_complex() const
Is Complex.
NetGameEventValue(bool value)
Constructs a NetGameEventValue.
float get_number() const
To number.
unsigned int get_uinteger() const
To unsigned integer.
std::string get_string() const
To string.
unsigned char value_uchar
Definition event_value.h:243
unsigned int value_uint
Definition event_value.h:241
NetGameEventValue(const wchar_t *str)
Constructs a NetGameEventValue.
const NetGameEventValue & get_member(unsigned int index) const
int get_integer() const
To integer.
DataBuffer get_binary() const
To binary.
Type get_type() const
Get Type.
bool is_number() const
Is Number.
bool is_string() const
Is String.
bool value_bool
Definition event_value.h:245
bool is_null() const
Is Null.
NetGameEventValue(unsigned int value)
Constructs a NetGameEventValue.
bool is_boolean() const
Is Boolean.
bool is_binary() const
Is Binary.
int get_character() const
To character.
char value_char
Definition event_value.h:242
unsigned int get_ucharacter() const
To unsigned character.
bool is_ucharacter() const
Is Ucharacter.
unsigned int get_member_count() const
void add_member(const NetGameEventValue &value)
Add member.
bool is_integer() const
Is Integer.
Type
Definition event_value.h:43
operator std::string() const
Definition event_value.h:226
NetGameEventValue(char value)
Constructs a NetGameEventValue.
float value_float
Definition event_value.h:244
bool is_uinteger() const
Is Uinteger.
NetGameEventValue(float value)
Constructs a NetGameEventValue.
static std::string to_string(const NetGameEventValue &)
Helper function to obtain a string representation of an EventValue object.
bool get_boolean() const
To boolean.
NetGameEventValue(const DataBuffer &value)
Constructs a NetGameEventValue.
bool is_character() const
Is Character.
Definition clanapp.h:36