ztsdb
zcpp.hpp
1 // (C) 2015 Leonardo Silvestri
2 //
3 // This file is part of ztsdb.
4 //
5 // ztsdb is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // ztsdb is distributed in the hope that it will be useful,
11 // but 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 ztsdb. If not, see <http://www.gnu.org/licenses/>.
17 
18 
19 #ifndef ZCPP_H
20 #define ZCPP_H
21 
22 
23 #include "array.hpp"
24 #include "base_types.hpp"
25 #include "misc.hpp"
26 #include "zts.hpp"
27 #include "globals.hpp"
28 
29 
34 
35 
36 namespace arr {
37 
38  size_t getHeaderLength(const std::vector<std::string>& name);
39  int writeHeader(Global::buflen_pair& buf,
40  Global::MsgType msgtype,
41  const std::vector<std::string>& names);
42 
43  template<typename T>
44  Global::buflen_pair make_append_msg(const std::vector<std::string>& names, const arr::Array<T>& a)
45  {
46  if (a.size() == 0) {
47  throw std::out_of_range("make_append_msg: no data");
48  }
49  const auto headersz = getHeaderLength(names);
50  const auto totalsz = headersz + a.getBufferSize();
51  auto buf = std::make_pair(std::make_unique<char[]>(totalsz), totalsz);
52  a.to_buffer(buf.first.get() + headersz);
53  writeHeader(buf, Global::MsgType::APPEND, names);
54  return buf;
55  }
56 
57  template<typename T>
58  Global::buflen_pair make_append_msg(const std::vector<std::string>& names, const Vector<T>& v)
59  {
60  if (v.size() == 0) {
61  throw std::out_of_range("make_append_msg: no data");
62  }
63  const auto headersz = getHeaderLength(names);
64  const auto totalsz = headersz + v.getBufferSize();
65  auto buf = std::make_pair(std::make_unique<char[]>(totalsz), totalsz);
66  v.to_buffer(buf.first.get() + headersz);
67  writeHeader(buf, Global::MsgType::APPEND_VECTOR, names);
68  return buf;
69  }
70 
71  Global::buflen_pair make_append_msg(const std::vector<std::string>& names,
72  const Vector<Global::dtime>& idx,
73  const Vector<double>& v);
74 
75 
76  // specialize the above with string and zstring so that it fails... LLL
77 
78  Global::buflen_pair make_append_msg(const std::vector<string>& name, const arr::zts& z);
79 }
80 
81 
82 
83 #endif
arr::Array::size
idx_type size() const
Get the total number of elements in the array.
Definition: array.hpp:833
arr::zts
Definition: zts.hpp:35
arr
Contains the classes and functions that implement a multidimentional array type.
Definition: allocator.hpp:29
arr::Array::getBufferSize
size_t getBufferSize() const
Definition: array.hpp:490
arr::Array
Definition: array.hpp:109