source: flair-dev/trunk/include/FlairCore/Object.h@ 28

Last change on this file since 28 was 13, checked in by Bayard Gildas, 9 years ago

formatting script + include reformatted

File size: 4.3 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 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#define Warn(...) Warning(__PRETTY_FUNCTION__, __VA_ARGS__)
21#define Err(...) Error(__PRETTY_FUNCTION__, __VA_ARGS__)
22#define Info(...) Information(__PRETTY_FUNCTION__, __LINE__, __VA_ARGS__)
23
24#define TIME_INFINITE 0
25#define TIME_NONBLOCK ((Time)-1)
26
27class Object_impl;
28class Widget_impl;
29
30namespace flair {
31namespace core {
32
33class FrameworkManager;
34
35class Message {
36public:
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};
44
45/*!
46* \brief Time definition, in ns
47*
48*/
49typedef unsigned long long Time;
50
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*/
58Time GetTime(void);
59
60/*!
61* \brief Formatted print
62*
63* See standard printf for syntax.
64*
65* \param format text string to display
66*/
67void Printf(const char *format, ...);
68
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*/
77class Object {
78 friend class ::Widget_impl;
79
80public:
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 = "");
93
94 /*!
95 * \brief Destructor
96 *
97 * Calling it will automatically destruct all childs.
98 *
99 */
100 virtual ~Object();
101
102 /*!
103 * \brief Name
104 *
105 * \return Object's name
106 */
107 std::string ObjectName(void) const;
108
109 /*!
110 * \brief Type
111 *
112 * \return Object's type
113 */
114 std::string ObjectType(void) const;
115
116 /*!
117 * \brief Parent
118 *
119 * \return Object's parent
120 */
121 const Object *Parent(void) const;
122
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;
129
130 /*!
131 * \brief Childs
132 *
133 * \return a vector of all childs
134 */
135 std::vector<const Object *> *Childs(void) const;
136
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;
150
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;
162
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;
175
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;
186
187private:
188 class Object_impl *pimpl_;
189 void ColorPrintf(color_t, const char *function, int line, const char *format,
190 va_list *args) const;
191};
192
193} // end namespace core
194} // end namespace flair
195
196#endif // OBJECT_H
Note: See TracBrowser for help on using the repository browser.