Changeset 15 in flair-src for trunk/lib/FlairCore/src/Object.cpp
- Timestamp:
- 04/08/16 15:40:57 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairCore/src/Object.cpp
r2 r15 33 33 using std::vector; 34 34 35 namespace flair 36 { 37 namespace core 38 { 35 namespace flair { 36 namespace core { 39 37 40 Time GetTime(void) 41 { 38 Time GetTime(void) { 42 39 #ifdef __XENO__ 43 40 return rt_timer_read(); 44 41 #else 45 46 47 return (Time)((Time)(t.tv_sec)*1000000 + (Time)(t.tv_usec))*1000;42 struct timeval t; 43 gettimeofday(&t, NULL); 44 return (Time)((Time)(t.tv_sec) * 1000000 + (Time)(t.tv_usec)) * 1000; 48 45 49 46 #endif 50 47 } 51 48 52 void Printf(const char *format, ...) 53 { 54 va_list args; 55 va_start(args, format); 49 void Printf(const char *format, ...) { 50 va_list args; 51 va_start(args, format); 56 52 #ifdef __XENO__ 57 if(rt_task_self()!=NULL) 58 { 59 rt_vfprintf(stderr,format, args); 60 } 61 else 53 if (rt_task_self() != NULL) { 54 rt_vfprintf(stderr, format, args); 55 } else 62 56 #endif 63 64 vfprintf(stderr,format, args);65 57 { 58 vfprintf(stderr, format, args); 59 } 66 60 67 va_end(args);61 va_end(args); 68 62 } 69 63 70 Object::Object(const Object * parent,string name,string type)71 { 72 pimpl_=new Object_impl(this,parent,name,type);73 if(parent!=NULL)parent->pimpl_->AddChild(this);64 Object::Object(const Object *parent, string name, string type) { 65 pimpl_ = new Object_impl(this, parent, name, type); 66 if (parent != NULL) 67 parent->pimpl_->AddChild(this); 74 68 } 75 69 76 Object::~Object() 77 { 78 if(pimpl_->parent!=NULL)pimpl_->parent->pimpl_->RemoveChild(this);79 70 Object::~Object() { 71 if (pimpl_->parent != NULL) 72 pimpl_->parent->pimpl_->RemoveChild(this); 73 delete pimpl_; 80 74 } 81 75 82 string Object::ObjectName(void) const 83 { 84 return pimpl_->name; 76 string Object::ObjectName(void) const { return pimpl_->name; } 77 78 string Object::ObjectType(void) const { return pimpl_->type; } 79 80 const Object *Object::Parent(void) const { return pimpl_->parent; } 81 82 vector<const Object *> *Object::TypeChilds(void) const { 83 return &(pimpl_->type_childs); 85 84 } 86 85 87 string Object::ObjectType(void) const 88 { 89 return pimpl_->type; 86 vector<const Object *> *Object::Childs(void) const { return &(pimpl_->childs); } 87 88 void Object::ColorPrintf(color_t color, const char *function, int line, 89 const char *format, va_list *args) const { 90 #ifdef __XENO__ 91 if (rt_task_self() != NULL) { 92 rt_fprintf(stderr, "\033[%dm", color); 93 if (line) { 94 rt_fprintf(stderr, "%s - line %d, %s: ", function, line, 95 pimpl_->name.c_str()); 96 } else { 97 rt_fprintf(stderr, "%s, %s: ", function, pimpl_->name.c_str()); 98 } 99 rt_vfprintf(stderr, format, *args); 100 rt_fprintf(stderr, "\033[%dm", color_t::Auto); 101 } else 102 #endif 103 { 104 fprintf(stderr, "\033[%dm", color); 105 if (line) { 106 fprintf(stderr, "%s - line %d, %s: ", function, line, 107 pimpl_->name.c_str()); 108 } else { 109 fprintf(stderr, "%s, %s: ", function, pimpl_->name.c_str()); 110 } 111 vfprintf(stderr, format, *args); 112 fprintf(stderr, "\033[%dm", color_t::Auto); 113 } 90 114 } 91 115 92 const Object* Object::Parent(void) const 93 { 94 return pimpl_->parent; 95 } 96 97 vector<const Object*>* Object::TypeChilds(void) const 98 { 99 return &(pimpl_->type_childs); 100 } 101 102 vector<const Object*>* Object::Childs(void) const 103 { 104 return &(pimpl_->childs); 105 } 106 107 void Object::ColorPrintf(color_t color, const char *function, int line, const char *format,va_list *args) const { 108 #ifdef __XENO__ 109 if(rt_task_self()!=NULL) 110 { 111 rt_fprintf(stderr,"\033[%dm", color); 112 if (line) { 113 rt_fprintf(stderr,"%s - line %d, %s: ", function, line, pimpl_->name.c_str()); 114 } else { 115 rt_fprintf(stderr,"%s, %s: ", function, pimpl_->name.c_str()); 116 } 117 rt_vfprintf(stderr,format, *args); 118 rt_fprintf(stderr,"\033[%dm", color_t::Auto); 119 } 120 else 121 #endif 122 { 123 fprintf(stderr,"\033[%dm", color); 124 if (line) { 125 fprintf(stderr,"%s - line %d, %s: ", function, line, pimpl_->name.c_str()); 126 } else { 127 fprintf(stderr,"%s, %s: ", function, pimpl_->name.c_str()); 128 } 129 vfprintf(stderr,format, *args); 130 fprintf(stderr,"\033[%dm", color_t::Auto); 131 } 132 } 133 134 void Object::Information(const char *function, int line, const char *format, ...) const { 135 va_list args; 136 va_start(args, format); 137 ColorPrintf(color_t::Green, function, line, format, &args); 138 va_end (args); 116 void Object::Information(const char *function, int line, const char *format, 117 ...) const { 118 va_list args; 119 va_start(args, format); 120 ColorPrintf(color_t::Green, function, line, format, &args); 121 va_end(args); 139 122 } 140 123 141 124 void Object::Warning(const char *function, const char *format, ...) const { 142 143 144 145 va_end(args);125 va_list args; 126 va_start(args, format); 127 ColorPrintf(color_t::Orange, function, 0, format, &args); 128 va_end(args); 146 129 } 147 130 148 131 void Object::Error(const char *function, const char *format, ...) const { 149 150 151 152 va_end(args);132 va_list args; 133 va_start(args, format); 134 ColorPrintf(color_t::Red, function, 0, format, &args); 135 va_end(args); 153 136 154 pimpl_->error_occured=true;137 pimpl_->error_occured = true; 155 138 } 156 139 157 bool Object::ErrorOccured(bool recursive) const 158 { 159 return pimpl_->ErrorOccured(recursive); 140 bool Object::ErrorOccured(bool recursive) const { 141 return pimpl_->ErrorOccured(recursive); 160 142 } 161 143
Note:
See TracChangeset
for help on using the changeset viewer.