00001 /* 00002 ** ClanLib SDK 00003 ** Copyright (c) 1997-2009 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 00037 class CL_NetGameEventValue 00038 { 00039 public: 00040 enum Type 00041 { 00042 null, 00043 integer, 00044 uinteger, 00045 string, 00046 boolean, 00047 number, 00048 complex 00049 }; 00050 00051 CL_NetGameEventValue(); 00052 00056 CL_NetGameEventValue(int value); 00057 00061 CL_NetGameEventValue(unsigned int value); 00062 00066 CL_NetGameEventValue(float value); 00067 00071 CL_NetGameEventValue(const CL_String &value); 00072 00076 CL_NetGameEventValue(const CL_StringRef &value); 00077 00081 CL_NetGameEventValue(const char *str); 00082 00086 CL_NetGameEventValue(const wchar_t *str); 00087 explicit CL_NetGameEventValue(bool value); 00088 00092 CL_NetGameEventValue(Type type); 00093 00097 Type get_type() const; 00098 00102 bool is_null() const; 00103 00107 bool is_uinteger() const; 00108 00112 bool is_integer() const; 00113 00117 bool is_number() const; 00118 00122 bool is_string() const; 00123 00127 bool is_boolean() const; 00128 00132 bool is_complex() const; 00133 00134 unsigned int get_member_count() const; 00135 const CL_NetGameEventValue &get_member(unsigned int index) const; 00136 00140 void add_member(const CL_NetGameEventValue &value); 00141 00146 void set_member(unsigned int index, const CL_NetGameEventValue &value); 00147 00148 unsigned int to_uinteger() const; 00149 00153 int to_integer() const; 00154 00158 float to_number() const; 00159 00163 CL_String to_string() const; 00164 00168 bool to_boolean() const; 00169 00170 inline operator unsigned int() const { return to_uinteger(); } 00171 inline operator int() const { return to_integer(); } 00172 inline operator float() const { return to_number(); } 00173 inline operator CL_String() const { return to_string(); } 00174 inline operator bool() const { return to_boolean(); } 00175 00176 private: 00177 00179 void throw_if_not_complex() const; 00180 00181 Type type; 00182 union 00183 { 00184 int value_int; 00185 unsigned int value_uint; 00186 float value_float; 00187 bool value_bool; 00188 }; 00189 CL_String value_string; 00190 std::vector<CL_NetGameEventValue> value_complex; 00191 }; 00192 00194
1.4.6