experimental support for DT_STRING datatype
This commit is contained in:
parent
337fbf9745
commit
ef16fd3228
@ -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<<num.uint32_;
|
||||
else if ( num.dtidx_ == 5 ) out<<num.float32_;
|
||||
else if ( num.dtidx_ == 6 ) out<<num.float64_;
|
||||
else if ( num.dtidx_ == 7 ) out<<num.string_;
|
||||
return out;
|
||||
}
|
||||
|
||||
@ -332,7 +345,7 @@ const std::vector<tdm_datatype> 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"}
|
||||
|
||||
};
|
||||
|
||||
|
@ -652,6 +652,20 @@ std::vector<tdmdatatype> 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 "<<subm.id_<<" ("<<subm.number_of_rows_<<") "
|
||||
<<" does not agree with length of associated block "<<blk.id_<<" ("<<blk.length_<<")";
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
|
||||
// declare vector of appropriate length
|
||||
std::vector<tdmdatatype> datavec(blk.length_);
|
||||
|
||||
@ -705,6 +719,10 @@ std::vector<tdmdatatype> tdm_termite::get_channel(std::string& id)
|
||||
{
|
||||
this->convert_data_to_type<eFloat64Usi>(tdxblk,datavec);
|
||||
}
|
||||
else if ( blk.value_type_ == std::string("eStringUsi") )
|
||||
{
|
||||
this->convert_data_to_type<eStringUsi>(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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user