source: flair-dev/trunk/include/FlairCore/io_data.h@ 94

Last change on this file since 94 was 76, checked in by Sanahuja Guillaume, 6 years ago

m

File size: 5.5 KB
RevLine 
[2]1// %flair:license{
[13]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[2]4// %flair:license}
5/*!
6 * \file io_data.h
7 * \brief Abstract class for data types.
8 * \author Guillaume Sanahuja, Copyright Heudiasyc UMR UTC/CNRS 7253
9 * \date 2012/03/21
10 * \version 4.0
11 */
12
13#ifndef IO_DATA_H
14#define IO_DATA_H
15
16#include <Mutex.h>
17
18class IODevice_impl;
19class io_data_impl;
20
[13]21namespace flair {
22namespace core {
[2]23
[13]24class Object;
[2]25
[13]26class DataType {
27public:
28 virtual std::string GetDescription() const = 0;
29 // size in bytes
30 virtual size_t GetSize() const = 0;
31};
[2]32
[13]33class DummyType : public DataType {
34public:
35 size_t GetSize() const { return 0; }
36 std::string GetDescription() const { return "dummy"; };
37};
38extern DummyType dummyType;
[2]39
[13]40class ScalarType : public DataType {
41public:
42 ScalarType(size_t _size) : size(_size) {}
43 size_t GetSize() const { return size; }
44 virtual std::string GetDescription() const { return "scalar"; };
[2]45
[13]46private:
47 size_t size;
48};
[2]49
[13]50class SignedIntegerType : public ScalarType {
51public:
52 SignedIntegerType(size_t sizeInBits) : ScalarType(sizeInBits / 8) {}
53 std::string GetDescription() const {
54 return "int" + std::to_string(GetSize() * 8) + "_t";
55 };
56};
57extern SignedIntegerType Int8Type;
58extern SignedIntegerType Int16Type;
[2]59
[32]60class UnsignedIntegerType : public ScalarType {
61public:
62 UnsignedIntegerType(size_t sizeInBits) : ScalarType(sizeInBits / 8) {}
63 std::string GetDescription() const {
64 return "uint" + std::to_string(GetSize() * 8) + "_t";
65 };
66};
67extern UnsignedIntegerType UInt8Type;
68extern UnsignedIntegerType UInt16Type;
69
[13]70class FloatType : public ScalarType {
71public:
72 FloatType() : ScalarType(4) {}
73 std::string GetDescription() const { return "float"; };
74};
75extern FloatType floatType;
[2]76
[32]77class DoubleType : public ScalarType {
78public:
79 DoubleType() : ScalarType(8) {}
80 std::string GetDescription() const { return "double"; };
81};
82extern DoubleType doubleType;
83
[13]84/*! \class io_data
85*
86* \brief Abstract class for data types.
87*
88* Use this class to define a custom data type. Data types ares used for logging
89*and graphs. \n
90* The reimplemented class must call SetSize() in its constructor. \n
91* io_data can be constructed with n samples (see io_data::io_data).
92* In this case, old samples can be accessed throug io_data::Prev.
93*/
94class io_data : public Mutex {
95 friend class IODevice;
96 friend class ::IODevice_impl;
97 friend class ::io_data_impl;
[2]98
[13]99public:
100 /*!
101 * \brief Constructor
102 *
103 * Construct an io_data. \n
104 *
105 * \param parent parent
106 * \param name name
107 * \param n number of samples
108 */
109 io_data(const Object *parent, std::string name, int n);
[2]110
[13]111 /*!
112 * \brief Destructor
113 *
114 */
115 virtual ~io_data();
[2]116
[13]117 /*!
[68]118 * \brief Set data time, also caluculates the delta time based on last call
[13]119 *
[68]120 * TIME_INFINITE represents an unitialized time
121 *
[13]122 * \param time time
123 */
124 void SetDataTime(Time time);
[68]125
126 /*!
127 * \brief Set data time and delta time (thus delta time is not based on last call)
128 *
129 * TIME_INFINITE represents an unitialized time
130 *
131 * \param time time
132 * \param deltaTime delta time
133 */
134 void SetDataTime(Time time,Time deltaTime);
[2]135
[13]136 /*!
137 * \brief Data time
138 *
[68]139 * TIME_INFINITE represents an unitialized time.
140 *
[13]141 * \return data time
142 */
143 Time DataTime(void) const;
[68]144
145 /*!
146 * \brief Data delta time
147 *
148 * TIME_INFINITE represents an unitialized time.
149 *
150 * \return data delta time
151 */
152 Time DataDeltaTime(void) const;
153
154 /*!
155 * \brief Get data time and delta time
156 *
157 * TIME_INFINITE represents an unitialized time
158 *
159 * \param time time
160 * \param deltaTime delta time
161 */
162 void GetDataTime(Time &time,Time &deltaTime) const;
[2]163
[13]164 /*!
165 * \brief Previous data
166 *
167 * Access previous data. io_data must have been constructed with
168 * n>1, io_data::SetPtrToCircle must have been set and
169 * io_data::prev must have been allocated.
170 *
171 * \param n previous data number
172 *
173 * \return previous data
174 */
175 const io_data *Prev(int n) const;
[2]176
[13]177 virtual DataType const &GetDataType() const = 0;
[76]178
179 /*!
180 * \brief Raw write datas
181 *
182 * Copy the source to the internal datas. Source must be of the corresponding size.
183 *
184 * \param src source buffer
185 */
186 virtual void RawWrite(char *src) {};//todo put pure virtual
187
188 /*!
189 * \brief Raw read datas
190 *
191 * This method is automatically called by IODevice::ProcessUpdate to log
192 * io_data datas. \n
193 * This method must be reimplemented, in order to copy the datas to the logs.
194 * Copy the internal datas to destination. Destination must be of the corresponding size.
195 *
196 * \param dst destination buffer
197 */
198 virtual void RawRead(char *dst) const = 0;
[2]199
[76]200
[13]201protected:
202 /*!
203 * \brief Specify the description of the reimplemented class data's
204 *
205 * This method must be called in the constructor of the reimplemented class,
206 *once by element. \n
207 * Each element description must be called in the same order as CopyDatas put
208 *the datas in the buffer. \n
209 * The description will be used for the log descriptor file.
210 *
211 * \param description description of the element
212 * \param datatype type of the element
213 */
214 void AppendLogDescription(std::string description, DataType const &datatype);
[2]215
[13]216 /*!
217 * \brief Set the datas to circle
218 *
219 * \param ptr pointer to the data to circle
220 */
221 void SetPtrToCircle(void **ptr);
[2]222
[13]223 /*!
224 * \brief Pointer to previous data
225 *
226 * Reimplemented class must allocate this pointer if n>1. \n
227 * Pointer must be allocated with the same kind of reimplemented class.
228 */
229 io_data *prev;
[2]230
[13]231private:
232 io_data_impl *pimpl_;
233};
[2]234
235} // end namespace core
236} // end namespace flair
237
238#endif // IO_DATA_H
Note: See TracBrowser for help on using the repository browser.