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