File size: 5,847 Bytes
68ce2fc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
/*
Author(s): Anton Deguet
Created on: 2012-07-09
(C) Copyright 2012-2018 Johns Hopkins University (JHU), All Rights Reserved.
--- begin cisst license - do not edit ---
This software is provided "as is" under an open source license, with
no warranty. The complete license can be found in license.txt and
http://www.cisst.org/cisst/license.txt.
--- end cisst license ---
*/
#pragma once
#ifndef _vctDataFunctionsFixedSizeMatrix_h
#define _vctDataFunctionsFixedSizeMatrix_h
#include <cisstCommon/cmnDataFunctions.h>
#include <cisstVector/vctFixedSizeMatrixBase.h>
#include <cisstCommon/cmnDataFunctionsMatrixHelpers.h>
#if CISST_HAS_JSON
#include <cisstVector/vctDataFunctionsFixedSizeMatrixJSON.h>
#endif // CISST_HAS_JSON
template <class _elementType, vct::size_type _rows, vct::size_type _cols, bool _rowMajor>
class cmnData<vctFixedSizeMatrix<_elementType, _rows, _cols, _rowMajor> >
{
public:
enum {IS_SPECIALIZED = 1};
typedef vctFixedSizeMatrix<_elementType, _rows, _cols, _rowMajor> DataType;
static void Copy(DataType & data, const DataType & source)
{
data.Assign(source);
}
static std::string HumanReadable(const DataType & data)
{
return cmnDataMatrixHumanReadable(data);
}
static void SerializeBinary(const DataType & data, std::ostream & outputStream)
CISST_THROW(std::runtime_error)
{
cmnDataMatrixSerializeBinary(data, outputStream);
}
static void DeSerializeBinary(DataType & data,
std::istream & inputStream,
const cmnDataFormat & localFormat,
const cmnDataFormat & remoteFormat)
CISST_THROW(std::runtime_error)
{
cmnDataMatrixDeSerializeBinary(data, inputStream, localFormat, remoteFormat);
}
static void SerializeText(const DataType & data,
std::ostream & outputStream,
const char delimiter = ',')
CISST_THROW(std::runtime_error)
{
cmnDataMatrixSerializeText(data, outputStream, delimiter);
}
static std::string SerializeDescription(const DataType & data,
const char delimiter = ',',
const std::string & userDescription = "m")
{
return cmnDataMatrixSerializeDescription(data, delimiter, userDescription, false /* no need to serialize size */);
}
static void DeSerializeText(DataType & data,
std::istream & inputStream,
const char delimiter = ',')
CISST_THROW(std::runtime_error)
{
cmnDataMatrixDeSerializeText(data, inputStream, delimiter);
}
static bool ScalarNumberIsFixed(const DataType & data)
{
return ((data.size() == 0) || cmnData<_elementType>::ScalarNumberIsFixed(data.Element(0, 0)));
}
static size_t ScalarNumber(const DataType & data)
{
return cmnDataMatrixScalarNumber(data, false /* do not treat size as a scalar*/);
}
static std::string ScalarDescription(const DataType & data,
const size_t & index,
const std::string & userDescription = "m")
CISST_THROW(std::out_of_range)
{
return cmnDataMatrixScalarDescription(data, index, userDescription, false /* do not treat size as a scalar */);
}
static double Scalar(const DataType & data, const size_t & index)
CISST_THROW(std::out_of_range)
{
return cmnDataMatrixScalar(data, index, false /* do not treat size as a scalar */);
}
};
// ---------------------- older functions, to be deprecated
template <typename _elementType, vct::size_type _rows, vct::size_type _cols>
inline void cmnDeSerializeRaw(std::istream & inputStream,
vctFixedSizeMatrix<_elementType, _rows, _cols> & matrix)
CISST_THROW(std::runtime_error)
{
matrix.DeSerializeRaw(inputStream);
}
template <typename _elementType, vct::size_type _rows, vct::size_type _cols,
vct::stride_type _rowStride, vct::stride_type _colStride>
inline void cmnDeSerializeRaw(std::istream & inputStream,
vctFixedSizeMatrixRef<_elementType, _rows, _cols, _rowStride, _colStride> & matrix)
CISST_THROW(std::runtime_error)
{
matrix.DeSerializeRaw(inputStream);
}
template <typename _elementType, vct::size_type _rows, vct::size_type _cols>
inline void cmnSerializeRaw(std::ostream & outputStream,
const vctFixedSizeMatrix<_elementType, _rows, _cols> & matrix)
CISST_THROW(std::runtime_error)
{
matrix.SerializeRaw(outputStream);
}
template <typename _elementType, vct::size_type _rows, vct::size_type _cols,
vct::stride_type _rowStride, vct::stride_type _colStride>
inline void cmnSerializeRaw(std::ostream & outputStream,
const vctFixedSizeMatrixRef<_elementType, _rows, _cols, _rowStride, _colStride> & matrix)
CISST_THROW(std::runtime_error)
{
matrix.SerializeRaw(outputStream);
}
template <typename _elementType, vct::size_type _rows, vct::size_type _cols,
vct::stride_type _rowStride, vct::stride_type _colStride>
inline void cmnSerializeRaw(std::ostream & outputStream,
const vctFixedSizeConstMatrixRef<_elementType, _rows, _cols, _rowStride, _colStride> & matrix)
CISST_THROW(std::runtime_error)
{
matrix.SerializeRaw(outputStream);
}
// ----------------------- end of older functions
#endif // _vctDataFunctionsFixedSizeMatrix_h
|