KISSCPP
a C++ library for rapid application development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ptree_queue.hpp
Go to the documentation of this file.
1 // File : ptree_queue.hpp
2 // Author: Dirk J. Botha <bothadj@gmail.com>
3 //
4 // This file is part of kisscpp library.
5 //
6 // The kisscpp library is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU Lesser General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // The kisscpp library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with the kisscpp library. If not, see <http://www.gnu.org/licenses/>.
18 
19 #ifndef _PTREE_QUEUE_HPP_
20 #define _PTREE_QUEUE_HPP_
21 
22 #include <sstream>
23 #include <boost/scoped_ptr.hpp>
24 #include <boost/asio.hpp>
25 #include <boost/property_tree/ptree.hpp>
26 #include <boost/property_tree/json_parser.hpp>
28 
29 namespace kisscpp
30 {
31 
32 //--------------------------------------------------------------------------------
33 class PtreeBase64Bicoder : public Base64BiCoder<boost::property_tree::ptree>
34 {
35  public:
38 
39  //--------------------------------------------------------------------------------
40  boost::shared_ptr<std::string> encode(const boost::shared_ptr<boost::property_tree::ptree> obj2encode)
41  {
42  using namespace boost::property_tree::json_parser;
43 
44  std::stringstream tosstrm;
45 
46  write_json(tosstrm, (*obj2encode.get()), false);
47 
48  return encodeToBase64String(tosstrm.str());
49  }
50 
51  //--------------------------------------------------------------------------------
52  boost::shared_ptr<boost::property_tree::ptree> decode(std::string& str2decode)
53  {
54  using namespace boost::property_tree::json_parser;
55 
56  boost::shared_ptr<boost::property_tree::ptree> tPtreePtr;
57  boost::shared_ptr<std::string> jsonString = decodeFromBase64(str2decode);
58  std::stringstream fromStream;
59 
60  tPtreePtr.reset(new boost::property_tree::ptree());
61 
62  fromStream << (*jsonString.get());
63 
64  read_json(fromStream, (*tPtreePtr.get()));
65 
66  return tPtreePtr;
67  }
68 };
69 
71 typedef boost::shared_ptr<PtreeQ> SharedPtreeQ;
72 typedef boost::scoped_ptr<PtreeQ> ScopedPtreeQ;
73 
75 typedef boost::shared_ptr<SafePtreeQ> SharedSafePtreeQ;
76 typedef boost::scoped_ptr<SafePtreeQ> ScopedSafePtreeQ;
77 
78 }
79 
80 #endif
81 
~PtreeBase64Bicoder()
Definition: ptree_queue.hpp:37
boost::shared_ptr< std::string > encode(const boost::shared_ptr< boost::property_tree::ptree > obj2encode)
Definition: ptree_queue.hpp:40
Definition: persisted_queue.hpp:114
ThreadsafePersistedQueue< boost::property_tree::ptree, PtreeBase64Bicoder > SafePtreeQ
Definition: ptree_queue.hpp:74
PtreeBase64Bicoder()
Definition: ptree_queue.hpp:36
boost::shared_ptr< std::string > encodeToBase64String(const std::string &s)
Definition: persisted_queue.hpp:64
Definition: persisted_queue.hpp:51
boost::shared_ptr< PtreeQ > SharedPtreeQ
Definition: ptree_queue.hpp:71
boost::shared_ptr< boost::property_tree::ptree > decode(std::string &str2decode)
Definition: ptree_queue.hpp:52
boost::shared_ptr< SafePtreeQ > SharedSafePtreeQ
Definition: ptree_queue.hpp:75
PersistedQueue< boost::property_tree::ptree, PtreeBase64Bicoder > PtreeQ
Definition: ptree_queue.hpp:70
boost::scoped_ptr< PtreeQ > ScopedPtreeQ
Definition: ptree_queue.hpp:72
Definition: ptree_queue.hpp:33
boost::shared_ptr< std::string > decodeFromBase64(const std::string &s)
Definition: persisted_queue.hpp:77
boost::scoped_ptr< SafePtreeQ > ScopedSafePtreeQ
Definition: ptree_queue.hpp:76
Definition: threadsafe_persisted_queue.hpp:34