IceBlobToObject.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package ArmarXCore
19  * @author Raphael Grimm ( raphael dot grimm at kit dot edu)
20  * @date 2020
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #pragma once
25 
26 #include <string_view>
27 #include <sstream>
28 
29 #include <boost/iostreams/filtering_streambuf.hpp>
30 #include <boost/iostreams/copy.hpp>
31 #include <boost/iostreams/filter/gzip.hpp>
32 
33 #include <Ice/InputStream.h>
34 
35 //raw
36 namespace armarx
37 {
38  template<class T>
39  void iceBlobToObject(T& result, const std::string_view& sv)
40  {
41  const auto first = reinterpret_cast<const Ice::Byte*>(sv.data());
42  const auto last = first + sv.size();
43  Ice::InputStream{std::make_pair(first, last)}.read(result);
44  }
45 
46  template<class T>
47  T iceBlobToObject(const std::string_view& sv)
48  {
49  T result;
50  iceBlobToObject(result, sv);
51  return result;
52  }
53 
54  template<class T>
56  {
57  void deserialize(T& result, const std::string_view& sv)
58  {
59  iceBlobToObject(result, sv);
60  }
61  T deserialize(const std::string_view& sv)
62  {
63  return iceBlobToObject<T>(sv);
64  }
65  };
66 }
67 
68 //compressed
69 namespace armarx
70 {
71  template<class T>
72  void compressedIceBlobToObject(T& result, const std::string_view& sv)
73  {
74  std::stringstream istr;
75  istr << sv;
76  boost::iostreams::filtering_istreambuf in;
77  in.push(boost::iostreams::gzip_decompressor());
78  in.push(istr);
79  std::stringstream ostr;
80  boost::iostreams::copy(in, ostr);
81 
82  iceBlobToObject(result, ostr.str());
83  }
84 
85  template<class T>
86  T compressedIceBlobToObject(const std::string_view& sv)
87  {
88  T result;
89  compressedIceBlobToObject(result, sv);
90  return result;
91  }
92 
93  template<class T>
95  {
96  void deserialize(T& result, const std::string_view& sv)
97  {
98  compressedIceBlobToObject(result, sv);
99  }
100  T deserialize(const std::string_view& sv)
101  {
102  return compressedIceBlobToObject<T>(sv);
103  }
104  };
105 }
armarx::IceBlobToObjectDeserializer::deserialize
T deserialize(const std::string_view &sv)
Definition: IceBlobToObject.h:61
armarx::compressedIceBlobToObject
void compressedIceBlobToObject(T &result, const std::string_view &sv)
Definition: IceBlobToObject.h:72
armarx::IceBlobToObjectDeserializer::deserialize
void deserialize(T &result, const std::string_view &sv)
Definition: IceBlobToObject.h:57
armarx::CompressedIceBlobToObjectDeserializer::deserialize
T deserialize(const std::string_view &sv)
Definition: IceBlobToObject.h:100
copy
Use of this software is granted under one of the following two to be chosen freely by the user Boost Software License Version Marcin Kalicinski Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this and transmit the and to prepare derivative works of the and to permit third parties to whom the Software is furnished to do all subject to the including the above license this restriction and the following must be included in all copies of the in whole or in and all derivative works of the unless such copies or derivative works are solely in the form of machine executable object code generated by a source language processor THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR A PARTICULAR TITLE AND NON INFRINGEMENT IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN TORT OR ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE The MIT Marcin Kalicinski Permission is hereby free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to copy
Definition: license.txt:39
armarx::IceBlobToObjectDeserializer
Definition: IceBlobToObject.h:55
armarx::CompressedIceBlobToObjectDeserializer::deserialize
void deserialize(T &result, const std::string_view &sv)
Definition: IceBlobToObject.h:96
armarx::iceBlobToObject
void iceBlobToObject(T &result, const std::string_view &sv)
Definition: IceBlobToObject.h:39
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::CompressedIceBlobToObjectDeserializer
Definition: IceBlobToObject.h:94