4 #include "ssarchiver.h"
5 #include "ssstring_uty.h"
12 typedef wchar_t SsChar;
13 typedef std::vector<SsValue> SsArray;
14 typedef std::map<SsString,SsValue> SsHash;
46 SsValue() : type(unkown) , _str(0){}
48 explicit SsValue(
bool b) : type(boolean_type) { _bool = b; }
49 explicit SsValue(
int n) : type(int_type) { _int = n; }
50 explicit SsValue(
float n) : type(float_type) { _float = n; }
51 explicit SsValue(SsString& str) { type = string_type; _str =
new SsString(str); }
52 explicit SsValue(
const char* str) { type = string_type; _str =
new SsString(str); }
56 _array =
new SsArray(n);
60 explicit SsValue(SsHash& n) { type = hash_type; _hash =
new SsHash(n); }
69 _str =
new SsString( *x._str );
70 _float_temp = (float)atof( _str->c_str() );
71 _int_temp = atoi( _str->c_str() );
75 _float_temp = (float)_int;
76 _bool_temp = _int == 1 ?
true :
false;
80 _int_temp = (int)_float;
81 _bool_temp = _int > 0 ?
true :
false;
87 _array =
new SsArray( *x._array);
90 _hash =
new SsHash( *x._hash);
110 if ( type == string_type && _str) {
115 if ( type == array_type && _array){
119 if ( type == hash_type && _hash )
133 template <
typename T>
bool is()
const;
134 template <
typename T>
const T&
get()
const;
135 template <
typename T> T&
get();
137 const SsValue& operator[](
const std::string& key)
const
141 if ( type == hash_type )
143 SsHash::const_iterator i = _hash->find(key);
144 return i != _hash->end() ? i->second : r_value;
151 bool IsExistHashkey(
const std::string& key )
const
153 if ( type == hash_type )
155 SsHash::const_iterator i = _hash->find(key);
156 return i != _hash->end();
164 template <>
inline const SsString& SsValue::get<SsString>()
const {
165 static SsString ret =
"";
166 if ( this->type != string_type )
172 template <>
inline SsString& SsValue::get<SsString>() {
173 static SsString ret =
"";
174 if ( this->type != string_type )
181 template <>
inline const int& SsValue::get<int>()
const {
182 if ( this->type == float_type )
189 template <>
inline int& SsValue::get<int>() {
190 if ( this->type == float_type )
198 template <>
inline const float& SsValue::get<float>()
const {
199 if ( this->type == float_type )
206 template <>
inline float& SsValue::get<float>() {
207 if ( this->type == float_type )
215 template <>
inline const bool& SsValue::get<bool>()
const {
216 if ( this->type == boolean_type )
223 template <>
inline bool& SsValue::get<bool>() {
224 if ( this->type == boolean_type )
232 template <>
inline const SsArray& SsValue::get<SsArray>()
const {
235 template <>
inline SsArray& SsValue::get<SsArray>() {
240 template <>
inline const SsHash& SsValue::get<SsHash>()
const {
243 template <>
inline SsHash& SsValue::get<SsHash>() {
249 template <>
inline bool SsValue::is<bool>()
const {
250 return type == boolean_type;
253 template <>
inline bool SsValue::is<int>()
const {
254 return type == int_type;
257 template <>
inline bool SsValue::is<float>()
const {
258 return type == float_type;
260 template <>
inline bool SsValue::is<SsString>()
const {
261 return type == string_type;
264 template <>
inline bool SsValue::is<SsArray>()
const {
265 return type == array_type;
268 template <>
inline bool SsValue::is<SsHash>()
const {
269 return type == hash_type;
275 static SsValue SsValueSeriarizer__MakeValue(
const char* v )
277 std::string temp = v;
278 if ( is_digit_string( temp ) )
280 return SsValue( (
float)atof( v ));