Changeset 15 in flair-src for trunk/lib/FlairCore/src/Object.cpp


Ignore:
Timestamp:
04/08/16 15:40:57 (8 years ago)
Author:
Bayard Gildas
Message:

sources reformatted with flair-format-dir script

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairCore/src/Object.cpp

    r2 r15  
    3333using std::vector;
    3434
    35 namespace flair
    36 {
    37 namespace core
    38 {
     35namespace flair {
     36namespace core {
    3937
    40 Time GetTime(void)
    41 {
     38Time GetTime(void) {
    4239#ifdef __XENO__
    43     return rt_timer_read();
     40  return rt_timer_read();
    4441#else
    45     struct timeval t;
    46     gettimeofday(&t, NULL);
    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;
    4845
    4946#endif
    5047}
    5148
    52 void Printf(const char *format, ...)
    53 {
    54     va_list args;
    55     va_start(args, format);
     49void Printf(const char *format, ...) {
     50  va_list args;
     51  va_start(args, format);
    5652#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
    6256#endif
    63     {
    64         vfprintf(stderr,format, args);
    65     }
     57  {
     58    vfprintf(stderr, format, args);
     59  }
    6660
    67     va_end (args);
     61  va_end(args);
    6862}
    6963
    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);
     64Object::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);
    7468}
    7569
    76 Object::~Object()
    77 {
    78     if(pimpl_->parent!=NULL) pimpl_->parent->pimpl_->RemoveChild(this);
    79     delete pimpl_;
     70Object::~Object() {
     71  if (pimpl_->parent != NULL)
     72    pimpl_->parent->pimpl_->RemoveChild(this);
     73  delete pimpl_;
    8074}
    8175
    82 string Object::ObjectName(void) const
    83 {
    84     return pimpl_->name;
     76string Object::ObjectName(void) const { return pimpl_->name; }
     77
     78string Object::ObjectType(void) const { return pimpl_->type; }
     79
     80const Object *Object::Parent(void) const { return pimpl_->parent; }
     81
     82vector<const Object *> *Object::TypeChilds(void) const {
     83  return &(pimpl_->type_childs);
    8584}
    8685
    87 string Object::ObjectType(void) const
    88 {
    89     return pimpl_->type;
     86vector<const Object *> *Object::Childs(void) const { return &(pimpl_->childs); }
     87
     88void 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  }
    90114}
    91115
    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);
     116void 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);
    139122}
    140123
    141124void Object::Warning(const char *function, const char *format, ...) const {
    142     va_list args;
    143     va_start(args, format);
    144     ColorPrintf(color_t::Orange, function, 0, format, &args);
    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);
    146129}
    147130
    148131void Object::Error(const char *function, const char *format, ...) const {
    149     va_list args;
    150     va_start(args, format);
    151     ColorPrintf(color_t::Red, function, 0, format, &args);
    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);
    153136
    154     pimpl_->error_occured=true;
     137  pimpl_->error_occured = true;
    155138}
    156139
    157 bool Object::ErrorOccured(bool recursive) const
    158 {
    159     return pimpl_->ErrorOccured(recursive);
     140bool Object::ErrorOccured(bool recursive) const {
     141  return pimpl_->ErrorOccured(recursive);
    160142}
    161143
Note: See TracChangeset for help on using the changeset viewer.