source: flair-src/trunk/lib/FlairCore/src/Object.h

Last change on this file was 294, checked in by Sanahuja Guillaume, 3 years ago

vrpn modifs

File size: 4.6 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//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
33class Object_impl;
34class Widget_impl;
35
36namespace flair {
37namespace core {
38
39class FrameworkManager;
40
41class Message {
42public:
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*/
55typedef 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*/
64Time GetTime(void);
65
66/*!
67* \brief Formatted print
68*
69* See standard printf for syntax.
70*
71* \param format text string to display
72*/
73void Printf(const char *format, ...);
74
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*/
83class Object {
84  friend class ::Widget_impl;
85
86public:
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 = "");
99
100  /*!
101  * \brief Destructor
102  *
103  * Calling it will automatically destruct all childs.
104  *
105  */
106  virtual ~Object();
107
108  /*!
109  * \brief Name
110  *
111  * \return Object's name
112  */
113  std::string ObjectName(void) const;
114
115  /*!
116  * \brief Type
117  *
118  * \return Object's type
119  */
120  std::string ObjectType(void) const;
121
122  /*!
123  * \brief Parent
124  *
125  * \return Object's parent
126  */
127  const Object *Parent(void) const;
128
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;
135
136  /*!
137  * \brief Childs
138  *
139  * \return a vector of all childs
140  */
141  std::vector<const Object *> *Childs(void) const;
142
143  /*!
144  * \brief Formatted information
145  *
146  * Green colored Printf(). \n
147  * Note that it is better to call Info macro, which automatically fills
148  * calling 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,
155                   ...) const;
156
157  /*!
158  * \brief Formatted warning
159  *
160  * Orange colored Printf(). \n
161  * Note that it is better to call Warn macro, which automatically fills
162  * calling function parameter.
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;
168
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
174  * calling parameter. \n
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;
181
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;
192
193private:
194  class Object_impl *pimpl_;
195  void ColorPrintf(color_t, const char *function, int line, const char *format,
196                   va_list *args) const;
197};
198
199} // end namespace core
200} // end namespace flair
201
202#endif // OBJECT_H
Note: See TracBrowser for help on using the repository browser.