get_channel as non-template function

This commit is contained in:
Mario Fink 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(eFloat32Usi num): float32_(num), dtidx_(5) {};
tdmdatatype(eFloat64Usi num): float64_(num), dtidx_(6) {}; tdmdatatype(eFloat64Usi num): float64_(num), dtidx_(6) {};
// identify type
short int& dtype() { return dtidx_; }
// overall assignment operator // overall assignment operator
tdmdatatype& operator=(const tdmdatatype &num) tdmdatatype& operator=(const tdmdatatype &num)
{ {
@ -90,14 +93,12 @@ public:
} }
tdmdatatype& operator=(const eFloat32Usi &num) tdmdatatype& operator=(const eFloat32Usi &num)
{ {
std::cout<<"tdmdatatype operator= for eFloat32Usi\n";
this->float32_ = num; this->float32_ = num;
this->dtidx_ = 5; this->dtidx_ = 5;
return *this; return *this;
} }
tdmdatatype& operator=(const eFloat64Usi &num) tdmdatatype& operator=(const eFloat64Usi &num)
{ {
std::cout<<"tdmdatatype operator= for eFloat64Usi\n";
this->float64_ = num; this->float64_ = num;
this->dtidx_ = 6; this->dtidx_ = 6;
return *this; return *this;
@ -105,17 +106,17 @@ public:
// define custom stream operator to print the correct type // define custom stream operator to print the correct type
friend std::ostream& operator<<(std::ostream& out, const tdmdatatype& num) friend std::ostream& operator<<(std::ostream& out, const tdmdatatype& num)
{ {
std::cout<<"operator<< dtidx_:"<<num.dtidx_<<"\n"; if ( num.dtidx_ == 0 ) out<<num.sint16_;
if ( num.dtidx_ == 0 ) out<<num.sint16_; else if ( num.dtidx_ == 1 ) out<<num.sint32_;
else if ( num.dtidx_ == 1 ) out<<num.sint32_; else if ( num.dtidx_ == 2 ) out<<num.uint8_;
else if ( num.dtidx_ == 2 ) out<<num.uint8_; else if ( num.dtidx_ == 3 ) out<<num.uint16_;
else if ( num.dtidx_ == 3 ) out<<num.uint16_; else if ( num.dtidx_ == 4 ) out<<num.uint32_;
else if ( num.dtidx_ == 4 ) out<<num.uint32_; else if ( num.dtidx_ == 5 ) out<<num.float32_;
else if ( num.dtidx_ == 5 ) out<<num.float32_; else if ( num.dtidx_ == 6 ) out<<num.float64_;
else if ( num.dtidx_ == 6 ) out<<num.float64_; return out;
return out; }
}
}; };
// // base class for all tdm datatypes // // 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 // extract channel by id
template<typename tdmtype> // template<typename tdmtype>
std::vector<tdmtype> tdm_reaper::get_channel(std::string& id) std::vector<tdmdatatype> tdm_reaper::get_channel(std::string& id)
{ {
// check for existence of required channel id (=key) // check for existence of required channel id (=key)
if ( tdmchannels_.count(id) == 1 ) if ( tdmchannels_.count(id) == 1 )
@ -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); 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) // std::vector<double> tdm_reaper::get_channel(std::string &id)
// { // {

View File

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

View File

@ -201,15 +201,14 @@ int main(int argc, char* argv[])
std::cout<<jack.get_localcolumn_overview(formatter)<<"\n"; std::cout<<jack.get_localcolumn_overview(formatter)<<"\n";
std::cout<<jack.get_block_overview(formatter)<<"\n"; std::cout<<jack.get_block_overview(formatter)<<"\n";
tdmdatatype A; std::string chid("usi14");
A = (eUInt8Usi)0.354; std::vector<tdmdatatype> chdata = jack.get_channel(chid);
std::cout<<A<<"\n";
// std::string chid("usi14"); std::cout<<"channel size: "<<chdata.size()<<"\n";
// std::vector<tdmdatatype> chdata = jack.get_channel<tdmdatatype>(chid); for ( tdmdatatype el: chdata )
// {
// std::cout<<"channel size: "<<chdata.size()<<"\n"; std::cout<<el<<":"<<el.dtype()<<"\n";
// for ( tdmdatatype el: chdata ) std::cout<<el<<"\n"; }
// std::vector<std::string> chgrids = jack.get_channelgroup_ids(); // std::vector<std::string> chgrids = jack.get_channelgroup_ids();
// for ( auto el: chgrids ) std::cout<<el<<","; // for ( auto el: chgrids ) std::cout<<el<<",";