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