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 #define JSON_SPIRIT_MVALUE_ENABLED 36 template<
class Config >
44 typedef typename Config::Object_type
Object;
45 typedef typename Config::Array_type
Array;
59 template<
class Iter >
62 template< BOOST_VARIANT_ENUM_PARAMS(
typename T ) >
63 Value_impl(
const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& variant );
73 bool is_uint64()
const;
76 const String_type&
get_str()
const;
77 const Object& get_obj()
const;
78 const Array& get_array()
const;
79 bool get_bool()
const;
81 boost::int64_t get_int64()
const;
82 boost::uint64_t get_uint64()
const;
83 double get_real()
const;
88 template<
typename T > T
get_value()
const;
95 void check_type(
const Value_type vtype )
const;
97 typedef boost::variant< boost::recursive_wrapper< Object >, boost::recursive_wrapper< Array >,
98 String_type, bool, boost::int64_t, double,
Null, boost::uint64_t >
Variant;
106 template<
typename T,
typename A,
template<
typename,
typename >
class Cont >
109 return Array( cont.begin(), cont.end() );
114 return static_cast< boost::int64_t
>( i );
127 template<
class Config >
137 Pair_impl(
const String_type& name,
const Value_type& value );
145 #if defined( JSON_SPIRIT_VALUE_ENABLED ) || defined( JSON_SPIRIT_WVALUE_ENABLED ) 146 template<
class String >
149 typedef String String_type;
155 static Value_type& add( Object_type& obj,
const String_type& name,
const Value_type& value )
157 obj.push_back( Pair_type( name , value ) );
159 return obj.back().value_;
162 static String_type get_name(
const Pair_type& pair )
167 static Value_type
get_value(
const Pair_type& pair )
176 #ifdef JSON_SPIRIT_VALUE_ENABLED 177 typedef Config_vector< std::string > Config;
180 typedef Config::Pair_type Pair;
181 typedef Config::Object_type Object;
182 typedef Config::Array_type Array;
187 #if defined( JSON_SPIRIT_WVALUE_ENABLED ) && !defined( BOOST_NO_STD_WSTRING ) 188 typedef Config_vector< std::wstring > wConfig;
191 typedef wConfig::Pair_type wPair;
192 typedef wConfig::Object_type wObject;
193 typedef wConfig::Array_type wArray;
198 #if defined( JSON_SPIRIT_MVALUE_ENABLED ) || defined( JSON_SPIRIT_WMVALUE_ENABLED ) 199 template<
class String >
208 static Value_type&
add( Object_type& obj,
const String_type& name,
const Value_type& value )
210 return obj[ name ] = value;
213 static String_type
get_name(
const Pair_type& pair )
227 #ifdef JSON_SPIRIT_MVALUE_ENABLED 237 #if defined( JSON_SPIRIT_WMVALUE_ENABLED ) && !defined( BOOST_NO_STD_WSTRING ) 241 typedef wmConfig::Object_type wmObject;
242 typedef wmConfig::Array_type wmArray;
254 template<
class Config >
257 template<
class Config >
263 template<
class Config >
265 :
v_( String_type( value ) )
269 template<
class Config >
275 template<
class Config >
281 template<
class Config >
287 template<
class Config >
293 template<
class Config >
295 :
v_( static_cast<
boost::int64_t >( value ) )
299 template<
class Config >
305 template<
class Config >
311 template<
class Config >
317 template<
class Config >
323 template<
class Config >
324 template<
class Iter >
326 :
v_( Array( first, last ) )
330 template<
class Config >
331 template< BOOST_VARIANT_ENUM_PARAMS(
typename T ) >
337 template<
class Config >
342 std::swap(
v_, tmp.
v_ );
347 template<
class Config >
350 if(
this == &lhs )
return true;
352 if(
type() != lhs.
type() )
return false;
357 template<
class Config >
368 template<
class Config >
371 return v_.which() == null_type + 1;
374 template<
class Config >
380 template<
class Config >
383 if(
type() != vtype )
385 std::ostringstream os;
387 os <<
"value type is " <<
type() <<
" not " << vtype;
389 throw std::runtime_error( os.str() );
393 template<
class Config >
398 return *boost::get< String_type >( &
v_ );
401 template<
class Config >
406 return *boost::get< Object >( &
v_ );
409 template<
class Config >
414 return *boost::get< Array >( &
v_ );
417 template<
class Config >
422 return boost::get< bool >(
v_ );
425 template<
class Config >
430 return static_cast< int >(
get_int64() );
433 template<
class Config >
440 return static_cast< boost::int64_t
>(
get_uint64() );
443 return boost::get< boost::int64_t >(
v_ );
446 template<
class Config >
453 return static_cast< boost::uint64_t
>(
get_int64() );
456 return boost::get< boost::uint64_t >(
v_ );
459 template<
class Config >
470 return boost::get< double >(
v_ );
473 template<
class Config >
478 return *boost::get< Object >( &
v_ );
481 template<
class Config >
486 return *boost::get< Array >( &
v_ );
489 template<
class Config >
496 template<
class Config >
499 if(
this == &lhs )
return true;
506 template <
class String_type >
511 for(
const char* p = c_str; *p != 0; ++p )
523 template<
typename T >
528 template<
class Value >
531 return value.get_int();
534 template<
class Value >
537 return value.get_int64();
540 template<
class Value >
543 return value.get_uint64();
546 template<
class Value >
549 return value.get_real();
552 template<
class Value >
555 return value.get_str();
558 template<
class Value >
561 return value.get_array();
564 template<
class Value >
567 return value.get_obj();
570 template<
class Value >
573 return value.get_bool();
577 template<
class Config >
578 template<
typename T >
boost::uint64_t get_uint64() const
boost::int64_t get_int64() const
boost::variant< boost::recursive_wrapper< Object >, boost::recursive_wrapper< Array >, String_type, bool, boost::int64_t, double, Null, boost::uint64_t > Variant
bool get_value(const Value &value, Type_to_type< bool >)
static const Value_impl null
Variant operator()(const T &t) const
bool operator==(const Pair_impl &lhs) const
static Value_type get_value(const Pair_type &pair)
static String_type get_name(const Pair_type &pair)
Config::Value_type Value_type
mConfig::Value_type mValue
Config::String_type String_type
String_type::const_pointer Const_str_ptr
void check_type(const Value_type vtype) const
bool operator==(const Null &, const Null &)
mConfig::Array_type mArray
Config::Object_type Object
const String_type & get_str() const
int get_value(const Value &value, Type_to_type< int >)
Variant operator()(int i) const
Config::String_type String_type
Config_map< std::string > mConfig
String_type to_str(const char *c_str)
std::map< String_type, Value_type > Object_type
mConfig::Object_type mObject
Value_impl< Config_map > Value_type
const Array & get_array() const
Variant operator()(const Cont< T, A > &cont) const
const Object & get_obj() const
bool operator==(const Value_impl &lhs) const
Value_impl & operator=(const Value_impl &lhs)
std::pair< String_type, Value_type > Pair_type
std::string get_str(std::string::const_iterator begin, std::string::const_iterator end)
std::vector< Value_type > Array_type
static Value_type & add(Object_type &obj, const String_type &name, const Value_type &value)