get_channel as non-template function
This commit is contained in:
parent
93f0077146
commit
d0fe710512
@ -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
|
||||
|
@ -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)
|
||||
// {
|
||||
|
@ -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);
|
||||
|
15
src/main.cpp
15
src/main.cpp
@ -201,15 +201,14 @@ int main(int argc, char* argv[])
|
||||
std::cout<<jack.get_localcolumn_overview(formatter)<<"\n";
|
||||
std::cout<<jack.get_block_overview(formatter)<<"\n";
|
||||
|
||||
tdmdatatype A;
|
||||
A = (eUInt8Usi)0.354;
|
||||
std::cout<<A<<"\n";
|
||||
std::string chid("usi14");
|
||||
std::vector<tdmdatatype> chdata = jack.get_channel(chid);
|
||||
|
||||
// std::string chid("usi14");
|
||||
// std::vector<tdmdatatype> chdata = jack.get_channel<tdmdatatype>(chid);
|
||||
//
|
||||
// std::cout<<"channel size: "<<chdata.size()<<"\n";
|
||||
// for ( tdmdatatype el: chdata ) std::cout<<el<<"\n";
|
||||
std::cout<<"channel size: "<<chdata.size()<<"\n";
|
||||
for ( tdmdatatype el: chdata )
|
||||
{
|
||||
std::cout<<el<<":"<<el.dtype()<<"\n";
|
||||
}
|
||||
|
||||
// std::vector<std::string> chgrids = jack.get_channelgroup_ids();
|
||||
// for ( auto el: chgrids ) std::cout<<el<<",";
|
||||
|
Loading…
x
Reference in New Issue
Block a user