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> 25 #define JSON_SPIRIT_VALUE_ENABLED 38 template<
class Config >
61 template<
class Iter >
64 template< BOOST_VARIANT_ENUM_PARAMS(
typename T ) >
65 Value_impl(
const boost::variant< BOOST_VARIANT_ENUM_PARAMS(
T) >& variant );
75 bool is_uint64()
const;
78 const String_type&
get_str()
const;
79 const Object& get_obj()
const;
80 const Array& get_array()
const;
81 bool get_bool()
const;
85 double get_real()
const;
97 void check_type(
const Value_type vtype )
const;
99 typedef boost::variant< boost::recursive_wrapper< Object >, boost::recursive_wrapper< Array >,
108 template<
typename T,
typename A,
template<
typename,
typename >
class Cont >
111 return Array( cont.begin(), cont.end() );
116 return static_cast< boost::int64_t
>( i );
129 template<
class Config >
139 Pair_impl(
const String_type& name,
const Value_type& value );
147 #if defined( JSON_SPIRIT_VALUE_ENABLED ) || defined( JSON_SPIRIT_WVALUE_ENABLED ) 148 template<
class String >
157 static Value_type&
add( Object_type& obj,
const String_type& name,
const Value_type& value )
159 obj.push_back( Pair_type( name , value ) );
161 return obj.back().value_;
164 static const String_type&
get_name(
const Pair_type& pair )
169 static const Value_type&
get_value(
const Pair_type& pair )
178 #ifdef JSON_SPIRIT_VALUE_ENABLED 189 #if defined( JSON_SPIRIT_WVALUE_ENABLED ) && !defined( BOOST_NO_STD_WSTRING ) 193 typedef wConfig::Pair_type wPair;
194 typedef wConfig::Object_type wObject;
195 typedef wConfig::Array_type wArray;
200 #if defined( JSON_SPIRIT_MVALUE_ENABLED ) || defined( JSON_SPIRIT_WMVALUE_ENABLED ) 201 template<
class String >
204 typedef String String_type;
206 typedef std::vector< Value_type > Array_type;
207 typedef std::map< String_type, Value_type > Object_type;
208 typedef std::pair< const String_type, Value_type > Pair_type;
210 static Value_type& add( Object_type& obj,
const String_type& name,
const Value_type& value )
212 return obj[ name ] = value;
215 static const String_type& get_name(
const Pair_type& pair )
220 static const Value_type&
get_value(
const Pair_type& pair )
229 #ifdef JSON_SPIRIT_MVALUE_ENABLED 230 typedef Config_map< std::string > mConfig;
233 typedef mConfig::Object_type mObject;
234 typedef mConfig::Array_type mArray;
239 #if defined( JSON_SPIRIT_WMVALUE_ENABLED ) && !defined( BOOST_NO_STD_WSTRING ) 240 typedef Config_map< std::wstring > wmConfig;
243 typedef wmConfig::Object_type wmObject;
244 typedef wmConfig::Array_type wmArray;
256 template<
class Config >
259 template<
class Config >
265 template<
class Config >
267 :
v_( String_type( value ) )
271 template<
class Config >
277 template<
class Config >
283 template<
class Config >
289 template<
class Config >
295 template<
class Config >
297 :
v_( static_cast< boost::
int64_t >( value ) )
301 template<
class Config >
307 template<
class Config >
313 template<
class Config >
319 template<
class Config >
325 template<
class Config >
326 template<
class Iter >
328 :
v_( Array( first, last ) )
332 template<
class Config >
333 template< BOOST_VARIANT_ENUM_PARAMS(
typename T ) >
339 template<
class Config >
349 template<
class Config >
352 if(
this == &lhs )
return true;
354 if(
type() != lhs.
type() )
return false;
359 template<
class Config >
370 template<
class Config >
373 return v_.which() == null_type + 1;
376 template<
class Config >
382 template<
class Config >
385 if(
type() != vtype )
387 std::ostringstream os;
391 throw std::runtime_error( os.str() );
395 template<
class Config >
400 return *boost::get< String_type >( &
v_ );
403 template<
class Config >
408 return *boost::get< Object >( &
v_ );
411 template<
class Config >
416 return *boost::get< Array >( &
v_ );
419 template<
class Config >
424 return boost::get< bool >(
v_ );
427 template<
class Config >
432 return static_cast< int >(
get_int64() );
435 template<
class Config >
445 return boost::get< boost::int64_t >(
v_ );
448 template<
class Config >
458 return boost::get< boost::uint64_t >(
v_ );
461 template<
class Config >
472 return boost::get< double >(
v_ );
475 template<
class Config >
480 return *boost::get< Object >( &
v_ );
483 template<
class Config >
488 return *boost::get< Array >( &
v_ );
491 template<
class Config >
498 template<
class Config >
501 if(
this == &lhs )
return true;
508 template <
class String_type >
513 for(
const char* p = c_str; *p != 0; ++p )
525 template<
typename T >
530 template<
class Value >
536 template<
class Value >
542 template<
class Value >
548 template<
class Value >
554 template<
class Value >
560 template<
class Value >
566 template<
class Value >
572 template<
class Value >
579 template<
class Config >
580 template<
typename T >
596 case null_type:
return "null";
601 return "unknown type";
boost::uint64_t get_uint64() const
Definition: json_spirit_value.h:449
int get_int() const
Definition: json_spirit_value.h:428
T get_value() const
Definition: json_spirit_value.h:581
boost::int64_t get_int64() const
Definition: json_spirit_value.h:436
boost::variant< boost::recursive_wrapper< Object >, boost::recursive_wrapper< Array >, String_type, bool, boost::int64_t, double, Null, boost::uint64_t > Variant
Definition: json_spirit_value.h:100
bool get_value(const Value &value, Type_to_type< bool >)
Definition: json_spirit_value.h:573
Variant v_
Definition: json_spirit_value.h:102
Value_impl< Config_vector > Value_type
Definition: json_spirit_value.h:152
Pair_impl< Config_vector > Pair_type
Definition: json_spirit_value.h:153
static const Value_impl null
Definition: json_spirit_value.h:93
Variant operator()(const T &t) const
Definition: json_spirit_value.h:120
bool operator==(const Pair_impl &lhs) const
Definition: json_spirit_value.h:499
double get_real() const
Definition: json_spirit_value.h:462
Config_vector< std::string > Config
Definition: json_spirit_value.h:179
static void swap(UniqueRange &p1, UniqueRange &p2)
Definition: unique_range.h:198
Definition: json_spirit_error_position.h:15
std::vector< Pair_type > Object_type
Definition: json_spirit_value.h:155
Definition: json_spirit_value.h:36
std::vector< Value_type > Array_type
Definition: json_spirit_value.h:154
Config::Value_type Value_type
Definition: json_spirit_value.h:133
Config::Object_type Object
Definition: json_spirit_value.h:183
Definition: json_spirit_value.h:40
Definition: json_spirit_value.h:149
bool is_uint64() const
Definition: json_spirit_value.h:371
Value_type value_
Definition: json_spirit_value.h:144
Definition: json_spirit_value.h:32
Config::String_type String_type
Definition: json_spirit_value.h:45
Config Config_type
Definition: json_spirit_value.h:44
String_type::const_pointer Const_str_ptr
Definition: json_spirit_value.h:48
bool get_bool() const
Definition: json_spirit_value.h:420
void check_type(const Value_type vtype) const
Definition: json_spirit_value.h:383
bool operator==(const Null &, const Null &)
Definition: json_spirit_value.h:251
unsigned long long uint64_t
Definition: wposix_types.h:57
Config::Value_type Value
Definition: json_spirit_value.h:181
Definition: json_spirit_value.h:526
Value_type
Definition: json_spirit_value.h:32
Config::Object_type Object
Definition: json_spirit_value.h:46
const String_type & get_str() const
Definition: json_spirit_value.h:396
Definition: json_spirit_value.h:104
int get_value(const Value &value, Type_to_type< int >)
Definition: json_spirit_value.h:531
String_type name_
Definition: json_spirit_value.h:143
Variant operator()(int i) const
Definition: json_spirit_value.h:114
Definition: json_spirit_value.h:32
Definition: json_spirit_value.h:32
static Value_type & add(Object_type &obj, const String_type &name, const Value_type &value)
Definition: json_spirit_value.h:157
Config::Array_type Array
Definition: json_spirit_value.h:184
Config::String_type String_type
Definition: json_spirit_value.h:132
String_type to_str(const char *c_str)
Definition: json_spirit_value.h:509
#define T(string_literal)
Definition: secure_crt.cpp:76
Definition: json_spirit_value.h:32
Value_type type() const
Definition: json_spirit_value.h:360
Config::Array_type Array
Definition: json_spirit_value.h:47
const Array & get_array() const
Definition: json_spirit_value.h:412
Definition: json_spirit_value.h:32
String String_type
Definition: json_spirit_value.h:151
Value_impl()
Definition: json_spirit_value.h:260
Pair_impl()
Definition: json_spirit_value.h:135
static const Value_type & get_value(const Pair_type &pair)
Definition: json_spirit_value.h:169
Variant operator()(const Cont< T, A > &cont) const
Definition: json_spirit_value.h:109
static const String_type & get_name(const Pair_type &pair)
Definition: json_spirit_value.h:164
Definition: json_spirit_value.h:32
Definition: json_spirit_value.h:130
static std::string value_type_to_string(Value_type vtype)
Definition: json_spirit_value.h:586
Definition: json_spirit_value.h:32
const Object & get_obj() const
Definition: json_spirit_value.h:404
bool operator==(const Value_impl &lhs) const
Definition: json_spirit_value.h:350
Value_impl & operator=(const Value_impl &lhs)
Definition: json_spirit_value.h:340
std::string get_str(std::string::const_iterator begin, std::string::const_iterator end)
Definition: json_spirit_reader_template.h:176
Config::Pair_type Pair
Definition: json_spirit_value.h:182
bool is_null() const
Definition: json_spirit_value.h:377
long long int64_t
Definition: wposix_types.h:48