Flow123d  release_3.0.0-863-g23f23ed
json_spirit_utils.h
Go to the documentation of this file.
1 #ifndef JSON_SPIRIT_UTILS
2 #define JSON_SPIRIT_UTILS
3 
4 // Copyright John W. Wilkinson 2007 - 2011
5 // Distributed under the MIT License, see accompanying file LICENSE.txt
6 
7 // json spirit version 4.05
8 
9 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
10 # pragma once
11 #endif
12 
13 #include "json_spirit_value.h"
14 #include <map>
15 
16 namespace json_spirit
17 {
18  template< class Obj_t, class Map_t >
19  void obj_to_map( const Obj_t& obj, Map_t& mp_obj )
20  {
21  mp_obj.clear();
22 
23  for( typename Obj_t::const_iterator i = obj.begin(); i != obj.end(); ++i )
24  {
25  mp_obj[ i->name_ ] = i->value_;
26  }
27  }
28 
29  template< class Obj_t, class Map_t >
30  void map_to_obj( const Map_t& mp_obj, Obj_t& obj )
31  {
32  obj.clear();
33 
34  for( typename Map_t::const_iterator i = mp_obj.begin(); i != mp_obj.end(); ++i )
35  {
36  obj.push_back( typename Obj_t::value_type( i->first, i->second ) );
37  }
38  }
39 
40 #ifdef JSON_SPIRIT_VALUE_ENABLED
41  typedef std::map< std::string, Value > Mapped_obj;
42 #endif
43 
44 #if defined( JSON_SPIRIT_WVALUE_ENABLED ) && !defined( BOOST_NO_STD_WSTRING )
45  typedef std::map< std::wstring, wValue > wMapped_obj;
46 #endif
47 
48  template< class Object_type, class String_type >
49  const typename Object_type::value_type::Value_type& find_value( const Object_type& obj, const String_type& name )
50  {
51  for( typename Object_type::const_iterator i = obj.begin(); i != obj.end(); ++i )
52  {
53  if( i->name_ == name )
54  {
55  return i->value_;
56  }
57  }
58 
59  return Object_type::value_type::Value_type::null;
60  }
61 }
62 
63 #endif
void map_to_obj(const Map_t &mp_obj, Obj_t &obj)
const Object_type::value_type::Value_type & find_value(const Object_type &obj, const String_type &name)
void obj_to_map(const Obj_t &obj, Map_t &mp_obj)