* tdm_datatype: - use typedefs to map basic types
- no derive type (polymorph) anymore * makefile: - use HPP to list .hpp dependencies
This commit is contained in:
parent
90253f819a
commit
93f0077146
@ -5,174 +5,266 @@
|
|||||||
|
|
||||||
// https://zone.ni.com/reference/de-XX/help/370858P-0113/tdmdatamodel/tdmdatamodel/tdm_header_tdx_data/
|
// 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
|
class tdmdatatype
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
short int sint16_;
|
eInt16Usi sint16_; // 0
|
||||||
int sint32_;
|
eInt32Usi sint32_; // 1
|
||||||
unsigned char uint8_;
|
eUInt8Usi uint8_; // 2
|
||||||
unsigned short int uint16_;
|
eUInt16Usi uint16_; // 3
|
||||||
unsigned int uint32_;
|
eUInt32Usi uint32_; // 4
|
||||||
float float32_;
|
eFloat32Usi float32_; // 5
|
||||||
double float64_;
|
eFloat64Usi float64_; // 6
|
||||||
|
short int dtidx_; // \in \{0,...,6\}
|
||||||
public:
|
public:
|
||||||
tdmdatatype(): sint16_(0), sint32_(0),
|
tdmdatatype(): sint16_(0), sint32_(0),
|
||||||
uint8_(0), uint16_(0), uint32_(0),
|
uint8_(0), uint16_(0), uint32_(0),
|
||||||
float32_(0.0), float64_(0.0) {};
|
float32_(0.0), float64_(0.0),
|
||||||
virtual ~tdmdatatype() = default;
|
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)
|
friend std::ostream& operator<<(std::ostream& out, const tdmdatatype& num)
|
||||||
{
|
{
|
||||||
return num.print(out);
|
std::cout<<"operator<< dtidx_:"<<num.dtidx_<<"\n";
|
||||||
}
|
if ( num.dtidx_ == 0 ) out<<num.sint16_;
|
||||||
virtual std::ostream& print(std::ostream& out) const
|
else if ( num.dtidx_ == 1 ) out<<num.sint32_;
|
||||||
{
|
else if ( num.dtidx_ == 2 ) out<<num.uint8_;
|
||||||
out<<"tdmdatatype";
|
else if ( num.dtidx_ == 3 ) out<<num.uint16_;
|
||||||
return out;
|
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;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class eInt16Usi: public tdmdatatype
|
// // base class for all tdm datatypes
|
||||||
{
|
// class tdmdatatype
|
||||||
public:
|
// {
|
||||||
eInt16Usi() { }
|
// protected:
|
||||||
eInt16Usi(short int num) { sint16_ = num; }
|
// short int sint16_;
|
||||||
// eInt16Usi& operator=(const eInt16Usi &num)
|
// int sint32_;
|
||||||
// {
|
// unsigned char uint8_;
|
||||||
// // self-assignment check
|
// unsigned short int uint16_;
|
||||||
// if ( this != &num)
|
// unsigned int uint32_;
|
||||||
// {
|
// float float32_;
|
||||||
// this->sint16_ = num.sint16_;
|
// double float64_;
|
||||||
// }
|
// public:
|
||||||
// return *this;
|
// tdmdatatype(): sint16_(0), sint32_(0),
|
||||||
// }
|
// uint8_(0), uint16_(0), uint32_(0),
|
||||||
friend std::ostream& operator<<(std::ostream& out, const eInt16Usi& num)
|
// float32_(0.0), float64_(0.0) {};
|
||||||
{
|
// virtual ~tdmdatatype() = default;
|
||||||
return num.print(out);
|
// friend std::ostream& operator<<(std::ostream& out, const tdmdatatype& num)
|
||||||
}
|
// {
|
||||||
std::ostream& print(std::ostream& out) const override
|
// return num.print(out);
|
||||||
{
|
// }
|
||||||
out<<sint16_;
|
// virtual std::ostream& print(std::ostream& out) const
|
||||||
return out;
|
// {
|
||||||
}
|
// out<<"tdmdatatype";
|
||||||
};
|
// return out;
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
class eInt32Usi: public tdmdatatype
|
// class eInt16Usi: public tdmdatatype
|
||||||
{
|
// {
|
||||||
public:
|
// public:
|
||||||
eInt32Usi() { }
|
// eInt16Usi() { }
|
||||||
eInt32Usi(int num) { sint32_ = num; }
|
// eInt16Usi(short int num) { sint16_ = num; }
|
||||||
friend std::ostream& operator<<(std::ostream& out, const eInt32Usi& num)
|
// // eInt16Usi& operator=(const eInt16Usi &num)
|
||||||
{
|
// // {
|
||||||
return num.print(out);
|
// // // self-assignment check
|
||||||
}
|
// // if ( this != &num)
|
||||||
std::ostream& print(std::ostream& out) const override
|
// // {
|
||||||
{
|
// // this->sint16_ = num.sint16_;
|
||||||
out<<sint32_;
|
// // }
|
||||||
return out;
|
// // return *this;
|
||||||
}
|
// // }
|
||||||
};
|
// friend std::ostream& operator<<(std::ostream& out, const eInt16Usi& num)
|
||||||
|
// {
|
||||||
class eUInt8Usi: public tdmdatatype
|
// return num.print(out);
|
||||||
{
|
// }
|
||||||
public:
|
// std::ostream& print(std::ostream& out) const override
|
||||||
eUInt8Usi() { }
|
// {
|
||||||
eUInt8Usi(int num) { uint8_ = num; }
|
// out<<sint16_;
|
||||||
friend std::ostream& operator<<(std::ostream& out, const eUInt8Usi& num)
|
// return out;
|
||||||
{
|
// }
|
||||||
return num.print(out);
|
// };
|
||||||
}
|
//
|
||||||
std::ostream& print(std::ostream& out) const override
|
// class eInt32Usi: public tdmdatatype
|
||||||
{
|
// {
|
||||||
out<<uint8_;
|
// public:
|
||||||
return out;
|
// eInt32Usi() { }
|
||||||
}
|
// eInt32Usi(int num) { sint32_ = num; }
|
||||||
};
|
// friend std::ostream& operator<<(std::ostream& out, const eInt32Usi& num)
|
||||||
|
// {
|
||||||
class eUInt16Usi: public tdmdatatype
|
// return num.print(out);
|
||||||
{
|
// }
|
||||||
public:
|
// std::ostream& print(std::ostream& out) const override
|
||||||
eUInt16Usi() { }
|
// {
|
||||||
eUInt16Usi(int num) { uint16_ = num; }
|
// out<<sint32_;
|
||||||
friend std::ostream& operator<<(std::ostream& out, const eUInt16Usi& num)
|
// return out;
|
||||||
{
|
// }
|
||||||
return num.print(out);
|
// };
|
||||||
}
|
//
|
||||||
std::ostream& print(std::ostream& out) const override
|
// class eUInt8Usi: public tdmdatatype
|
||||||
{
|
// {
|
||||||
out<<uint16_;
|
// public:
|
||||||
return out;
|
// eUInt8Usi() { }
|
||||||
}
|
// eUInt8Usi(int num) { uint8_ = num; }
|
||||||
};
|
// friend std::ostream& operator<<(std::ostream& out, const eUInt8Usi& num)
|
||||||
|
// {
|
||||||
class eUInt32Usi: public tdmdatatype
|
// return num.print(out);
|
||||||
{
|
// }
|
||||||
public:
|
// std::ostream& print(std::ostream& out) const override
|
||||||
eUInt32Usi() { }
|
// {
|
||||||
eUInt32Usi(int num) { uint32_ = num; }
|
// out<<uint8_;
|
||||||
friend std::ostream& operator<<(std::ostream& out, const eUInt32Usi& num)
|
// return out;
|
||||||
{
|
// }
|
||||||
return num.print(out);
|
// };
|
||||||
}
|
//
|
||||||
std::ostream& print(std::ostream& out) const override
|
// class eUInt16Usi: public tdmdatatype
|
||||||
{
|
// {
|
||||||
out<<uint32_;
|
// public:
|
||||||
return out;
|
// eUInt16Usi() { }
|
||||||
}
|
// eUInt16Usi(int num) { uint16_ = num; }
|
||||||
};
|
// friend std::ostream& operator<<(std::ostream& out, const eUInt16Usi& num)
|
||||||
|
// {
|
||||||
class eFloat32Usi: public tdmdatatype
|
// return num.print(out);
|
||||||
{
|
// }
|
||||||
public:
|
// std::ostream& print(std::ostream& out) const override
|
||||||
eFloat32Usi() { }
|
// {
|
||||||
eFloat32Usi(int num) { float32_ = num; }
|
// out<<uint16_;
|
||||||
friend std::ostream& operator<<(std::ostream& out, const eFloat32Usi& num)
|
// return out;
|
||||||
{
|
// }
|
||||||
return num.print(out);
|
// };
|
||||||
}
|
//
|
||||||
std::ostream& print(std::ostream& out) const override
|
// class eUInt32Usi: public tdmdatatype
|
||||||
{
|
// {
|
||||||
out<<float32_;
|
// public:
|
||||||
return out;
|
// eUInt32Usi() { }
|
||||||
}
|
// eUInt32Usi(int num) { uint32_ = num; }
|
||||||
};
|
// friend std::ostream& operator<<(std::ostream& out, const eUInt32Usi& num)
|
||||||
|
// {
|
||||||
class eFloat64Usi: public tdmdatatype
|
// return num.print(out);
|
||||||
{
|
// }
|
||||||
public:
|
// std::ostream& print(std::ostream& out) const override
|
||||||
eFloat64Usi() { }
|
// {
|
||||||
eFloat64Usi(int num) { float64_ = num; }
|
// out<<uint32_;
|
||||||
friend std::ostream& operator<<(std::ostream& out, const eFloat64Usi& num)
|
// return out;
|
||||||
{
|
// }
|
||||||
return num.print(out);
|
// };
|
||||||
}
|
//
|
||||||
std::ostream& print(std::ostream& out) const override
|
// class eFloat32Usi: public tdmdatatype
|
||||||
{
|
// {
|
||||||
out<<float64_;
|
// public:
|
||||||
return out;
|
// eFloat32Usi() { }
|
||||||
}
|
// eFloat32Usi(int num) { float32_ = num; }
|
||||||
};
|
// friend std::ostream& operator<<(std::ostream& out, const eFloat32Usi& num)
|
||||||
|
// {
|
||||||
|
// return num.print(out);
|
||||||
|
// }
|
||||||
|
// std::ostream& print(std::ostream& out) const override
|
||||||
|
// {
|
||||||
|
// out<<float32_;
|
||||||
|
// return out;
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// class eFloat64Usi: public tdmdatatype
|
||||||
|
// {
|
||||||
|
// public:
|
||||||
|
// eFloat64Usi() { }
|
||||||
|
// eFloat64Usi(int num) { float64_ = num; }
|
||||||
|
// friend std::ostream& operator<<(std::ostream& out, const eFloat64Usi& num)
|
||||||
|
// {
|
||||||
|
// return num.print(out);
|
||||||
|
// }
|
||||||
|
// std::ostream& print(std::ostream& out) const override
|
||||||
|
// {
|
||||||
|
// out<<float64_;
|
||||||
|
// return out;
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
struct tdm_datatype {
|
struct tdm_datatype {
|
||||||
|
|
||||||
|
7
makefile
7
makefile
@ -3,8 +3,9 @@
|
|||||||
# declare name of executable
|
# declare name of executable
|
||||||
EXE = tdmreaper
|
EXE = tdmreaper
|
||||||
|
|
||||||
# source name
|
# sources and headers
|
||||||
SRC := tdm_reaper
|
SRC := tdm_reaper
|
||||||
|
HPP = $(wildcard lib/*.hpp)
|
||||||
|
|
||||||
# compiler and C++ standard
|
# compiler and C++ standard
|
||||||
CC = g++ -std=c++17
|
CC = g++ -std=c++17
|
||||||
@ -38,7 +39,7 @@ uninstall : $(INST)/$(EXE)
|
|||||||
rm $<
|
rm $<
|
||||||
|
|
||||||
# build main.cpp object file and include git version/commit tag
|
# build main.cpp object file and include git version/commit tag
|
||||||
main.o : src/main.cpp lib/$(SRC).hpp lib/tdm_datamodel.hpp
|
main.o : src/main.cpp lib/$(SRC).hpp $(HPP)
|
||||||
@cp $< $<.cpp
|
@cp $< $<.cpp
|
||||||
@if [ $(OST) = "Linux" ]; then\
|
@if [ $(OST) = "Linux" ]; then\
|
||||||
sed -i 's/TAGSTRING/$(GTAG)/g' $<.cpp; \
|
sed -i 's/TAGSTRING/$(GTAG)/g' $<.cpp; \
|
||||||
@ -51,7 +52,7 @@ main.o : src/main.cpp lib/$(SRC).hpp lib/tdm_datamodel.hpp
|
|||||||
$(CC) -c $(OPT) -I $(LIB) -I lib/ $<.cpp -o $@
|
$(CC) -c $(OPT) -I $(LIB) -I lib/ $<.cpp -o $@
|
||||||
@rm $<.cpp
|
@rm $<.cpp
|
||||||
|
|
||||||
$(SRC).o : lib/$(SRC).cpp lib/$(SRC).hpp lib/tdm_datamodel.hpp
|
$(SRC).o : lib/$(SRC).cpp lib/$(SRC).hpp $(HPP)
|
||||||
$(CC) -c $(OPT) -I $(LIB) $< -o $@
|
$(CC) -c $(OPT) -I $(LIB) $< -o $@
|
||||||
|
|
||||||
clean :
|
clean :
|
||||||
|
12
src/main.cpp
12
src/main.cpp
@ -201,11 +201,15 @@ 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";
|
||||||
|
|
||||||
std::string chid("usi14");
|
tdmdatatype A;
|
||||||
std::vector<tdmdatatype> chdata = jack.get_channel<tdmdatatype>(chid);
|
A = (eUInt8Usi)0.354;
|
||||||
|
std::cout<<A<<"\n";
|
||||||
|
|
||||||
std::cout<<"channel size: "<<chdata.size()<<"\n";
|
// std::string chid("usi14");
|
||||||
for ( tdmdatatype el: chdata ) std::cout<<el<<"\n";
|
// 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::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<<",";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user