Back to home page

Bitcoin sources

 
 

    


File indexing completed on 2020-06-25 15:43:19

0001 #ifndef JSON_SPIRIT_UTILS
0002 #define JSON_SPIRIT_UTILS
0003 
0004 //          Copyright John W. Wilkinson 2007 - 2009.
0005 // Distributed under the MIT License, see accompanying file LICENSE.txt
0006 
0007 // json spirit version 4.03
0008 
0009 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
0010 # pragma once
0011 #endif
0012 
0013 #include "json_spirit_value.h"
0014 #include <map>
0015 
0016 namespace json_spirit
0017 { 
0018     template< class Obj_t, class Map_t >
0019     void obj_to_map( const Obj_t& obj, Map_t& mp_obj )
0020     {
0021         mp_obj.clear();
0022 
0023         for( typename Obj_t::const_iterator i = obj.begin(); i != obj.end(); ++i )
0024         {
0025             mp_obj[ i->name_ ] = i->value_;
0026         }
0027     }
0028 
0029     template< class Obj_t, class Map_t >
0030     void map_to_obj( const Map_t& mp_obj, Obj_t& obj )
0031     {
0032         obj.clear();
0033 
0034         for( typename Map_t::const_iterator i = mp_obj.begin(); i != mp_obj.end(); ++i )
0035         {
0036             obj.push_back( typename Obj_t::value_type( i->first, i->second ) );
0037         }
0038     }
0039 
0040     typedef std::map< std::string, Value > Mapped_obj;
0041 
0042 #ifndef BOOST_NO_STD_WSTRING
0043     typedef std::map< std::wstring, wValue > wMapped_obj;
0044 #endif
0045 
0046     template< class Object_type, class String_type >
0047     const typename Object_type::value_type::Value_type& find_value( const Object_type& obj, const String_type& name )
0048     {
0049         for( typename Object_type::const_iterator i = obj.begin(); i != obj.end(); ++i )
0050         {
0051             if( i->name_ == name )
0052             {
0053                 return i->value_;
0054             }
0055         }
0056 
0057         return Object_type::value_type::Value_type::null;
0058     }
0059 }
0060 
0061 #endif