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

Last change on this file since 12 was 2, checked in by Sanahuja Guillaume, 9 years ago

initial commit flaircore

File size: 4.9 KB
Line 
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}
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
21namespace flair { namespace core {
22
23 class Object;
24
25 class DataType {
26 public:
27 virtual std::string GetDescription() const =0;
28 //size in bytes
29 virtual size_t GetSize() const =0;
30 };
31
32 class DummyType: public DataType {
33 public:
34 size_t GetSize() const {return 0;}
35 std::string GetDescription() const {return "dummy";};
36 };
37 extern DummyType dummyType;
38
39 class ScalarType: public DataType {
40 public:
41 ScalarType(size_t _size):size(_size) {}
42 size_t GetSize() const {return size;}
43 virtual std::string GetDescription() const {return "scalar";};
44 private:
45 size_t size;
46 };
47
48 class SignedIntegerType: public ScalarType {
49 public:
50 SignedIntegerType(size_t sizeInBits):ScalarType(sizeInBits/8){}
51 std::string GetDescription() const {return "int"+std::to_string(GetSize()*8)+"_t";};
52 };
53 extern SignedIntegerType Int8Type;
54 extern SignedIntegerType Int16Type;
55
56 class FloatType: public ScalarType {
57 public:
58 FloatType():ScalarType(4){}
59 std::string GetDescription() const {return "float";};
60 };
61 extern FloatType floatType;
62
63
64 /*! \class io_data
65 *
66 * \brief Abstract class for data types.
67 *
68 * Use this class to define a custom data type. Data types ares used for logging and graphs. \n
69 * The reimplemented class must call SetSize() in its constructor. \n
70 * io_data can be constructed with n samples (see io_data::io_data).
71 * In this case, old samples can be accessed throug io_data::Prev.
72 */
73 class io_data: public Mutex {
74 friend class IODevice;
75 friend class ::IODevice_impl;
76 friend class ::io_data_impl;
77
78 public:
79 /*!
80 * \brief Constructor
81 *
82 * Construct an io_data. \n
83 *
84 * \param parent parent
85 * \param name name
86 * \param n number of samples
87 */
88 io_data(const Object* parent,std::string name,int n);
89
90 /*!
91 * \brief Destructor
92 *
93 */
94 virtual ~io_data();
95
96 /*!
97 * \brief Set data time
98 *
99 * \param time time
100 */
101 void SetDataTime(Time time);
102
103 /*!
104 * \brief Data time
105 *
106 * \return data time
107 */
108 Time DataTime(void) const;
109
110 /*!
111 * \brief Previous data
112 *
113 * Access previous data. io_data must have been constructed with
114 * n>1, io_data::SetPtrToCircle must have been set and
115 * io_data::prev must have been allocated.
116 *
117 * \param n previous data number
118 *
119 * \return previous data
120 */
121 const io_data* Prev(int n) const;
122
123 virtual DataType const&GetDataType() const =0;
124
125 protected:
126 /*!
127 * \brief Specify the description of the reimplemented class data's
128 *
129 * This method must be called in the constructor of the reimplemented class, once by element. \n
130 * Each element description must be called in the same order as CopyDatas put the datas in the buffer. \n
131 * The description will be used for the log descriptor file.
132 *
133 * \param description description of the element
134 * \param datatype type of the element
135 */
136 void AppendLogDescription(std::string description, DataType const &datatype);
137
138 /*!
139 * \brief Set the datas to circle
140 *
141 * \param ptr pointer to the data to circle
142 */
143 void SetPtrToCircle(void **ptr);
144
145 /*!
146 * \brief Pointer to previous data
147 *
148 * Reimplemented class must allocate this pointer if n>1. \n
149 * Pointer must be allocated with the same kind of reimplemented class.
150 */
151 io_data* prev;
152
153 private:
154 /*!
155 * \brief Copy datas
156 *
157 * This method is automatically called by IODevice::ProcessUpdate to log io_data datas. \n
158 * This method must be reimplemented, in order to copy the datas to the logs.
159 * Copied datas must be of size io_data::Size.
160 *
161 * \param dst destination buffer
162 */
163 virtual void CopyDatas(char* dst) const =0;
164
165 io_data_impl *pimpl_;
166 };
167
168} // end namespace core
169} // end namespace flair
170
171#endif // IO_DATA_H
Note: See TracBrowser for help on using the repository browser.