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