mimmo_binary_stream.cpp
1 /*---------------------------------------------------------------------------*\
2 *
3 * mimmo
4 *
5 * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of mimmo.
10 *
11 * mimmo is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * mimmo is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with mimmo. If not, see <http://www.gnu.org/licenses/>.
22 *
23 \*---------------------------------------------------------------------------*/
24 #include "mimmo_binary_stream.hpp"
25 
26 namespace mimmo{
35  IBinaryStream::IBinaryStream(std::size_t size) : bitpit::IBinaryStream(size){};
41  IBinaryStream::IBinaryStream(const char *buffer, std::size_t size) : bitpit::IBinaryStream(buffer,size){};
46  IBinaryStream::IBinaryStream(const std::vector<char> &buffer): bitpit::IBinaryStream(buffer){};
47 
56  OBinaryStream::OBinaryStream(std::size_t size): bitpit::OBinaryStream(size){};
57 
58 };
59 
66 mimmo::OBinaryStream& operator<<(mimmo::OBinaryStream &buffer, const std::string& element){
67 
68  // Copy until +1 size term, the last one is the end character (old version)
69  // std::vector<char> inputss(element.c_str(), element.c_str()+element.size()+1);
70 
71  std::vector<char> inputss(element.c_str(), element.c_str()+element.size());
72  buffer << (std::size_t)inputss.size();
73  for (char & pp: inputss){
74  buffer<<pp;
75  }
76 
77  return buffer;
78 
79 }
80 
87 mimmo::IBinaryStream& operator>>(mimmo::IBinaryStream &buffer, std::string& element){
88 
89  std::size_t nids;
90  buffer >> nids;
91  std::vector<char> inputss(nids);
92  for (std::size_t i = 0; i < nids; ++i){
93  buffer >> inputss[i];
94  }
95 
96  // Copy until -1 term, the last one is the end character (old version)
97  // element = std::string(inputss.begin(), inputss.end()-1);
98 
99  element = std::string(inputss.begin(), inputss.end());
100 
101 
102  return buffer;
103 
104 }
mimmo custom derivation of bitpit OBinaryStream (see relative doc)
mimmo::OBinaryStream & operator<<(mimmo::OBinaryStream &buf, const std::string &element)
mimmo::IBinaryStream & operator>>(mimmo::IBinaryStream &buffer, std::string &element)
mimmo custom derivation of bitpit IBinaryStream (see relative doc)