get_channel as non-template function

This commit is contained in:
2021-01-22 13:53:24 +01:00
parent 93f0077146
commit d0fe710512
4 changed files with 32 additions and 28 deletions

View File

@@ -40,6 +40,9 @@ public:
tdmdatatype(eFloat32Usi num): float32_(num), dtidx_(5) {};
tdmdatatype(eFloat64Usi num): float64_(num), dtidx_(6) {};
// identify type
short int& dtype() { return dtidx_; }
// overall assignment operator
tdmdatatype& operator=(const tdmdatatype &num)
{
@@ -90,14 +93,12 @@ public:
}
tdmdatatype& operator=(const eFloat32Usi &num)
{
std::cout<<"tdmdatatype operator= for eFloat32Usi\n";
this->float32_ = num;
this->dtidx_ = 5;
return *this;
}
tdmdatatype& operator=(const eFloat64Usi &num)
{
std::cout<<"tdmdatatype operator= for eFloat64Usi\n";
this->float64_ = num;
this->dtidx_ = 6;
return *this;
@@ -105,17 +106,17 @@ public:
// define custom stream operator to print the correct type
friend std::ostream& operator<<(std::ostream& out, const tdmdatatype& num)
{
std::cout<<"operator<< dtidx_:"<<num.dtidx_<<"\n";
if ( num.dtidx_ == 0 ) out<<num.sint16_;
else if ( num.dtidx_ == 1 ) out<<num.sint32_;
else if ( num.dtidx_ == 2 ) out<<num.uint8_;
else if ( num.dtidx_ == 3 ) out<<num.uint16_;
else if ( num.dtidx_ == 4 ) out<<num.uint32_;
else if ( num.dtidx_ == 5 ) out<<num.float32_;
else if ( num.dtidx_ == 6 ) out<<num.float64_;
return out;
}
{
if ( num.dtidx_ == 0 ) out<<num.sint16_;
else if ( num.dtidx_ == 1 ) out<<num.sint32_;
else if ( num.dtidx_ == 2 ) out<<num.uint8_;
else if ( num.dtidx_ == 3 ) out<<num.uint16_;
else if ( num.dtidx_ == 4 ) out<<num.uint32_;
else if ( num.dtidx_ == 5 ) out<<num.float32_;
else if ( num.dtidx_ == 6 ) out<<num.float64_;
return out;
}
};
// // base class for all tdm datatypes

View File

@@ -568,8 +568,8 @@ std::string tdm_reaper::get_block_overview(format formatter)
// -------------------------------------------------------------------------- //
// extract channel by id
template<typename tdmtype>
std::vector<tdmtype> tdm_reaper::get_channel(std::string& id)
// template<typename tdmtype>
std::vector<tdmdatatype> tdm_reaper::get_channel(std::string& id)
{
// check for existence of required channel id (=key)
if ( tdmchannels_.count(id) == 1 )
@@ -592,7 +592,7 @@ std::vector<tdmtype> tdm_reaper::get_channel(std::string& id)
// use "values" id to map to external block
block blk = tdx_blocks_.at(loccol.external_id_);
// // distinguish numeric datatypes
// switch ( blk.value_type_ )
// {
@@ -634,10 +634,14 @@ std::vector<tdmtype> tdm_reaper::get_channel(std::string& id)
throw std::invalid_argument(std::string("channel id does not exist: ") + id);
}
return std::vector<tdmtype>();
std::vector<tdmdatatype> data;
eFloat32Usi m(4);
data.push_back(m);
// std::vector<tdmdatatype>();
return data;
}
template std::vector<tdmdatatype> tdm_reaper::get_channel<tdmdatatype>(std::string& id);
// template std::vector<tdmdatatype> tdm_reaper::get_channel<tdmdatatype>(std::string& id);
// std::vector<double> tdm_reaper::get_channel(std::string &id)
// {

View File

@@ -180,8 +180,8 @@ public:
}
// extract channel by id
template<typename tdmtype>
std::vector<tdmtype> get_channel(std::string& id);
// template<typename tdmtype>
std::vector<tdmdatatype> get_channel(std::string& id);
// (TODO introduce template T to reference specific datatype instead of double in general)
// std::vector<double> get_channel(std::string &id);