Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

object.cc

Go to the documentation of this file.
00001 #include "object.hh"
00002 #include "world.hh"
00003 #include <iostream>
00004 
00005 namespace anoid {
00006     namespace base {
00007 
00008         using namespace std;
00009         using namespace config;
00010 
00011         Object *Object::add(Object *o) {
00012             if ((o->parent == NULL) && (o->world == NULL)) {
00013                 o->world = world;
00014                 o->parent = this;
00015                 if (o->ID == 0)
00016                     o->ID = world->getFreshID();
00017                 children.push_back(o);
00018             } // else error!
00019             return o;
00020         }
00021 
00022         Object::Object(int i): ID(i), parent(NULL), world(NULL) {
00023         }
00024 
00025         void Object::init(Configuration &c) {
00026             list<Configuration *> children = c.getChildren();
00027             while (!children.empty()) {
00028                 Configuration *config = children.back();
00029                 children.pop_back();
00030                 Object *o = world->loadObject(config->getName());
00031                 if (o) {
00032                     add(o);
00033                     o->init(*config);
00034                 }
00035 
00036                 delete config;
00037             }
00038         }
00039 
00040         void Object::update() {
00041             vector<Object*>::iterator i;
00042             for (i = children.begin(); i != children.end(); ++i)
00043                 (*i)->update();
00044         }
00045 
00046         void Object::redraw() {
00047             vector<Object*>::iterator i;
00048             for (i = children.begin(); i != children.end(); ++i)
00049                 (*i)->redraw();
00050         }
00051 
00052         void Object::receive(Message *m) {
00053             vector<Object*>::iterator i;
00054             for (i = children.begin(); i != children.end(); ++i)
00055                 (*i)->receive(m);
00056         }
00057 
00058         void Object::listen(const string &m) {
00059             getWorld()->listen(this, m);
00060         }
00061 
00062     };
00063 };

Anoid NG © Michael Westergaard, Martin Stig Stissing, Ronni Michael Laursen, and Kristian Bisgaard Lassen