Flair
Framework Libre Air
io_data.h
Go to the documentation of this file.
1 // %flair:license{
2 // This file is part of the Flair framework distributed under the
3 // CECILL-C License, Version 1.0.
4 // %flair:license}
13 #ifndef IO_DATA_H
14 #define IO_DATA_H
15 
16 #include <Mutex.h>
17 
18 class IODevice_impl;
19 class io_data_impl;
20 
21 namespace flair {
22 namespace core {
23 
24 class Object;
25 
26 class DataType {
27 public:
28  virtual std::string GetDescription() const = 0;
29  // size in bytes
30  virtual size_t GetSize() const = 0;
31 };
32 
33 class DummyType : public DataType {
34 public:
35  size_t GetSize() const { return 0; }
36  std::string GetDescription() const { return "dummy"; };
37 };
38 extern DummyType dummyType;
39 
40 class ScalarType : public DataType {
41 public:
42  ScalarType(size_t _size) : size(_size) {}
43  size_t GetSize() const { return size; }
44  virtual std::string GetDescription() const { return "scalar"; };
45 
46 private:
47  size_t size;
48 };
49 
50 class SignedIntegerType : public ScalarType {
51 public:
52  SignedIntegerType(size_t sizeInBits) : ScalarType(sizeInBits / 8) {}
53  std::string GetDescription() const {
54  return "int" + std::to_string(GetSize() * 8) + "_t";
55  };
56 };
57 extern SignedIntegerType Int8Type;
58 extern SignedIntegerType Int16Type;
59 
61 public:
62  UnsignedIntegerType(size_t sizeInBits) : ScalarType(sizeInBits / 8) {}
63  std::string GetDescription() const {
64  return "uint" + std::to_string(GetSize() * 8) + "_t";
65  };
66 };
67 extern UnsignedIntegerType UInt8Type;
68 extern UnsignedIntegerType UInt16Type;
69 
70 class FloatType : public ScalarType {
71 public:
72  FloatType() : ScalarType(4) {}
73  std::string GetDescription() const { return "float"; };
74 };
75 extern FloatType floatType;
76 
77 class DoubleType : public ScalarType {
78 public:
79  DoubleType() : ScalarType(8) {}
80  std::string GetDescription() const { return "double"; };
81 };
82 extern DoubleType doubleType;
83 
94 class io_data : public Mutex {
95  friend class IODevice;
96  friend class ::IODevice_impl;
97  friend class ::io_data_impl;
98 
99 public:
109  io_data(const Object *parent, std::string name, int n);
110 
115  virtual ~io_data();
116 
124  void SetDataTime(Time time);
125 
134  void SetDataTime(Time time,Time deltaTime);
135 
143  Time DataTime(void) const;
144 
152  Time DataDeltaTime(void) const;
153 
162  void GetDataTime(Time &time,Time &deltaTime) const;
163 
175  const io_data *Prev(int n) const;
176 
177  virtual DataType const &GetDataType() const = 0;
178 
186  virtual void RawWrite(char *src) {};//todo put pure virtual
187 
198  virtual void RawRead(char *dst) const = 0;
199 
200 
201 protected:
214  void AppendLogDescription(std::string description, DataType const &datatype);
215 
221  void SetPtrToCircle(void **ptr);
222 
230 
231 private:
232  io_data_impl *pimpl_;
233 };
234 
235 } // end namespace core
236 } // end namespace flair
237 
238 #endif // IO_DATA_H
Abstract class for data types.
Definition: io_data.h:94
const io_data * Prev(int n) const
Previous data.
Definition: io_data.h:26
Time DataDeltaTime(void) const
Data delta time.
Base class for all Framework's classes.
Definition: Object.h:77
Abstract class for input/ouput system.
Definition: IODevice.h:45
namespace of the flair Framework
Definition: Ahrs.h:19
Time DataTime(void) const
Data time.
Class defining a mutex.
Definition: Mutex.h:29
unsigned long long Time
Time definition, in ns.
Definition: Object.h:49
virtual void RawWrite(char *src)
Raw write datas.
Definition: io_data.h:186
void SetPtrToCircle(void **ptr)
Set the datas to circle.
io_data * prev
Pointer to previous data.
Definition: io_data.h:229
Definition: io_data.h:40
Definition: io_data.h:77
Definition: io_data.h:33
void SetDataTime(Time time)
Set data time, also caluculates the delta time based on last call.
Definition: io_data.h:60
Class defining a mutex.
io_data(const Object *parent, std::string name, int n)
Constructor.
Definition: io_data.h:50
void AppendLogDescription(std::string description, DataType const &datatype)
Specify the description of the reimplemented class data's.
Definition: io_data.h:70
virtual ~io_data()
Destructor.
void GetDataTime(Time &time, Time &deltaTime) const
Get data time and delta time.
virtual void RawRead(char *dst) const =0
Raw read datas.