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

Last change on this file since 12 was 2, checked in by Sanahuja Guillaume, 9 years ago

initial commit flaircore

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