event_value.h Source File - ClanLib SDK
Description: event_value.h Source File

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
39 class NetGameEventValue
40 {
41 public:
42 enum class Type
43 {
44 null,
45 integer,
46 uinteger,
47 character,
48 ucharacter,
49 string,
50 boolean,
51 number,
52 complex,
53 binary
54 };
55
56 NetGameEventValue();
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 {
240 int value_int;
241 unsigned int value_uint;
242 char value_char;
243 unsigned char value_uchar;
244 float value_float;
245 bool value_bool;
246 };
247 std::string value_string;
248 DataBuffer value_binary;
249 std::vector<NetGameEventValue> value_complex;
250 };
251
253}
254
clan::DataBuffer
General purpose data buffer.
Definition databuffer.h:42
clan::NetGameEventValue
NetGameEventValue.
Definition event_value.h:40
clan::NetGameEventValue::set_member
void set_member(unsigned int index, const NetGameEventValue &value)
Set member.
clan::NetGameEventValue::value_int
int value_int
Definition event_value.h:240
clan::NetGameEventValue::NetGameEventValue
NetGameEventValue(unsigned char value)
Constructs a NetGameEventValue.
clan::NetGameEventValue::NetGameEventValue
NetGameEventValue(int value)
Constructs a NetGameEventValue.
clan::NetGameEventValue::NetGameEventValue
NetGameEventValue(const char *str)
Constructs a NetGameEventValue.
clan::NetGameEventValue::NetGameEventValue
NetGameEventValue(const std::string &value)
Constructs a NetGameEventValue.
clan::NetGameEventValue::NetGameEventValue
NetGameEventValue(Type type)
Constructs a NetGameEventValue.
clan::NetGameEventValue::is_complex
bool is_complex() const
Is Complex.
clan::NetGameEventValue::NetGameEventValue
NetGameEventValue(bool value)
Constructs a NetGameEventValue.
clan::NetGameEventValue::get_number
float get_number() const
To number.
clan::NetGameEventValue::get_uinteger
unsigned int get_uinteger() const
To unsigned integer.
clan::NetGameEventValue::get_string
std::string get_string() const
To string.
clan::NetGameEventValue::value_uchar
unsigned char value_uchar
Definition event_value.h:243
clan::NetGameEventValue::NetGameEventValue
NetGameEventValue()
clan::NetGameEventValue::value_uint
unsigned int value_uint
Definition event_value.h:241
clan::NetGameEventValue::NetGameEventValue
NetGameEventValue(const wchar_t *str)
Constructs a NetGameEventValue.
clan::NetGameEventValue::get_member
const NetGameEventValue & get_member(unsigned int index) const
clan::NetGameEventValue::get_integer
int get_integer() const
To integer.
clan::NetGameEventValue::get_binary
DataBuffer get_binary() const
To binary.
clan::NetGameEventValue::get_type
Type get_type() const
Get Type.
clan::NetGameEventValue::is_number
bool is_number() const
Is Number.
clan::NetGameEventValue::is_string
bool is_string() const
Is String.
clan::NetGameEventValue::value_bool
bool value_bool
Definition event_value.h:245
clan::NetGameEventValue::is_null
bool is_null() const
Is Null.
clan::NetGameEventValue::NetGameEventValue
NetGameEventValue(unsigned int value)
Constructs a NetGameEventValue.
clan::NetGameEventValue::is_boolean
bool is_boolean() const
Is Boolean.
clan::NetGameEventValue::is_binary
bool is_binary() const
Is Binary.
clan::NetGameEventValue::get_character
int get_character() const
To character.
clan::NetGameEventValue::value_char
char value_char
Definition event_value.h:242
clan::NetGameEventValue::get_ucharacter
unsigned int get_ucharacter() const
To unsigned character.
clan::NetGameEventValue::is_ucharacter
bool is_ucharacter() const
Is Ucharacter.
clan::NetGameEventValue::get_member_count
unsigned int get_member_count() const
clan::NetGameEventValue::add_member
void add_member(const NetGameEventValue &value)
Add member.
clan::NetGameEventValue::is_integer
bool is_integer() const
Is Integer.
clan::NetGameEventValue::Type
Type
Definition event_value.h:43
clan::NetGameEventValue::Type::integer
@ integer
clan::NetGameEventValue::Type::null
@ null
clan::NetGameEventValue::Type::complex
@ complex
clan::NetGameEventValue::Type::uinteger
@ uinteger
clan::NetGameEventValue::Type::boolean
@ boolean
clan::NetGameEventValue::Type::binary
@ binary
clan::NetGameEventValue::Type::character
@ character
clan::NetGameEventValue::Type::number
@ number
clan::NetGameEventValue::Type::ucharacter
@ ucharacter
clan::NetGameEventValue::string
operator std::string() const
Definition event_value.h:226
clan::NetGameEventValue::NetGameEventValue
NetGameEventValue(char value)
Constructs a NetGameEventValue.
clan::NetGameEventValue::value_float
float value_float
Definition event_value.h:244
clan::NetGameEventValue::is_uinteger
bool is_uinteger() const
Is Uinteger.
clan::NetGameEventValue::NetGameEventValue
NetGameEventValue(float value)
Constructs a NetGameEventValue.
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_boolean
bool get_boolean() const
To boolean.
clan::NetGameEventValue::NetGameEventValue
NetGameEventValue(const DataBuffer &value)
Constructs a NetGameEventValue.
clan::NetGameEventValue::is_character
bool is_character() const
Is Character.
clan
Definition clanapp.h:36