Add a templated helper function for read and write to simplify the code
This commit is contained in:
parent
4b530e9376
commit
0530bc2cd7
@ -78,9 +78,19 @@ public:
|
|||||||
// read data from the topic.
|
// read data from the topic.
|
||||||
int read(char *buf, int length);
|
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.
|
// write data to the topic.
|
||||||
int write(const char *buf, const int length);
|
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.
|
// close the participant.
|
||||||
bool close();
|
bool close();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user