21#ifndef _cmnDataFunctionsVectorHelpers_h
22#define _cmnDataFunctionsVectorHelpers_h
24template <
class _vectorType>
26 const _vectorType & source)
29 data.resize(source.size());
30 typedef _vectorType VectorType;
31 typedef typename VectorType::iterator
iterator;
37 iterSource != endSource;
38 ++iterSource, ++iterData) {
43template <
class _vectorType>
46 std::stringstream stringStream;
48 typedef _vectorType VectorType;
56 stringStream << cmnData<typename _vectorType::value_type>::HumanReadable(*iter);
59 return stringStream.str();
62template <
class _vectorType>
64 std::ostream & outputStream,
73 outputStream << delimiter;
79template <
class _vectorType>
81 std::istream & inputStream,
85 typedef typename _vectorType::iterator
iterator;
90 cmnDataDeSerializeTextDelimiter(inputStream, delimiter,
"std::vector");
96template <
class _vectorType>
98 std::istream & inputStream,
107 cmnDataDeSerializeTextDelimiter(inputStream, delimiter,
"vctFixedSizeVectorBase");
112template <
class _vectorType>
114 std::istream & inputStream,
115 const char delimiter)
121 if (data.size() !=
size) {
122 cmnThrow(
"cmnDataDeSerializeText: vector size doesn't match");
126 cmnDataDeSerializeTextDelimiter(inputStream, delimiter,
"vctFixedSizeVectorBase");
131template <
class _vectorType>
133 const char delimiter,
134 const std::string & userDescription,
135 const bool serializeSize)
137 std::string prefix = (userDescription ==
"") ?
"v[" : (userDescription +
"[");
138 std::stringstream indexSuffix;
139 std::stringstream description;
140 const size_t size = data.size();
142 description << cmnData<size_t>::SerializeDescription(
size, delimiter, (userDescription ==
"") ?
"v.size" : (userDescription +
".size"));
145 for (index = 0; index <
size; ++index) {
146 if (index != 0 || serializeSize) {
147 description << delimiter;
150 indexSuffix.str(std::string());
151 indexSuffix << index <<
"]";
152 description << cmnData<typename _vectorType::value_type>::SerializeDescription(data[index], delimiter, prefix + indexSuffix.str());
154 return description.str();
157template <
class _vectorType>
159 std::ostream & outputStream)
165 for (; iter !=
end; ++iter) {
170template <
class _vectorType>
172 std::istream & inputStream,
178 typedef typename _vectorType::iterator
iterator;
181 for (; iter !=
end; ++iter) {
186template <
class _vectorType>
188 std::istream & inputStream,
200template <
class _vectorType>
202 std::istream & inputStream,
210 if (data.size() !=
size) {
211 cmnThrow(
"cmnDataDeSerializeBinary: vector size doesn't match");
217template <
class _vectorType>
220 if (data.size() == 0) {
223 typedef typename _vectorType::value_type
value_type;
231 for (; iter !=
end; ++iter) {
237template <
class _vectorType,
class _elementType>
240 size_t & elementIndex,
size_t & inElementIndex)
244 if (scalarNumberPerElement == 0) {
247 if (index < scalarNumber) {
248 elementIndex = index / scalarNumberPerElement;
249 inElementIndex = index % scalarNumberPerElement;
254 bool indexFound =
false;
255 size_t scalarCounter = 0;
256 size_t lastScalarInElement = 0;
257 size_t firstScalarInElement = 0;
258 size_t numberOfScalarsInElement = 0;
262 firstScalarInElement = scalarCounter;
263 lastScalarInElement = scalarCounter + numberOfScalarsInElement - 1;
264 scalarCounter = lastScalarInElement + 1;
266 indexFound = ((index >= firstScalarInElement) && (index <= lastScalarInElement));
267 }
while ((!indexFound)
268 && (elementIndex <
size));
271 inElementIndex = index - firstScalarInElement;
277template <
class _vectorType>
280 const std::string & userDescription)
283 size_t elementIndex, inElementIndex;
284 std::stringstream suffix;
287 index, elementIndex, inElementIndex)) {
288 suffix <<
"[" << index <<
"]";
291 cmnThrow(std::out_of_range(
"cmnDataScalarDescription: vector index out of range"));
295template <
class _vectorType>
299 size_t elementIndex, inElementIndex;
302 index, elementIndex, inElementIndex)) {
305 cmnThrow(std::out_of_range(
"cmnDataScalar: vector index out of range"));
Definition cmnDataFunctions.h:51
static void Copy(DataType &data, const DataType &source)
static size_t DeSerializeBinary(DataType &data, const char *buffer, size_t bufferSize, const cmnDataFormat &CMN_UNUSED(localFormat), const cmnDataFormat &CMN_UNUSED(remoteFormat))
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
size_t CISST_EXPORT cmnDataDeSerializeBinary_size_t(size_t &data, const char *buffer, size_t bufferSize, const cmnDataFormat &localFormat, const cmnDataFormat &remoteFormat)
void cmnDataVectorCopy(_vectorType &data, const _vectorType &source)
Definition cmnDataFunctionsVectorHelpers.h:25
void cmnDataVectorSerializeText(const _vectorType &data, std::ostream &outputStream, const char delimiter) CISST_THROW(std
Definition cmnDataFunctionsVectorHelpers.h:63
void cmnDataVectorDeSerializeBinary(_vectorType &data, std::istream &inputStream, const cmnDataFormat &localFormat, const cmnDataFormat &remoteFormat) CISST_THROW(std
Definition cmnDataFunctionsVectorHelpers.h:171
void cmnDataVectorSerializeBinary(const _vectorType &data, std::ostream &outputStream) CISST_THROW(std
Definition cmnDataFunctionsVectorHelpers.h:158
std::string cmnDataVectorSerializeDescription(const _vectorType &data, const char delimiter, const std::string &userDescription, const bool serializeSize)
Definition cmnDataFunctionsVectorHelpers.h:132
size_t cmnDataVectorScalarNumber(const _vectorType &data)
Definition cmnDataFunctionsVectorHelpers.h:218
void cmnDataVectorDeSerializeBinaryCheckSize(_vectorType &data, std::istream &inputStream, const cmnDataFormat &localFormat, const cmnDataFormat &remoteFormat) CISST_THROW(std
Definition cmnDataFunctionsVectorHelpers.h:201
void cmnDataVectorDeSerializeBinaryResize(_vectorType &data, std::istream &inputStream, const cmnDataFormat &localFormat, const cmnDataFormat &remoteFormat) CISST_THROW(std
Definition cmnDataFunctionsVectorHelpers.h:187
void cmnDataVectorDeSerializeTextCheckSize(_vectorType &data, std::istream &inputStream, const char delimiter) CISST_THROW(std
Definition cmnDataFunctionsVectorHelpers.h:113
bool cmnDataVectorScalarFindInVectorIndex(_vectorType data, const size_t size, const size_t scalarNumber, const size_t index, size_t &elementIndex, size_t &inElementIndex)
Definition cmnDataFunctionsVectorHelpers.h:238
void cmnDataVectorDeSerializeTextResize(_vectorType &data, std::istream &inputStream, const char delimiter) CISST_THROW(std
Definition cmnDataFunctionsVectorHelpers.h:97
std::string cmnDataVectorScalarDescription(const _vectorType &data, const size_t index, const std::string &userDescription) CISST_THROW(std
Definition cmnDataFunctionsVectorHelpers.h:278
void cmnDataVectorDeSerializeText(_vectorType &data, std::istream &inputStream, const char delimiter)
Definition cmnDataFunctionsVectorHelpers.h:80
double cmnDataVectorScalar(const _vectorType &data, const size_t index) CISST_THROW(std
Definition cmnDataFunctionsVectorHelpers.h:296
std::string cmnDataVectorHumanReadable(const _vectorType &data)
Definition cmnDataFunctionsVectorHelpers.h:44
#define CISST_THROW(exceptionParameter)
Somewhat portable compilation warning message. This works with very recent versions of gcc (4....
Definition cmnPortability.h:559
void cmnThrow(const _exceptionType &except, cmnLogLevel lod=CMN_LOG_LEVEL_INIT_ERROR)
Definition cmnThrow.h:76
const_iterator end(void) const
Definition vctDynamicConstMatrixBase.h:209
OwnerType::const_iterator const_iterator
Definition vctDynamicConstMatrixBase.h:95
OwnerType::iterator iterator
Definition vctDynamicConstMatrixBase.h:92
size_type size(void) const
Definition vctDynamicConstMatrixBase.h:228
const_iterator begin(void) const
Definition vctDynamicConstMatrixBase.h:203