Changeset 2063 for code/branches/objecthierarchy/src/core/BaseObject.cc
- Timestamp:
- Oct 29, 2008, 6:39:31 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/core/BaseObject.cc
r2019 r2063 94 94 95 95 XMLPortObjectTemplate(BaseObject, Template, "templates", addTemplate, getTemplate, xmlelement, mode, Template*); 96 97 Element* events = xmlelement.FirstChildElement("events", false); 98 99 if (events) 100 { 101 std::list<std::string> eventnames; 102 103 if (mode == XMLPort::LoadObject) 104 { 105 for (ticpp::Iterator<ticpp::Element> child = events->FirstChildElement(false); child != child.end(); child++) 106 eventnames.push_back(child->Value()); 107 } 108 else if (mode == XMLPort::SaveObject) 109 { 110 for (std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->getIdentifier()->getXMLPortEventMapBegin(); it != this->getIdentifier()->getXMLPortEventMapEnd(); ++it) 111 eventnames.push_back(it->first); 112 } 113 114 for (std::list<std::string>::iterator it = eventnames.begin(); it != eventnames.end(); ++it) 115 { 116 std::string sectionname = (*it); 117 ExecutorMember<BaseObject>* loadexecutor = createExecutor(createFunctor(&BaseObject::addEvent), std::string( "BaseObject" ) + "::" + "addEvent"); 118 ExecutorMember<BaseObject>* saveexecutor = createExecutor(createFunctor(&BaseObject::getEvent), std::string( "BaseObject" ) + "::" + "getEvent"); 119 loadexecutor->setDefaultValue(1, sectionname); 120 121 XMLPortClassObjectContainer<BaseObject, BaseObject>* container = 0; 122 container = (XMLPortClassObjectContainer<BaseObject, BaseObject>*)(this->getIdentifier()->getXMLPortEventContainer(sectionname)); 123 if (!container) 124 { 125 container = new XMLPortClassObjectContainer<BaseObject, BaseObject>(sectionname, this->getIdentifier(), loadexecutor, saveexecutor, false, true); 126 this->getIdentifier()->addXMLPortEventContainer(sectionname, container); 127 } 128 container->port(this, *events, mode); 129 } 130 } 96 131 } 97 132 … … 146 181 return 0; 147 182 } 183 184 void BaseObject::addEvent(BaseObject* event, const std::string& sectionname) 185 { 186 this->eventListeners_.insert(std::pair<std::string, BaseObject*>(sectionname, event)); 187 } 188 189 BaseObject* BaseObject::getEvent(unsigned int index) const 190 { 191 unsigned int i = 0; 192 for (std::set<std::pair<std::string, BaseObject*> >::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it) 193 { 194 if (i == index) 195 return (*it).second; 196 ++i; 197 } 198 return 0; 199 } 200 201 void BaseObject::addEventContainer(const std::string& sectionname, EventContainer* container) 202 { 203 std::map<std::string, EventContainer*>::const_iterator it = this->eventContainers_.find(sectionname); 204 if (it != this->eventContainers_.end()) 205 { 206 COUT(2) << "Warning: Overwriting EventContainer in class " << this->getIdentifier()->getName() << "." << std::endl; 207 delete (it->second); 208 } 209 210 this->eventContainers_[sectionname] = container; 211 } 212 213 EventContainer* BaseObject::getEventContainer(const std::string& sectionname) const 214 { 215 std::map<std::string, EventContainer*>::const_iterator it = this->eventContainers_.begin(); 216 if (it != this->eventContainers_.end()) 217 return ((*it).second); 218 else 219 return 0; 220 } 221 222 void BaseObject::fireEvent() 223 { 224 this->fireEvent(true); 225 this->fireEvent(false); 226 } 227 228 void BaseObject::fireEvent(bool activate) 229 { 230 Event event(activate, this); 231 232 for (std::set<std::pair<std::string, BaseObject*> >::iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it) 233 { 234 event.sectionname_ = (*it).first; 235 (*it).second->processEvent(event); 236 } 237 } 238 239 void BaseObject::processEvent(Event& event) 240 { 241 SetEvent(BaseObject, "activity", setActive, event); 242 SetEvent(BaseObject, "visibility", setVisible, event); 243 } 148 244 }
Note: See TracChangeset
for help on using the changeset viewer.