From ef16fd322817db3e64ef1d88281a2f2b7c029ed3 Mon Sep 17 00:00:00 2001 From: Mario Fink Date: Wed, 22 Sep 2021 17:29:07 +0200 Subject: [PATCH] experimental support for DT_STRING datatype --- lib/tdm_datatype.hpp | 19 ++++++++++++++++--- lib/tdm_termite.cpp | 22 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/lib/tdm_datatype.hpp b/lib/tdm_datatype.hpp index e59db3d..de4d101 100644 --- a/lib/tdm_datatype.hpp +++ b/lib/tdm_datatype.hpp @@ -14,6 +14,7 @@ typedef unsigned short int eUInt16Usi; typedef unsigned int eUInt32Usi; typedef float eFloat32Usi; typedef double eFloat64Usi; +typedef char eStringUsi; class tdmdatatype { @@ -26,12 +27,13 @@ protected: eUInt32Usi uint32_; // 4 eFloat32Usi float32_; // 5 eFloat64Usi float64_; // 6 - short int dtidx_; // \in \{0,...,6\} + eStringUsi string_; // 7 + short int dtidx_; // \in \{0,...,7\} public: tdmdatatype(): sint16_(0), sint32_(0), uint8_(0), uint16_(0), uint32_(0), - float32_(0.0), float64_(0.0), + float32_(0.0), float64_(0.0), string_(0), dtidx_(0) { }; // every supported datatype gets its own constructor tdmdatatype(eInt16Usi num): sint16_(num), dtidx_(0) {}; @@ -41,6 +43,7 @@ public: tdmdatatype(eUInt32Usi num): uint32_(num), dtidx_(4) {}; tdmdatatype(eFloat32Usi num): float32_(num), dtidx_(5) {}; tdmdatatype(eFloat64Usi num): float64_(num), dtidx_(6) {}; + tdmdatatype(eStringUsi num): string_(num), dtidx_(7) {}; // identify type short int& dtype() { return dtidx_; } @@ -55,6 +58,7 @@ public: this->uint32_ = num.uint32_; this->float32_ = num.float32_; this->float64_ = num.float64_; + this->string_ = num.string_; this->dtidx_ = num.dtidx_; } @@ -70,6 +74,7 @@ public: this->uint32_ = num.uint32_; this->float32_ = num.float32_; this->float64_ = num.float64_; + this->string_ = num.string_; this->dtidx_ = num.dtidx_; } @@ -119,6 +124,12 @@ public: this->dtidx_ = 6; return *this; } + tdmdatatype& operator=(const eStringUsi &num) + { + this->string_ = num; + this->dtidx_ = 7; + return *this; + } // obtain number as double double as_double() @@ -131,6 +142,7 @@ public: else if ( dtidx_ == 4 ) num = (double)uint32_; else if ( dtidx_ == 5 ) num = (double)float32_; else if ( dtidx_ == 6 ) num = (double)float64_; + else if ( dtidx_ == 7 ) num = (double)(int)string_; return num; } @@ -144,6 +156,7 @@ public: else if ( num.dtidx_ == 4 ) out< tdm_datatypes = { {"eFloat32Usi","DT_FLOAT",3,"float_sequence",4,"32 bit float"}, {"eFloat64Usi","DT_DOUBLE",7,"double_sequence",8,"64 bit double"}, - // {"eStringUsi","DT_STRING",1,"string_sequence",0,"text"} + {"eStringUsi","DT_STRING",1,"string_sequence",1,"text"} }; diff --git a/lib/tdm_termite.cpp b/lib/tdm_termite.cpp index 4de0d3c..c7ab374 100644 --- a/lib/tdm_termite.cpp +++ b/lib/tdm_termite.cpp @@ -652,6 +652,20 @@ std::vector tdm_termite::get_channel(std::string& id) } block blk = tdx_blocks_.at(loccol.external_id_); + // find corresponding submatrix + if ( submatrices_.count(loccol.submatrix_) != 1 ) + { + throw std::runtime_error(std::string("no associated submatrix for localcolumn found: ") + loccol.id_); + } + submatrix subm = submatrices_.at(loccol.submatrix_); + if ( subm.number_of_rows_ != blk.length_ ) + { + std::stringstream ss; + ss<<"number of rows in submatrix "< datavec(blk.length_); @@ -705,6 +719,10 @@ std::vector tdm_termite::get_channel(std::string& id) { this->convert_data_to_type(tdxblk,datavec); } + else if ( blk.value_type_ == std::string("eStringUsi") ) + { + this->convert_data_to_type(tdxblk,datavec); + } else { throw std::runtime_error(std::string("unsupported/unknown datatype") + blk.value_type_); @@ -1001,6 +1019,10 @@ void tdm_termite::check_datatype_consistency() { if ( el.size_ != sizeof(eFloat64Usi) ) throw std::logic_error("invalid representation of eFloat64Usi"); } + else if ( el.name_ == "eStringUsi" ) + { + if ( el.size_ != sizeof(eStringUsi) ) throw std::logic_error("invalid representation of eStringUsi"); + } else { throw std::logic_error("missing datatype validation");