source: flair-src/trunk/lib/FlairCore/src/Object_impl.cpp @ 2

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

flaircore

File size: 2.5 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:    classe pour qobject
14//
15//
16/*********************************************************************/
17
18#include "Object.h"
19#include "Object_impl.h"
20
21using std::string;
22using std::vector;
23using namespace flair::core;
24
25Object_impl::Object_impl(const Object* self,const Object* parent,string name,string type)
26{
27    //Printf("Object %s\n",name.c_str());
28    this->self=self;
29    this->parent=parent;
30    this->name=name;
31    this->type=type;
32    error_occured=false;
33
34    if(parent!=NULL)
35    {
36        if(name=="") this->name=parent->ObjectName();
37    }
38}
39
40Object_impl::~Object_impl()
41{
42    //Printf("destruction Object %s %s\n",name.c_str(),type.c_str());
43
44    while(childs.size()!=0)
45    {
46        //Printf("child %i %s %s\n",childs.size(),childs.front()->ObjectName().c_str(),childs.front()->ObjectType().c_str());
47        //if(childs.front()!=NULL)
48        delete childs.front();
49    }
50
51    if(type_childs.size()!=0)
52    {
53        type_childs.clear();
54        self->Warn("type_childs not cleared\n");
55    }
56
57    //Printf("destruction Object %s %s ok\n",name.c_str(),type.c_str());
58}
59
60void Object_impl::AddChild(const Object* child)
61{
62    childs.push_back(child);
63//self->Printf("added Object %s %s (%s %s)\n",child->ObjectName().c_str(),child->ObjectType().c_str(),name.c_str(),type.c_str());
64    if(child->ObjectType()==type) type_childs.push_back(child);
65}
66
67void Object_impl::RemoveChild(const Object* child)
68{
69    //self->Printf("removed Object %s %s (%s %s)\n",child->ObjectName().c_str(),child->ObjectType().c_str(),name.c_str(),type.c_str());
70
71    for(vector<const Object*>::iterator it=childs.begin() ; it < childs.end(); it++ )
72    {
73        if(*it==child)
74        {
75            childs.erase (it);
76            break;
77        }
78    }
79
80    for(vector<const Object*>::iterator it=type_childs.begin() ; it < type_childs.end(); it++ )
81    {
82        if(*it==child)
83        {
84            type_childs.erase (it);
85            break;
86        }
87    }
88}
89
90bool Object_impl::ErrorOccured(bool recursive)
91{
92    if(recursive==true)
93    {
94        for(size_t i=0;i<childs.size();i++)
95        {
96            if(childs[i]->ErrorOccured(true)==true)
97            {
98                return true;
99            }
100        }
101    }
102    return error_occured;
103}
Note: See TracBrowser for help on using the repository browser.