cisst-saw
Loading...
Searching...
No Matches
cmnDataFunctions.h
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3
4/*
5 Author(s): Anton Deguet
6 Created on: 2011-06-27
7
8 (C) Copyright 2011-2025 Johns Hopkins University (JHU), All Rights Reserved.
9
10--- begin cisst license - do not edit ---
11
12This software is provided "as is" under an open source license, with
13no warranty. The complete license can be found in license.txt and
14http://www.cisst.org/cisst/license.txt.
15
16--- end cisst license ---
17*/
18
19#pragma once
20#ifndef _cmnDataFunctions_h
21#define _cmnDataFunctions_h
22
23#include <string.h> // for memcpy
24#include <iostream>
25#include <sstream>
29
30// always include last
32
49template <typename _elementType>
51{
52public:
53 enum {IS_SPECIALIZED = 0};
54
55 typedef _elementType DataType;
56
59 static
60 std::string
61 HumanReadable(const DataType & data);
62
70 static
71 void
72 Copy(DataType & data, const DataType & source);
73
81 static
82 std::string
83 SerializeDescription(const DataType & data, const char delimiter,
84 const std::string & userDescription = "");
85
92 static
93 void
94 SerializeText(const DataType & data, std::ostream & outputStream,
95 const char delimiter = ',') CISST_THROW(std::runtime_error);
96
106 static
107 void
108 DeSerializeText(DataType & data, std::istream & inputStream,
109 const char delimiter = ',') CISST_THROW(std::runtime_error);
110
113 static
114 void
115 SerializeBinary(const DataType & data, std::ostream & outputStream)
116 CISST_THROW(std::runtime_error);
117
120 static
121 void
122 DeSerializeBinary(DataType & data, std::istream & inputStream,
123 const cmnDataFormat & localFormat,
124 const cmnDataFormat & remoteFormat) CISST_THROW(std::runtime_error);
125
130 static
131 size_t
133
141 static
142 size_t
143 SerializeBinary(const DataType & data, char * buffer, size_t bufferSize);
144
145 static
146 size_t
147 DeSerializeBinary(DataType & data, const char * buffer, size_t bufferSize,
148 const cmnDataFormat & CMN_UNUSED(localFormat),
149 const cmnDataFormat & CMN_UNUSED(remoteFormat));
150
151 static
152 std::string
153 ScalarDescription(const DataType & data, const size_t index, const std::string & userDescription = "")
154 CISST_THROW(std::out_of_range);
155
156 static
157 double
158 Scalar(const DataType & data, const size_t index)
159 CISST_THROW(std::out_of_range);
160
161 static
162 size_t ScalarNumber(const DataType & data);
163
164 static
165 bool ScalarNumberIsFixed(const DataType & data);
166};
167
168
169template <typename _elementType>
170void cmnDataCopy(_elementType & destination, const _elementType & source)
171{
172 cmnData<_elementType>::Copy(destination, source);
173}
174
175template <typename _elementType>
176std::string cmnDataHumanReadable(const _elementType & data)
177{
179}
180
181
182/* Native types to overload:
183 bool
184 char
185 unsigned char
186 short
187 unsigned short
188 int
189 unsigned int
190 long long int
191 unsigned long long int
192 float
193 double
194*/
198
204CMN_DATA_SPECIALIZE_ALL_BYTE_SWAP(unsigned long int, uli);
206CMN_DATA_SPECIALIZE_ALL_BYTE_SWAP(unsigned long long int, ulli);
209
213size_t CISST_EXPORT cmnDataDeSerializeBinary_size_t(size_t & data, const char * buffer, size_t bufferSize,
214 const cmnDataFormat & localFormat,
215 const cmnDataFormat & remoteFormat);
216
218 std::istream & inputStream,
219 const cmnDataFormat & localFormat,
220 const cmnDataFormat & remoteFormat) CISST_THROW(std::runtime_error);
222
224void CISST_EXPORT cmnDataDeSerializeTextDelimiter(std::istream & inputStream, const char delimiter, const char * className)
225 CISST_THROW(std::runtime_error);
226
227#endif // _cmnDataFunctions_h
Definition cmnDataFormat.h:30
Definition cmnDataFunctions.h:51
static void Copy(DataType &data, const DataType &source)
static void static SerializeText(const DataType &data, std::ostream &outputStream, const char delimiter=',') CISST_THROW(std void static DeSerializeText(DataType &data, std::istream &inputStream, const char delimiter=',') CISST_THROW(std void static SerializeBinary(const DataType &data, std::ostream &outputStream) CISST_THROW(std void static DeSerializeBinary(DataType &data, std::istream &inputStream, const cmnDataFormat &localFormat, const cmnDataFormat &remoteFormat) CISST_THROW(std size_t SerializeBinaryByteSize(const DataType &data)
Definition cmnDataFunctions.h:132
static size_t DeSerializeBinary(DataType &data, const char *buffer, size_t bufferSize, const cmnDataFormat &CMN_UNUSED(localFormat), const cmnDataFormat &CMN_UNUSED(remoteFormat))
static std::string SerializeDescription(const DataType &data, const char delimiter, const std::string &userDescription="")
_elementType DataType
Definition cmnDataFunctions.h:55
@ IS_SPECIALIZED
Definition cmnDataFunctions.h:53
static std::string HumanReadable(const DataType &data)
static bool ScalarNumberIsFixed(const DataType &data)
static size_t SerializeBinary(const DataType &data, char *buffer, size_t bufferSize)
static std::string static ScalarDescription(const DataType &data, const size_t index, const std::string &userDescription="") CISST_THROW(std double static Scalar(const DataType &data, const size_t index) CISST_THROW(std size_t ScalarNumber(const DataType &data)
Definition cmnDataFunctions.h:162
std::string cmnDataHumanReadable(const _elementType &data)
Definition cmnDataFunctions.h:176
void cmnDataCopy(_elementType &destination, const _elementType &source)
Definition cmnDataFunctions.h:170
size_t CISST_EXPORT cmnDataDeSerializeBinary_size_t(size_t &data, const char *buffer, size_t bufferSize, const cmnDataFormat &localFormat, const cmnDataFormat &remoteFormat)
#define CMN_DATA_SPECIALIZE_ALL_NO_BYTE_SWAP(type, description)
Definition cmnDataFunctionsMacros.h:229
#define CMN_DATA_SPECIALIZE_ALL_BYTE_SWAP(type, description)
Definition cmnDataFunctionsMacros.h:250
Macros to export the symbols of cisstCommon (in a Dll).
#define CISST_EXPORT
Definition cmnExportMacros.h:50
#define CMN_UNUSED(argument)
Definition cmnPortability.h:497
#define CISST_THROW(exceptionParameter)
Somewhat portable compilation warning message. This works with very recent versions of gcc (4....
Definition cmnPortability.h:559
Declaration of the template function cmnThrow.
STL namespace.