cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | List of all members
cmnData< _elementType > Class Template Reference

#include <cmnDataFunctions.h>

Public Types

enum  { IS_SPECIALIZED = 0 }
 
typedef _elementType DataType
 

Public Member Functions

template<>
void CISST_EXPORT Copy (mtsGenericObject &data, const mtsGenericObject &source)
 
template<>
void CISST_EXPORT SerializeBinary (const mtsGenericObject &data, std::ostream &outputStream) throw(std::runtime_error)
 
template<>
void CISST_EXPORT DeSerializeBinary (mtsGenericObject &data, std::istream &inputStream, const cmnDataFormat &localFormat, const cmnDataFormat &remoteFormat) throw(std::runtime_error)
 
template<>
void CISST_EXPORT SerializeText (const mtsGenericObject &data, std::ostream &outputStream, const char delimiter) throw(std::runtime_error)
 
template<>
std::string CISST_EXPORT SerializeDescription (const mtsGenericObject &data, const char delimiter, const std::string &userDescription)
 
template<>
void CISST_EXPORT DeSerializeText (mtsGenericObject &data, std::istream &inputStream, const char delimiter) throw(std::runtime_error)
 
template<>
std::string CISST_EXPORT HumanReadable (const mtsGenericObject &data)
 
template<>
bool CISST_EXPORT ScalarNumberIsFixed (const mtsGenericObject &data)
 
template<>
size_t CISST_EXPORT ScalarNumber (const mtsGenericObject &data)
 
template<>
double CISST_EXPORT Scalar (const mtsGenericObject &data, const size_t index) throw(std::out_of_range)
 
template<>
std::string CISST_EXPORT ScalarDescription (const mtsGenericObject &data, const size_t index, const std::string &userDescription) throw(std::out_of_range)
 

Static Public Member Functions

static std::string HumanReadable (const DataType &data)
 
static void Copy (DataType &data, const DataType &source)
 
static std::string SerializeDescription (const DataType &data, const char delimiter, const std::string &userDescription="")
 
static void SerializeText (const DataType &data, std::ostream &outputStream, const char delimiter= ',') throw (std::runtime_error)
 
static void DeSerializeText (DataType &data, std::istream &inputStream, const char delimiter= ',') throw (std::runtime_error)
 
static void SerializeBinary (const DataType &data, std::ostream &outputStream) throw (std::runtime_error)
 
static void DeSerializeBinary (DataType &data, std::istream &inputStream, const cmnDataFormat &localFormat, const cmnDataFormat &remoteFormat) throw (std::runtime_error)
 
static size_t SerializeBinaryByteSize (const DataType &data)
 
static size_t SerializeBinary (const DataType &data, char *buffer, size_t bufferSize)
 
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 ScalarDescription (const DataType &data, const size_t index, const std::string &userDescription="") throw (std::out_of_range)
 
static double Scalar (const DataType &data, const size_t index) throw (std::out_of_range)
 
static size_t ScalarNumber (const DataType &data)
 
static bool ScalarNumberIsFixed (const DataType &data)
 

Detailed Description

template<typename _elementType>
class cmnData< _elementType >

cmnDataFunction. Data functions used to handle objects across the cisst libraries. All data function names use the prefix cmnData and the first parameter is the object currently manipulated.

The main principle is to rely on the compiler to find the proper class overload for each object type. void cmnData<int>::HumanReadable(const int & data); void cmnData<std::string>::HumanReadable(const std::string & data); ... This approach allows to manipulate external data types by overloading the required cmnData class.

Error handling is based on standard exceptions using std::runtime_error.

Member Typedef Documentation

template<typename _elementType>
typedef _elementType cmnData< _elementType >::DataType

Member Enumeration Documentation

template<typename _elementType>
anonymous enum
Enumerator
IS_SPECIALIZED 

Member Function Documentation

template<typename _elementType>
static void cmnData< _elementType >::Copy ( DataType data,
const DataType source 
)
static

Copy the source to the data object. This allows to define mechanisms that might be more efficient than copy constructors and avoid the ambiguities of the assignment operator. For example, to copy a dynamic vector of simple object, it can be more efficient to use a memcpy than to iterate over each element and assign one by one.

template<>
void CISST_EXPORT cmnData< mtsGenericObject >::Copy ( mtsGenericObject data,
const mtsGenericObject source 
)
template<typename _elementType>
static void cmnData< _elementType >::DeSerializeBinary ( DataType data,
std::istream &  inputStream,
const cmnDataFormat localFormat,
const cmnDataFormat remoteFormat 
)
throw (std::runtime_error
)
static
template<>
void CISST_EXPORT cmnData< mtsGenericObject >::DeSerializeBinary ( mtsGenericObject data,
std::istream &  inputStream,
const cmnDataFormat localFormat,
const cmnDataFormat remoteFormat 
)
throw(std::runtime_error
)
template<typename _elementType>
static size_t cmnData< _elementType >::DeSerializeBinary ( DataType data,
const char *  buffer,
size_t  bufferSize,
const cmnDataFormat CMN_UNUSEDlocalFormat,
const cmnDataFormat CMN_UNUSEDremoteFormat 
)
static
template<typename _elementType>
static void cmnData< _elementType >::DeSerializeText ( DataType data,
std::istream &  inputStream,
const char  delimiter = ',' 
)
throw (std::runtime_error
)
static

