source: flair-src/branches/sanscv/lib/FlairCore/src/Object.cpp@ 475

Last change on this file since 475 was 324, checked in by Sanahuja Guillaume, 5 years ago

removing opencv dependency

File size: 3.8 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// created: 2012/05/07
6// filename: Object.cpp
7//
8// author: Guillaume Sanahuja
9// Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11// version: $Id: $
12//
13// purpose: Base class for all Framework's classes
14//
15//
16/*********************************************************************/
17
18#include <stdio.h>
19
20#include "Object.h"
21#include "Object_impl.h"
22#include "FrameworkManager.h"
23
24#ifdef __XENO__
25#include <native/task.h>
26#include <native/timer.h>
27#include "rtdk.h"
28#else
29#include <sys/time.h>
30#endif
31
32using std::string;
33using std::vector;
34
35namespace flair {
36namespace core {
37
38Time GetTime(void) {
39#ifdef __XENO__
40 return rt_timer_read();
41#else
42 struct timeval t;
43 gettimeofday(&t, NULL);
44 return (Time)((Time)(t.tv_sec) * 1000000 + (Time)(t.tv_usec)) * 1000;
45#endif
46}
47
48unsigned long long GetTimeMS(void) {
49#ifdef __XENO__
50 return rt_timer_read()/1000000;
51#else
52 struct timeval t;
53 gettimeofday(&t, NULL);
54 return (unsigned long long)((unsigned long long)(t.tv_sec) * 1000 + (unsigned long long)(t.tv_usec))/1000;
55#endif
56}
57
58void Printf(const char *format, ...) {
59 va_list args;
60 va_start(args, format);
61#ifdef __XENO__
62 if (rt_task_self() != NULL) {
63 rt_vfprintf(stderr, format, args);
64 } else
65#endif
66 {
67 vfprintf(stderr, format, args);
68 }
69
70 va_end(args);
71}
72
73Object::Object(const Object *parent, string name, string type) {
74 pimpl_ = new Object_impl(this, parent, name, type);
75 if (parent != NULL)
76 parent->pimpl_->AddChild(this);
77}
78
79Object::~Object() {
80 if (pimpl_->parent != NULL)
81 pimpl_->parent->pimpl_->RemoveChild(this);
82 delete pimpl_;
83}
84
85string Object::ObjectName(void) const { return pimpl_->name; }
86
87string Object::ObjectType(void) const { return pimpl_->type; }
88
89const Object *Object::Parent(void) const { return pimpl_->parent; }
90
91vector<const Object *> *Object::TypeChilds(void) const {
92 return &(pimpl_->type_childs);
93}
94
95vector<const Object *> *Object::Childs(void) const { return &(pimpl_->childs); }
96
97void Object::ColorPrintf(color_t color, const char *function, int line,
98 const char *format, va_list *args) const {
99#ifdef __XENO__
100 if (rt_task_self() != NULL) {
101 rt_fprintf(stderr, "\033[%dm", color);
102 if(function) {
103 if (line) {
104 rt_fprintf(stderr, "%s - line %d, %s: ", function, line,
105 pimpl_->name.c_str());
106 } else {
107 rt_fprintf(stderr, "%s, %s: ", function, pimpl_->name.c_str());
108 }
109 }
110 rt_vfprintf(stderr, format, *args);
111 rt_fprintf(stderr, "\033[%dm", color_t::Auto);
112 } else
113#endif
114 {
115 fprintf(stderr, "\033[%dm", color);
116 if(function) {
117 if (line) {
118 fprintf(stderr, "%s - line %d, %s: ", function, line,
119 pimpl_->name.c_str());
120 } else {
121 fprintf(stderr, "%s, %s: ", function, pimpl_->name.c_str());
122 }
123 }
124 vfprintf(stderr, format, *args);
125 fprintf(stderr, "\033[%dm", color_t::Auto);
126 }
127}
128
129void Object::Information(const char *function, int line, const char *format,
130 ...) const {
131 va_list args;
132 va_start(args, format);
133 ColorPrintf(color_t::Green, function, line, format, &args);
134 va_end(args);
135}
136
137void Object::Warning(const char *function, const char *format, ...) const {
138 va_list args;
139 va_start(args, format);
140 ColorPrintf(color_t::Orange, function, 0, format, &args);
141 va_end(args);
142}
143
144void Object::Error(const char *function, const char *format, ...) const {
145 va_list args;
146 va_start(args, format);
147 ColorPrintf(color_t::Red, function, 0, format, &args);
148 va_end(args);
149
150 pimpl_->error_occured = true;
151}
152
153bool Object::ErrorOccured(bool recursive) const {
154 return pimpl_->ErrorOccured(recursive);
155}
156
157} // end namespace core
158} // end namespace flair
Note: See TracBrowser for help on using the repository browser.