genesis 1 #ifndef JSON_SPIRIT_UTILS
genesis 2 #define JSON_SPIRIT_UTILS
genesis 3
genesis 4
genesis 5
genesis 6
genesis 7
genesis 8
genesis 9 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
genesis 10 # pragma once
genesis 11 #endif
genesis 12
genesis 13 #include "json_spirit_value.h"
genesis 14 #include <map>
genesis 15
genesis 16 namespace json_spirit
genesis 17 {
genesis 18 template< class Obj_t, class Map_t >
genesis 19 void obj_to_map( const Obj_t& obj, Map_t& mp_obj )
genesis 20 {
genesis 21 mp_obj.clear();
genesis 22
genesis 23 for( typename Obj_t::const_iterator i = obj.begin(); i != obj.end(); ++i )
genesis 24 {
genesis 25 mp_obj[ i->name_ ] = i->value_;
genesis 26 }
genesis 27 }
genesis 28
genesis 29 template< class Obj_t, class Map_t >
genesis 30 void map_to_obj( const Map_t& mp_obj, Obj_t& obj )
genesis 31 {
genesis 32 obj.clear();
genesis 33
genesis 34 for( typename Map_t::const_iterator i = mp_obj.begin(); i != mp_obj.end(); ++i )
genesis 35 {
genesis 36 obj.push_back( typename Obj_t::value_type( i->first, i->second ) );
genesis 37 }
genesis 38 }
genesis 39
genesis 40 typedef std::map< std::string, Value > Mapped_obj;
genesis 41
genesis 42 #ifndef BOOST_NO_STD_WSTRING
genesis 43 typedef std::map< std::wstring, wValue > wMapped_obj;
genesis 44 #endif
genesis 45
genesis 46 template< class Object_type, class String_type >
genesis 47 const typename Object_type::value_type::Value_type& find_value( const Object_type& obj, const String_type& name )
genesis 48 {
genesis 49 for( typename Object_type::const_iterator i = obj.begin(); i != obj.end(); ++i )
genesis 50 {
genesis 51 if( i->name_ == name )
genesis 52 {
genesis 53 return i->value_;
genesis 54 }
genesis 55 }
genesis 56
genesis 57 return Object_type::value_type::Value_type::null;
genesis 58 }
genesis 59 }
genesis 60
genesis 61 #endif