json_spirit_utils.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
  2. #ifndef JSON_SPIRIT_UTILS
  3. #define JSON_SPIRIT_UTILS
  4. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  5. # pragma once
  6. #endif
  7. #include "json_spirit_value.h"
  8. #include <map>
  9. namespace json_spirit
  10. {
  11. template< class Obj_t, class Map_t >
  12. void obj_to_map( const Obj_t& obj, Map_t& mp_obj )
  13. {
  14. mp_obj.clear();
  15. for( typename Obj_t::const_iterator i = obj.begin(); i != obj.end(); ++i )
  16. {
  17. mp_obj[ i->name_ ] = i->value_;
  18. }
  19. }
  20. template< class Obj_t, class Map_t >
  21. void map_to_obj( const Map_t& mp_obj, Obj_t& obj )
  22. {
  23. obj.clear();
  24. for( typename Map_t::const_iterator i = mp_obj.begin(); i != mp_obj.end(); ++i )
  25. {
  26. obj.push_back( typename Obj_t::value_type( i->first, i->second ) );
  27. }
  28. }
  29. typedef std::map< std::string, Value > Mapped_obj;
  30. #ifndef BOOST_NO_STD_WSTRING
  31. typedef std::map< std::wstring, wValue > wMapped_obj;
  32. #endif
  33. template< class Object_type, class String_type >
  34. const typename Object_type::value_type::Value_type& find_value( const Object_type& obj, const String_type& name )
  35. {
  36. for( typename Object_type::const_iterator i = obj.begin(); i != obj.end(); ++i )
  37. {
  38. if( i->name_ == name )
  39. {
  40. return i->value_;
  41. }
  42. }
  43. return Object_type::value_type::Value_type::null;
  44. }
  45. }
  46. #endif