7 #ifndef HELICS_CPP98_DATABUFFER_HPP_
8 #define HELICS_CPP98_DATABUFFER_HPP_
10 #include "helics/helics.h"
11 #include "helicsExceptions.hpp"
20 DataBuffer() HELICS_NOTHROW: buff(helicsCreateDataBuffer(0)) {}
23 void toBytes(
double val) { helicsDoubleToBytes(val, buff); }
24 void toBytes(int64_t val) { helicsIntegerToBytes(val, buff); }
25 void toBytes(
const std::string& val) { helicsStringToBytes(val.c_str(), buff); }
26 void toBytes(
const std::vector<double>& val)
28 helicsVectorToBytes(val.data(),
static_cast<int>(val.size()), buff);
30 void toBytes(
const std::complex<double> val)
32 helicsComplexToBytes(val.real(), val.imag(), buff);
34 void toBytes(
const double* vals,
int size) { helicsVectorToBytes(vals,
size, buff); }
35 void toBytes(
const std::string& name,
double val)
37 helicsNamedPointToBytes(name.c_str(), val, buff);
40 void toBytes(
char val) { helicsCharToBytes(val, buff); }
43 int size() {
return helicsDataBufferSize(buff); }
46 int capacity() {
return helicsDataBufferCapacity(buff); }
49 int stringSize() {
return helicsDataBufferStringSize(buff); }
57 result.resize(
static_cast<size_t>(
size) + 1);
59 helicsDataBufferToString(buff, &result[0],
size + 1, &
size);
60 if (!(result.empty()) && (result[
static_cast<size_t>(
size) - 1] ==
'\0')) {
61 result.resize(
static_cast<size_t>(
size) - 1);
72 str.resize(
static_cast<size_t>(
size) + 1);
74 helicsDataBufferToString(buff, &str[0],
size + 1, &
size);
75 if (!(str.empty()) && (str[
static_cast<size_t>(
size) - 1] ==
'\0')) {
76 str.resize(
static_cast<size_t>(
size) - 1);
85 int size = helicsDataBufferStringSize(buff);
87 name.resize(
static_cast<size_t>(
size) + 1);
89 helicsDataBufferToNamedPoint(buff, &name[0],
size + 1, &
size, val);
93 int64_t
toInt() {
return helicsDataBufferToInteger(buff); }
97 HelicsBool val = helicsDataBufferToBoolean(buff);
101 double toDouble() {
return helicsDataBufferToDouble(buff); }
106 std::complex<double> result(hc.real, hc.imag);
115 helicsDataBufferToVector(buff, data, maxlen, &maxlen);
122 int actualSize = helicsDataBufferVectorSize(buff);
123 data.resize(actualSize);
124 helicsDataBufferToVector(buff, data.data(), actualSize, HELICS_NULL_POINTER);
133 helicsDataBufferToComplexVector(buff, data, maxlen, &maxlen);