Set the value of the data object by deserializing each element from the input stream. The function will look for the user provided delimiter between the elements to deserialize. Using the previous example, the overloaded function for a dynamic vector will look for the size (4), attempt to resize the data vector to fit 4 elements, skip one delimiter (comma) and then attempt to deserialize 4 comma separated values from the input stream.

template<>
void CISST_EXPORT cmnData< mtsGenericObject >::DeSerializeText ( mtsGenericObject data,
std::istream &  inputStream,
const char  delimiter 
)
throw(std::runtime_error
)
template<typename _elementType>
static std::string cmnData< _elementType >::HumanReadable ( const DataType data)
static

Returns a human readable string describing a specific instance of an object.

template<>
std::string CISST_EXPORT cmnData< mtsGenericObject >::HumanReadable ( const mtsGenericObject data)
template<typename _elementType>
static double cmnData< _elementType >::Scalar ( const DataType data,
const size_t  index 
)
throw (std::out_of_range
)
static
template<>
double CISST_EXPORT cmnData< mtsGenericObject >::Scalar ( const mtsGenericObject data,
const size_t  index 
)
throw(std::out_of_range
)
template<typename _elementType>
static std::string cmnData< _elementType >::ScalarDescription ( const DataType data,
const size_t  index,
const std::string &  userDescription = "" 
)
throw (std::out_of_range
)
static
template<>
std::string CISST_EXPORT cmnData< mtsGenericObject >::ScalarDescription ( const mtsGenericObject data,
const size_t  index,
const std::string &  userDescription 
)
throw(std::out_of_range
)
template<>
size_t CISST_EXPORT cmnData< mtsGenericObject >::ScalarNumber ( const mtsGenericObject data)
template<typename _elementType>
static size_t cmnData< _elementType >::ScalarNumber ( const DataType data)
static
template<>
bool CISST_EXPORT cmnData< mtsGenericObject >::ScalarNumberIsFixed ( const mtsGenericObject data)
template<typename _elementType>
static bool cmnData< _elementType >::ScalarNumberIsFixed ( const DataType data)
static
template<typename _elementType>
static void cmnData< _elementType >::SerializeBinary ( const DataType data,
std::ostream &  outputStream 
)
throw (std::runtime_error
)
static

Serializes each element of the data object in binary format.

template<typename _elementType>
static size_t cmnData< _elementType >::SerializeBinary ( const DataType data,
char *  buffer,
size_t  bufferSize 
)
static

Attempt to serialize the data object using the user provided buffer. The buffer size must be provided by the caller. The function first checks that the buffer is large enough and returns 0 otherwise. The function then serializes (binary format) the data object, modify the parameter bufferSize to reflect how much is left and return the number of bytes used.

template<>
void CISST_EXPORT cmnData< mtsGenericObject >::SerializeBinary ( const mtsGenericObject data,
std::ostream &  outputStream 
)
throw(std::runtime_error
)
template<typename _elementType>
static size_t cmnData< _elementType >::SerializeBinaryByteSize ( const DataType data)
static

Returns the numbers of bytes required to stored the content of the data object. This function can be used to allocate a char buffer used to perform the serialization.

template<typename _elementType>
static std::string cmnData< _elementType >::SerializeDescription ( const DataType data,
const char  delimiter,
const std::string &  userDescription = "" 
)
static

Provides a human readble string describing each element of the data object. This description is for all instances of the same "size". For example, if the data object is a dynamic vector of intergers of size 4, the delimiter is a comma and the user description is "V", the returned string would look like "V.size,v[0],v[1],v[2],v[3]".

template<>
std::string CISST_EXPORT cmnData< mtsGenericObject >::SerializeDescription ( const mtsGenericObject data,
const char  delimiter,
const std::string &  userDescription 
)
template<typename _elementType>
static void cmnData< _elementType >::SerializeText ( const DataType data,
std::ostream &  outputStream,
const char  delimiter = ',' 
)
throw (std::runtime_error
)
static

Serializes each element of the data object in text format, separated by the user provided delimiter. Using the previous example, this method would stream the size followed by the 4 value: "4,11,22,33,44". I/O stream errors can lead to exceptions.

template<>
void CISST_EXPORT cmnData< mtsGenericObject >::SerializeText ( const mtsGenericObject data,
std::ostream &  outputStream,
const char  delimiter 
)
throw(std::runtime_error
)

The documentation for this class was generated from the following file: