From 93f007714622315755f73d1ca829738c3f186823 Mon Sep 17 00:00:00 2001 From: Mario Fink Date: Fri, 22 Jan 2021 13:22:35 +0100 Subject: [PATCH] * tdm_datatype: - use typedefs to map basic types - no derive type (polymorph) anymore * makefile: - use HPP to list .hpp dependencies --- lib/tdm_datatype.hpp | 406 ++++++++++++++++++++++++++----------------- makefile | 7 +- src/main.cpp | 12 +- 3 files changed, 261 insertions(+), 164 deletions(-) diff --git a/lib/tdm_datatype.hpp b/lib/tdm_datatype.hpp index 21b11bc..5d48f99 100644 --- a/lib/tdm_datatype.hpp +++ b/lib/tdm_datatype.hpp @@ -5,174 +5,266 @@ // https://zone.ni.com/reference/de-XX/help/370858P-0113/tdmdatamodel/tdmdatamodel/tdm_header_tdx_data/ -// define mapping of C++ supported datatypes to tdm datatypes +// !!!! define mapping of locally supported datatypes to tdm datatypes +// !!!! this is where the magic happens !!! +typedef short int eInt16Usi; +typedef int eInt32Usi; +typedef unsigned char eUInt8Usi; +typedef unsigned short int eUInt16Usi; +typedef unsigned int eUInt32Usi; +typedef float eFloat32Usi; +typedef double eFloat64Usi; -// define mapping of locally supported datatypes to tdm datatypes -// typedef short int eInt16Usi; -// typedef int eInt32Usi; -// typedef unsigned char eUInt8Usi; -// typedef unsigned short int eUInt16Usi; -// typedef unsigned int eUInt32Usi; -// typedef float eFloat32Usi; -// typedef double eFloat64Usi; - -// enum class tdmdatatype { -// eInt16Usi, -// eInt32Usi, -// eUInt8Usi, -// eUInt16Usi, -// eUInt32Usi, -// eFloat32Usi, -// eFloat64Usi -// }; - -// base class for all tdm datatypes class tdmdatatype { protected: - short int sint16_; - int sint32_; - unsigned char uint8_; - unsigned short int uint16_; - unsigned int uint32_; - float float32_; - double float64_; + eInt16Usi sint16_; // 0 + eInt32Usi sint32_; // 1 + eUInt8Usi uint8_; // 2 + eUInt16Usi uint16_; // 3 + eUInt32Usi uint32_; // 4 + eFloat32Usi float32_; // 5 + eFloat64Usi float64_; // 6 + short int dtidx_; // \in \{0,...,6\} public: tdmdatatype(): sint16_(0), sint32_(0), uint8_(0), uint16_(0), uint32_(0), - float32_(0.0), float64_(0.0) {}; - virtual ~tdmdatatype() = default; + float32_(0.0), float64_(0.0), + dtidx_(0) { std::cout<<"tdmdatatype constructor\n"; }; + // every supported datatype get its own constructor + tdmdatatype(eInt16Usi num): sint16_(num), dtidx_(0) {}; + tdmdatatype(eInt32Usi num): sint32_(num), dtidx_(1) {}; + tdmdatatype(eUInt8Usi num): uint8_(num), dtidx_(2) {}; + tdmdatatype(eUInt16Usi num): uint16_(num), dtidx_(3) {}; + tdmdatatype(eUInt32Usi num): uint32_(num), dtidx_(4) {}; + tdmdatatype(eFloat32Usi num): float32_(num), dtidx_(5) {}; + tdmdatatype(eFloat64Usi num): float64_(num), dtidx_(6) {}; + + // overall assignment operator + tdmdatatype& operator=(const tdmdatatype &num) + { + if ( this != &num ) + { + this->sint16_ = num.sint16_; + this->sint32_ = num.sint32_; + this->uint8_ = num.uint8_; + this->uint16_ = num.uint16_; + this->uint32_ = num.uint32_; + this->float32_ = num.float32_; + this->float64_ = num.float64_; + } + + return *this; + } + + // implement assignment operator for individual datatypes + tdmdatatype& operator=(const eInt16Usi &num) + { + this->sint16_ = num; + this->dtidx_ = 0; + return *this; + } + tdmdatatype& operator=(const eInt32Usi &num) + { + this->sint32_ = num; + this->dtidx_ = 1; + return *this; + } + tdmdatatype& operator=(const eUInt8Usi &num) + { + this->uint8_ = num; + this->dtidx_ = 2; + return *this; + } + tdmdatatype& operator=(const eUInt16Usi &num) + { + this->uint16_ = num; + this->dtidx_ = 3; + return *this; + } + tdmdatatype& operator=(const eUInt32Usi &num) + { + this->uint32_ = num; + this->dtidx_ = 4; + return *this; + } + 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; + } + + // define custom stream operator to print the correct type friend std::ostream& operator<<(std::ostream& out, const tdmdatatype& num) - { - return num.print(out); - } - virtual std::ostream& print(std::ostream& out) const - { - out<<"tdmdatatype"; - return out; - } + { + std::cout<<"operator<< dtidx_:"<sint16_ = num.sint16_; - // } - // return *this; - // } - friend std::ostream& operator<<(std::ostream& out, const eInt16Usi& num) - { - return num.print(out); - } - std::ostream& print(std::ostream& out) const override - { - out<sint16_ = num.sint16_; +// // } +// // return *this; +// // } +// friend std::ostream& operator<<(std::ostream& out, const eInt16Usi& num) +// { +// return num.print(out); +// } +// std::ostream& print(std::ostream& out) const override +// { +// out< chdata = jack.get_channel(chid); + tdmdatatype A; + A = (eUInt8Usi)0.354; + std::cout< chdata = jack.get_channel(chid); + // + // std::cout<<"channel size: "< chgrids = jack.get_channelgroup_ids(); // for ( auto el: chgrids ) std::cout<