Add a templated helper function for read and write to simplify the code

This commit is contained in:
Erik Hofman 2021-03-27 13:56:21 +01:00
parent 4b530e9376
commit 0530bc2cd7

View File

@ -78,9 +78,19 @@ public:
// read data from the topic.
int read(char *buf, int length);
template<typename T>
bool read(T& sample) {
return (read((char*)&sample, sizeof(T)) == sizeof(T)) ? true : false;
}
// write data to the topic.
int write(const char *buf, const int length);
template<typename T>
bool write(const T& sample) {
return (write((char*)&sample, sizeof(T)) == sizeof(T)) ? true : false;
}
// close the participant.
bool close();