1 #ifndef JSON_SPIRIT_VALUE
2 #define JSON_SPIRIT_VALUE
9 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
19 #include <boost/config.hpp>
20 #include <boost/cstdint.hpp>
21 #include <boost/shared_ptr.hpp>
22 #include <boost/variant.hpp>
27 static const char* Value_type_name[]={
"obj",
"array",
"str",
"bool",
"int",
"real",
"null"};
29 template<
class Config >
63 const String_type&
get_str()
const;
75 template<
typename T > T
get_value()
const;
85 boost::recursive_wrapper< Object >, boost::recursive_wrapper< Array >,
95 template<
class Config >
109 template<
class String >
118 static Value_type&
add( Object_type& obj,
const String_type&
name,
const Value_type&
value )
120 obj.push_back(
Pair_type( name , value ) );
122 return obj.back().value_;
125 static String_type
get_name(
const Pair_type& pair )
147 #ifndef BOOST_NO_STD_WSTRING
159 template<
class String >
168 static Value_type&
add( Object_type& obj,
const String_type&
name,
const Value_type&
value )
173 static String_type
get_name(
const Pair_type& pair )
194 #ifndef BOOST_NO_STD_WSTRING
208 template<
class Config >
211 template<
class Config >
214 , is_uint64_( false )
218 template<
class Config >
222 , is_uint64_( false )
226 template<
class Config >
230 , is_uint64_( false )
234 template<
class Config >
238 , is_uint64_( false )
242 template<
class Config >
246 , is_uint64_( false )
250 template<
class Config >
254 , is_uint64_( false )
258 template<
class Config >
262 , is_uint64_( false )
266 template<
class Config >
270 , is_uint64_( false )
274 template<
class Config >
282 template<
class Config >
286 , is_uint64_( false )
290 template<
class Config >
292 : type_( other.type() )
294 , is_uint64_( other.is_uint64_ )
298 template<
class Config >
303 std::swap( type_, tmp.
type_ );
304 std::swap( v_, tmp.
v_ );
310 template<
class Config >
313 if(
this == &lhs )
return true;
315 if( type() != lhs.
type() )
return false;
320 template<
class Config >
326 template<
class Config >
332 template<
class Config >
338 template<
class Config >
341 if( type() != vtype )
343 std::ostringstream os;
346 os <<
"value is type " << Value_type_name[type()] <<
", expected " << Value_type_name[vtype];
348 throw std::runtime_error( os.str() );
352 template<
class Config >
357 return *boost::get< String_type >( &v_ );
360 template<
class Config >
365 return *boost::get< Object >( &v_ );
368 template<
class Config >
373 return *boost::get< Array >( &v_ );
376 template<
class Config >
381 return boost::get< bool >( v_ );
384 template<
class Config >
389 return static_cast< int >( get_int64() );
392 template<
class Config >
397 return boost::get< boost::int64_t >( v_ );
400 template<
class Config >
408 template<
class Config >
413 return is_uint64() ?
static_cast< double >( get_uint64() )
414 : static_cast< double >( get_int64() );
419 return boost::get< double >( v_ );
422 template<
class Config >
427 return *boost::get< Object >( &v_ );
430 template<
class Config >
435 return *boost::get< Array >( &v_ );
438 template<
class Config >
445 template<
class Config >
448 if(
this == &lhs )
return true;
455 template <
class String_type >
460 for(
const char* p = c_str; *p != 0; ++p )
472 template<
typename T >
477 template<
class Value >
483 template<
class Value >
489 template<
class Value >
495 template<
class Value >
501 template<
class Value >
507 template<
class Value >
513 template<
class Value >
519 template<
class Value >
526 template<
class Config >
527 template<
typename T >
Config::Value_type Value_type
const Object & get_obj() const
wmConfig::Array_type wmArray
std::vector< Pair_type > Object_type
std::map< String_type, Value_type > Object_type
static Value_type get_value(const Pair_type &pair)
Config::Object_type Object
Config_vector< std::string > Config
Pair_impl< Config_vector > Pair_type
bool operator==(const Pair_impl &lhs) const
std::vector< Value_type > Array_type
boost::uint64_t get_uint64() const
wConfig::Value_type wValue
Config_map< std::wstring > wmConfig
Config::String_type String_type
static String_type get_name(const Pair_type &pair)
Value_impl< Config_map > Value_type
Value_impl< Config_vector > Value_type
Object_type::value_type Pair_type
Value_impl & operator=(const Value_impl &lhs)
Config::Object_type Object
Pair_impl(const String_type &name, const Value_type &value)
static String_type get_name(const Pair_type &pair)
const Array & get_array() const
mConfig::Value_type mValue
Config::String_type String_type
wmConfig::Object_type wmObject
void check_type(const Value_type vtype) const
mConfig::Array_type mArray
static Value_type get_value(const Pair_type &pair)
wmConfig::Value_type wmValue
unsigned long long uint64_t
static const Value_impl null
int get_value(const Value &value, Type_to_type< int >)
const String_type & get_str() const
Config_map< std::string > mConfig
String_type to_str(const char *c_str)
mConfig::Object_type mObject
Config_vector< std::wstring > wConfig
wConfig::Array_type wArray
wConfig::Object_type wObject
boost::int64_t get_int64() const
boost::variant< String_type, boost::recursive_wrapper< Object >, boost::recursive_wrapper< Array >, bool, boost::int64_t, double > Variant
String_type::const_pointer Const_str_ptr
bool operator==(const Value_impl &lhs) const
static Value_type & add(Object_type &obj, const String_type &name, const Value_type &value)
std::vector< Value_type > Array_type
static Value_type & add(Object_type &obj, const String_type &name, const Value_type &value)