00001 /* 00002 ** ClanLib SDK 00003 ** Copyright (c) 1997-2011 The ClanLib Team 00004 ** 00005 ** This software is provided 'as-is', without any express or implied 00006 ** warranty. In no event will the authors be held liable for any damages 00007 ** arising from the use of this software. 00008 ** 00009 ** Permission is granted to anyone to use this software for any purpose, 00010 ** including commercial applications, and to alter it and redistribute it 00011 ** freely, subject to the following restrictions: 00012 ** 00013 ** 1. The origin of this software must not be misrepresented; you must not 00014 ** claim that you wrote the original software. If you use this software 00015 ** in a product, an acknowledgment in the product documentation would be 00016 ** appreciated but is not required. 00017 ** 2. Altered source versions must be plainly marked as such, and must not be 00018 ** misrepresented as being the original software. 00019 ** 3. This notice may not be removed or altered from any source distribution. 00020 ** 00021 ** Note: Some of the libraries ClanLib may link to may have additional 00022 ** requirements or restrictions. 00023 ** 00024 ** File Author(s): 00025 ** 00026 ** Magnus Norddahl 00027 */ 00028 00031 00032 #pragma once 00033 00034 #include "../api_network.h" 00035 00039 class CL_API_NETWORK CL_NetGameEventValue 00040 { 00041 public: 00042 enum Type 00043 { 00044 null, 00045 integer, 00046 uinteger, 00047 string, 00048 boolean, 00049 number, 00050 complex 00051 }; 00052 00053 CL_NetGameEventValue(); 00054 00058 CL_NetGameEventValue(int value); 00059 00063 CL_NetGameEventValue(unsigned int value); 00064 00068 CL_NetGameEventValue(float value); 00069 00073 CL_NetGameEventValue(const CL_String &value); 00074 00078 CL_NetGameEventValue(const CL_StringRef &value); 00079 00083 CL_NetGameEventValue(const char *str); 00084 00088 CL_NetGameEventValue(const wchar_t *str); 00089 explicit CL_NetGameEventValue(bool value); 00090 00094 CL_NetGameEventValue(Type type); 00095 00099 Type get_type() const; 00100 00104 bool is_null() const; 00105 00109 bool is_uinteger() const; 00110 00114 bool is_integer() const; 00115 00119 bool is_number() const; 00120 00124 bool is_string() const; 00125 00129 bool is_boolean() const; 00130 00134 bool is_complex() const; 00135 00136 unsigned int get_member_count() const; 00137 const CL_NetGameEventValue &get_member(unsigned int index) const; 00138 00142 void add_member(const CL_NetGameEventValue &value); 00143 00148 void set_member(unsigned int index, const CL_NetGameEventValue &value); 00149 00150 unsigned int to_uinteger() const; 00151 00155 int to_integer() const; 00156 00160 float to_number() const; 00161 00165 CL_String to_string() const; 00166 00170 bool to_boolean() const; 00171 00172 inline operator unsigned int() const { return to_uinteger(); } 00173 inline operator int() const { return to_integer(); } 00174 inline operator float() const { return to_number(); } 00175 inline operator CL_String() const { return to_string(); } 00176 inline operator bool() const { return to_boolean(); } 00177 00178 private: 00179 00181 void throw_if_not_complex() const; 00182 00183 Type type; 00184 union 00185 { 00186 int value_int; 00187 unsigned int value_uint; 00188 float value_float; 00189 bool value_bool; 00190 }; 00191 CL_String value_string; 00192 std::vector<CL_NetGameEventValue> value_complex; 00193 }; 00194 00196