cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
6  Author(s): Anton Deguet
7  Created on: 2011-06-27
8 
9  (C) Copyright 2011-2013 Johns Hopkins University (JHU), All Rights
10  Reserved.
11 
12 --- begin cisst license - do not edit ---
13 
14 This software is provided "as is" under an open source license, with
15 no warranty. The complete license can be found in license.txt and
16 http://www.cisst.org/cisst/license.txt.
17 
18 --- end cisst license ---
19 
20 */
21 
22 #pragma once
23 #ifndef _cmnDataFunctions_h
24 #define _cmnDataFunctions_h
25 
26 #include <string.h> // for memcpy
27 #include <iostream>
28 #include <sstream>
29 #include <cisstCommon/cmnThrow.h>
32 
33 // always include last
34 #include <cisstCommon/cmnExport.h>
35 
52 template <typename _elementType>
53 class cmnData
54 {
55 public:
56  enum {IS_SPECIALIZED = 0};
57 
58  typedef _elementType DataType;
59 
62  static
63  std::string
64  HumanReadable(const DataType & data);
65 
73  static
74  void
75  Copy(DataType & data, const DataType & source);
76 
84  static
85  std::string
86  SerializeDescription(const DataType & data, const char delimiter,
87  const std::string & userDescription = "");
88 
95  static
96  void
97  SerializeText(const DataType & data, std::ostream & outputStream,
98  const char delimiter = ',') throw (std::runtime_error);
99 
109  static
110  void
111  DeSerializeText(DataType & data, std::istream & inputStream,
112  const char delimiter = ',') throw (std::runtime_error);
113 
116  static
117  void
118  SerializeBinary(const DataType & data, std::ostream & outputStream)
119  throw (std::runtime_error);
120 
123  static
124  void
125  DeSerializeBinary(DataType & data, std::istream & inputStream,
126  const cmnDataFormat & localFormat,
127  const cmnDataFormat & remoteFormat) throw (std::runtime_error);
128 
133  static
134  size_t
135  SerializeBinaryByteSize(const DataType & data);
136 
144  static
145  size_t
146  SerializeBinary(const DataType & data, char * buffer, size_t bufferSize);
147 
148  static
149  size_t
150  DeSerializeBinary(DataType & data, const char * buffer, size_t bufferSize,
151  const cmnDataFormat & CMN_UNUSED(localFormat),
152  const cmnDataFormat & CMN_UNUSED(remoteFormat));
153 
154  static
155  std::string
156  ScalarDescription(const DataType & data, const size_t index, const std::string & userDescription = "")
157  throw (std::out_of_range);
158 
159  static
160  double
161  Scalar(const DataType & data, const size_t index)
162  throw (std::out_of_range);
163 
164  static
165  size_t ScalarNumber(const DataType & data);
166 
167  static
168  bool ScalarNumberIsFixed(const DataType & data);
169 };
170 
171 /* Native types to overload:
172  bool
173  char
174  unsigned char
175  short
176  unsigned short
177  int
178  unsigned int
179  long long int
180  unsigned long long int
181  float
182  double
183 */
186 CMN_DATA_SPECIALIZE_ALL_NO_BYTE_SWAP(unsigned char, uc);
187 
189 CMN_DATA_SPECIALIZE_ALL_BYTE_SWAP(unsigned short, us);
191 CMN_DATA_SPECIALIZE_ALL_BYTE_SWAP(unsigned int, ui);
193 CMN_DATA_SPECIALIZE_ALL_BYTE_SWAP(unsigned long int, uli);
194 CMN_DATA_SPECIALIZE_ALL_BYTE_SWAP(long long int, lli);
195 CMN_DATA_SPECIALIZE_ALL_BYTE_SWAP(unsigned long long int, ulli);
198 
202 size_t CISST_EXPORT cmnDataDeSerializeBinary_size_t(size_t & data, const char * buffer, size_t bufferSize,
203  const cmnDataFormat & localFormat,
204  const cmnDataFormat & remoteFormat);
205 
207  std::istream & inputStream,
208  const cmnDataFormat & localFormat,
209  const cmnDataFormat & remoteFormat) throw (std::runtime_error);
211 
213 void CISST_EXPORT cmnDataDeSerializeTextDelimiter(std::istream & inputStream, const char delimiter, const char * className)
214  throw (std::runtime_error);
215 
216 #endif // _cmnDataFunctions_h
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
Definition: cmnDataFormat.h:32
#define CMN_UNUSED(argument)
Definition: cmnPortability.h:479
CMN_DATA_SPECIALIZE_ALL_BYTE_SWAP(short, s)
size_t CISST_EXPORT cmnDataDeSerializeBinary_size_t(size_t &data, const char *buffer, size_t bufferSize, const cmnDataFormat &localFormat, const cmnDataFormat &remoteFormat)
static void SerializeBinary(const DataType &data, std::ostream &outputStream)
_elementType DataType
Definition: cmnDataFunctions.h:58
static void SerializeText(const DataType &data, std::ostream &outputStream, const char delimiter= ',')
Macros to export the symbols of cisstCommon (in a Dll).
CMN_DATA_SPECIALIZE_ALL_NO_BYTE_SWAP(bool, b)
static bool ScalarNumberIsFixed(const DataType &data)
static size_t ScalarNumber(const DataType &data)
static double Scalar(const DataType &data, const size_t index)
Definition: cmnDataFunctions.h:53
static std::string ScalarDescription(const DataType &data, const size_t index, const std::string &userDescription="")
static size_t SerializeBinaryByteSize(const DataType &data)
Definition: cmnDataFunctions.h:56
static std::string HumanReadable(const DataType &data)
static void DeSerializeText(DataType &data, std::istream &inputStream, const char delimiter= ',')
static std::string SerializeDescription(const DataType &data, const char delimiter, const std::string &userDescription="")
static void DeSerializeBinary(DataType &data, std::istream &inputStream, const cmnDataFormat &localFormat, const cmnDataFormat &remoteFormat)
Declaration of the template function cmnThrow.
static void Copy(DataType &data, const DataType &source)
void CISST_EXPORT cmnDataDeSerializeTextDelimiter(std::istream &inputStream, const char delimiter, const char *className)