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