[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 Object.h
|
---|
| 7 | * \brief Base class for all Framework's classes
|
---|
| 8 | * \author Guillaume Sanahuja, Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 9 | * \date 2012/05/07
|
---|
| 10 | * \version 4.0
|
---|
| 11 | */
|
---|
| 12 |
|
---|
| 13 | #ifndef OBJECT_H
|
---|
| 14 | #define OBJECT_H
|
---|
| 15 |
|
---|
| 16 | #include <string>
|
---|
| 17 | #include <vector>
|
---|
| 18 | #include <stdarg.h>
|
---|
| 19 |
|
---|
[13] | 20 | #define Warn(...) Warning(__PRETTY_FUNCTION__, __VA_ARGS__)
|
---|
| 21 | #define Err(...) Error(__PRETTY_FUNCTION__, __VA_ARGS__)
|
---|
| 22 | #define Info(...) Information(__PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
|
---|
[2] | 23 |
|
---|
| 24 | #define TIME_INFINITE 0
|
---|
| 25 | #define TIME_NONBLOCK ((Time)-1)
|
---|
| 26 |
|
---|
| 27 | class Object_impl;
|
---|
| 28 | class Widget_impl;
|
---|
| 29 |
|
---|
[13] | 30 | namespace flair {
|
---|
| 31 | namespace core {
|
---|
[2] | 32 |
|
---|
[13] | 33 | class FrameworkManager;
|
---|
[2] | 34 |
|
---|
[13] | 35 | class Message {
|
---|
| 36 | public:
|
---|
| 37 | Message(unsigned int myBufferSize) : bufferSize(myBufferSize) {
|
---|
| 38 | buffer = new char[bufferSize];
|
---|
| 39 | }
|
---|
| 40 | ~Message() { delete buffer; }
|
---|
| 41 | char *buffer;
|
---|
| 42 | size_t bufferSize;
|
---|
| 43 | };
|
---|
[2] | 44 |
|
---|
[13] | 45 | /*!
|
---|
| 46 | * \brief Time definition, in ns
|
---|
| 47 | *
|
---|
| 48 | */
|
---|
| 49 | typedef unsigned long long Time;
|
---|
[2] | 50 |
|
---|
[13] | 51 | /*!
|
---|
| 52 | * \brief Time
|
---|
| 53 | *
|
---|
| 54 | * \return actual time in ns (origin depends on whether the method is compiled in
|
---|
| 55 | *hard real time mode or not. As a conquence, only time differences should be
|
---|
| 56 | *used)
|
---|
| 57 | */
|
---|
| 58 | Time GetTime(void);
|
---|
[2] | 59 |
|
---|
[13] | 60 | /*!
|
---|
| 61 | * \brief Formatted print
|
---|
| 62 | *
|
---|
| 63 | * See standard printf for syntax.
|
---|
| 64 | *
|
---|
| 65 | * \param format text string to display
|
---|
| 66 | */
|
---|
| 67 | void Printf(const char *format, ...);
|
---|
[2] | 68 |
|
---|
[13] | 69 | /*! \class Object
|
---|
| 70 | *
|
---|
| 71 | * \brief Base class for all Framework's classes
|
---|
| 72 | *
|
---|
| 73 | * This is the base class for all other classes. \n
|
---|
| 74 | * It handles parent/child links and thus allow auto destruction of childs.
|
---|
| 75 | *
|
---|
| 76 | */
|
---|
| 77 | class Object {
|
---|
| 78 | friend class ::Widget_impl;
|
---|
[2] | 79 |
|
---|
[13] | 80 | public:
|
---|
| 81 | typedef enum { Auto = 0, Red = 31, Green = 32, Orange = 33 } color_t;
|
---|
| 82 | /*!
|
---|
| 83 | * \brief Constructor
|
---|
| 84 | *
|
---|
| 85 | * Construct an Object, which is child of its parent.
|
---|
| 86 | *
|
---|
| 87 | * \param parent parent
|
---|
| 88 | * \param name name
|
---|
| 89 | * \param type type
|
---|
| 90 | */
|
---|
| 91 | Object(const Object *parent = NULL, std::string name = "",
|
---|
| 92 | std::string type = "");
|
---|
[2] | 93 |
|
---|
[13] | 94 | /*!
|
---|
| 95 | * \brief Destructor
|
---|
| 96 | *
|
---|
| 97 | * Calling it will automatically destruct all childs.
|
---|
| 98 | *
|
---|
| 99 | */
|
---|
| 100 | virtual ~Object();
|
---|
[2] | 101 |
|
---|
[13] | 102 | /*!
|
---|
| 103 | * \brief Name
|
---|
| 104 | *
|
---|
| 105 | * \return Object's name
|
---|
| 106 | */
|
---|
| 107 | std::string ObjectName(void) const;
|
---|
[2] | 108 |
|
---|
[13] | 109 | /*!
|
---|
| 110 | * \brief Type
|
---|
| 111 | *
|
---|
| 112 | * \return Object's type
|
---|
| 113 | */
|
---|
| 114 | std::string ObjectType(void) const;
|
---|
[2] | 115 |
|
---|
[13] | 116 | /*!
|
---|
| 117 | * \brief Parent
|
---|
| 118 | *
|
---|
| 119 | * \return Object's parent
|
---|
| 120 | */
|
---|
| 121 | const Object *Parent(void) const;
|
---|
[2] | 122 |
|
---|
[13] | 123 | /*!
|
---|
| 124 | * \brief Childs of the same type
|
---|
| 125 | *
|
---|
| 126 | * \return a vector of all childs of the same type
|
---|
| 127 | */
|
---|
| 128 | std::vector<const Object *> *TypeChilds(void) const;
|
---|
[2] | 129 |
|
---|
[13] | 130 | /*!
|
---|
| 131 | * \brief Childs
|
---|
| 132 | *
|
---|
| 133 | * \return a vector of all childs
|
---|
| 134 | */
|
---|
| 135 | std::vector<const Object *> *Childs(void) const;
|
---|
[2] | 136 |
|
---|
[13] | 137 | /*!
|
---|
| 138 | * \brief Formatted information
|
---|
| 139 | *
|
---|
| 140 | * Green colored Printf(). \n
|
---|
| 141 | * Note that it is better to call Info macro, which automatically fills
|
---|
| 142 | *function parameter.
|
---|
| 143 | *
|
---|
| 144 | * \param function name of calling function
|
---|
| 145 | * \param line line number in calling function
|
---|
| 146 | * \param format text string to display
|
---|
| 147 | */
|
---|
| 148 | void Information(const char *function, int line, const char *format,
|
---|
| 149 | ...) const;
|
---|
[2] | 150 |
|
---|
[13] | 151 | /*!
|
---|
| 152 | * \brief Formatted warning
|
---|
| 153 | *
|
---|
| 154 | * Orange colored Printf(). \n
|
---|
| 155 | * Note that it is better to call Warn macro, which automatically fills
|
---|
| 156 | *function parameter.
|
---|
| 157 | *
|
---|
| 158 | * \param function name of calling function
|
---|
| 159 | * \param format text string to display
|
---|
| 160 | */
|
---|
| 161 | void Warning(const char *function, const char *format, ...) const;
|
---|
[2] | 162 |
|
---|
[13] | 163 | /*!
|
---|
| 164 | * \brief Formatted error
|
---|
| 165 | *
|
---|
| 166 | * Red colored Printf(). \n
|
---|
| 167 | * Note that it is better to call Err macro, which automatically fills function
|
---|
| 168 | *parameter. \n
|
---|
| 169 | * After calling this method, ErrorOccured() will always return true.
|
---|
| 170 | *
|
---|
| 171 | * \param function name of calling function
|
---|
| 172 | * \param format text string to display
|
---|
| 173 | */
|
---|
| 174 | void Error(const char *function, const char *format, ...) const;
|
---|
[2] | 175 |
|
---|
[13] | 176 | /*!
|
---|
| 177 | * \brief Has an errror occured?
|
---|
| 178 | *
|
---|
| 179 | * Check if an error occured, in fact if Error() was called at least once. \n
|
---|
| 180 | * Once Error() was called, this method will never return back false.
|
---|
| 181 | *
|
---|
| 182 | * \param recursive if true, recursively check among childs
|
---|
| 183 | * \return true if an error occured
|
---|
| 184 | */
|
---|
| 185 | bool ErrorOccured(bool recursive = true) const;
|
---|
[2] | 186 |
|
---|
[13] | 187 | private:
|
---|
| 188 | class Object_impl *pimpl_;
|
---|
| 189 | void ColorPrintf(color_t, const char *function, int line, const char *format,
|
---|
| 190 | va_list *args) const;
|
---|
| 191 | };
|
---|
[2] | 192 |
|
---|
| 193 | } // end namespace core
|
---|
| 194 | } // end namespace flair
|
---|
| 195 |
|
---|
| 196 | #endif // OBJECT_H
|
---|