From 0530bc2cd74fd365939dd43a160993140d48b119 Mon Sep 17 00:00:00 2001 From: Erik Hofman Date: Sat, 27 Mar 2021 13:56:21 +0100 Subject: [PATCH] Add a templated helper function for read and write to simplify the code --- simgear/io/SGDataDistributionService.hxx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/simgear/io/SGDataDistributionService.hxx b/simgear/io/SGDataDistributionService.hxx index d915a04e..92613fe0 100644 --- a/simgear/io/SGDataDistributionService.hxx +++ b/simgear/io/SGDataDistributionService.hxx @@ -78,9 +78,19 @@ public: // read data from the topic. int read(char *buf, int length); + template + 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 + bool write(const T& sample) { + return (write((char*)&sample, sizeof(T)) == sizeof(T)) ? true : false; + } + // close the participant. bool close();