//------------------------------------------------------------------------------ // addComponent() -- Add a new component to our list of components //------------------------------------------------------------------------------ bool Component::addComponent(Pair* const p) { PairStream* subcomponents = getComponents(); processComponents(subcomponents, typeid(Component), p); if (subcomponents != nullptr) subcomponents->unref(); return true; }
void IoDevice::copyData(const IoDevice& org, const bool cc) { BaseClass::copyData(org); if (cc) initData(); // clear our old lists of adapters and devices setSlotAdapters(nullptr); setSlotDevices(nullptr); // --- // copy the list of I/O adapters // --- if (org.adapters != nullptr) { PairStream* copy = static_cast<PairStream*>(org.adapters->clone()); setSlotAdapters(copy); copy->unref(); } // --- // copy the list of I/O devices // --- if (org.devices != nullptr) { PairStream* copy = static_cast<PairStream*>(org.devices->clone()); setSlotDevices(copy); copy->unref(); } }
//------------------------------------------------------------------------------ // updateData() -- Update non-time critical (background) stuff here //------------------------------------------------------------------------------ void Component::updateData(const LCreal dt) { // Update all my children PairStream* subcomponents = getComponents(); if (subcomponents != 0) { if (selection != 0) { // When we've selected only one if (selected != 0) selected->updateData(dt); } else { // When we should update them all List::Item* item = subcomponents->getFirstItem(); while (item != 0) { Pair* pair = (Pair*)(item->getValue()); Component* obj = (Component*)( pair->object() ); if (obj != 0) obj->updateData(dt); item = item->getNext(); } } subcomponents->unref(); subcomponents = 0; } // Update our log file if (elog0 != 0) { elog0->updateData(dt); } }
//------------------------------------------------------------------------------ // reset() -- Reset parameters //------------------------------------------------------------------------------ void Component::reset() { PairStream* subcomponents = getComponents(); if (subcomponents != 0) { if (selection != 0) { // When we've selected only one if (selected != 0) selected->reset(); } else { // When we should reset them all List::Item* item = subcomponents->getFirstItem(); while (item != 0) { Pair* pair = (Pair*)(item->getValue()); Component* obj = (Component*)( pair->object() ); if (obj != 0) obj->reset(); item = item->getNext(); } } subcomponents->unref(); subcomponents = 0; } // Reset the log file if (elog0 != 0) { elog0->reset(); } }
// setSlotComponent() -- Sets a single component bool Component::setSlotComponent(Component* const single) { // When a only one component ... make it a PairStream PairStream* tmp = new PairStream(); tmp->put( new Pair("1", single) ); // Process the new components list and swap processComponents(tmp, typeid(Component)); tmp->unref(); return true; }
//------------------------------------------------------------------------------ // copyData() -- copy member data //------------------------------------------------------------------------------ void IoHandler::copyData(const IoHandler& org, const bool cc) { BaseClass::copyData(org); if (cc) initData(); // clear the I/O buffers and list of devices setSlotIoData(nullptr); setSlotDevices(nullptr); // --- // copy the I/O buffers // --- if (org.inData != nullptr && org.inData == org.outData) { // Common input/output buffer IoData* copy = static_cast<IoData*>(org.inData->clone()); setSlotIoData(copy); copy->unref(); } else { // Separate input/output buffers if (org.inData != nullptr) { IoData* copy = static_cast<IoData*>(org.inData->clone()); setSlotInputData(copy); copy->unref(); } if (org.outData != nullptr) { IoData* copy = static_cast<IoData*>(org.outData->clone()); setSlotOutputData(copy); copy->unref(); } } // --- // copy the list of I/O devices // --- if (org.devices != nullptr) { PairStream* copy = static_cast<PairStream*>(org.devices->clone()); setSlotDevices(copy); copy->unref(); } netInitialized = false; netInitFailed = false; rate = 50; pri = 0.0; if (thread != nullptr) { thread->terminate(); thread = nullptr; } }
Pair* Component::findByIndex(const int slotindex) { Pair* p {}; PairStream* subcomponents = getComponents(); if (subcomponents != nullptr) { p = subcomponents->getPosition(slotindex); subcomponents->unref(); subcomponents = nullptr; } return p; }
bool StateMachine::setSlotStateMachines(const PairStream* const msg) { // First remove the old list; and make sure we tell the old stMachList // that we're no longer their container. if (stMachList != nullptr) { List::Item* item = stMachList->getFirstItem(); while (item != nullptr) { Pair* p = static_cast<Pair*>(item->getValue()); Component* q = static_cast<Component*>(p->object()); q->container(nullptr); item = item->getNext(); } stMachList = nullptr; } // Build a new list containing only StateMachine class (or derived) objects if (msg != nullptr) { PairStream* newList = new PairStream(); // For each object in the list; if it's a StateMachine (or derived from) then // clone the object and add it to the new list. const List::Item* item = msg->getFirstItem(); while (item != nullptr) { const Pair* p = static_cast<const Pair*>(item->getValue()); const StateMachine* q = dynamic_cast<const StateMachine*>(p->object()); if (q != nullptr) { Pair* cp = static_cast<Pair*>(p->clone()); StateMachine* cq = static_cast<StateMachine*>(cp->object()); cq->container(this); newList->put(cp); } else { std::cerr << "StateMachine::setSlotStateMachines(): " << *p->slot() << " is not a StateMachine!" << std::endl; } item = item->getNext(); } // Set the pointer to the new stMach list stMachList = newList; } return true; }
//------------------------------------------------------------------------------ // shutdownNotification() -- Default shutdown //------------------------------------------------------------------------------ bool Component::shutdownNotification() { // Tell all of our components PairStream* subcomponents = getComponents(); if (subcomponents != nullptr) { List::Item* item = subcomponents->getFirstItem(); while (item != nullptr) { const auto pair = static_cast<Pair*>(item->getValue()); const auto p = static_cast<Component*>(pair->object()); p->event(SHUTDOWN_EVENT); item = item->getNext(); } subcomponents->unref(); subcomponents = nullptr; } shutdown = true; return shutdown; }
//------------------------------------------------------------------------------ // shutdownNotification() -- Default shutdown //------------------------------------------------------------------------------ bool Component::shutdownNotification() { // Tell all of our components PairStream* subcomponents = getComponents(); if (subcomponents != 0) { List::Item* item = subcomponents->getFirstItem(); while (item != 0) { Pair* pair = (Pair*)(item->getValue()); Component* p = (Component*) pair->object(); p->event(SHUTDOWN_EVENT); item = item->getNext(); } subcomponents->unref(); subcomponents = 0; } shutdown = true; return shutdown; }
//------------------------------------------------------------------------------ // reset() -- Reset parameters //------------------------------------------------------------------------------ void Component::reset() { PairStream* subcomponents = getComponents(); if (subcomponents != nullptr) { if (selection != nullptr) { // When we've selected only one if (selected != nullptr) selected->reset(); } else { // When we should reset them all List::Item* item = subcomponents->getFirstItem(); while (item != nullptr) { const auto pair = static_cast<Pair*>(item->getValue()); const auto obj = static_cast<Component*>(pair->object()); obj->reset(); item = item->getNext(); } } subcomponents->unref(); subcomponents = nullptr; } }
//------------------------------------------------------------------------------ // updateTC() -- Update time critical stuff here //------------------------------------------------------------------------------ void Component::updateTC(const double dt) { // Update all my children PairStream* subcomponents = getComponents(); if (subcomponents != nullptr) { if (selection != nullptr) { // When we've selected only one if (selected != nullptr) selected->tcFrame(dt); } else { // When we should update them all List::Item* item = subcomponents->getFirstItem(); while (item != nullptr) { const auto pair = static_cast<Pair*>(item->getValue()); const auto obj = static_cast<Component*>( pair->object() ); obj->tcFrame(dt); item = item->getNext(); } } subcomponents->unref(); subcomponents = nullptr; } }
//------------------------------------------------------------------------------ // processComponents() -- process our new components list; // -- Add the components from the input list, 'list', to a new list, 'newList' // make sure they are all of type Component (or derived from it) // tell them that we are their container // -- Add an optional component to the end of the new list // -- Swap our 'components' list with the new list, newList // -- Handle selections. //------------------------------------------------------------------------------ void Component::processComponents( PairStream* const list, const std::type_info& filter, Pair* const add, Component* const remove ) { PairStream* oldList = components.getRefPtr(); // --- // Our dynamic_cast (see below) already filters on the Component class // --- bool skipFilter {}; if (filter == typeid(Component)) { skipFilter = true; } // --- // Create a new list, copy (filter) the component pairs and set their container pointers // --- const auto newList = new PairStream(); if (list != nullptr) { // Add the (filtered) components to the new list and set their container List::Item* item = list->getFirstItem(); while (item != nullptr) { const auto pair = static_cast<Pair*>(item->getValue()); const auto cp = dynamic_cast<Component*>( pair->object() ); if ( cp != nullptr && cp != remove && (skipFilter || cp->isClassType(filter)) ) { newList->put(pair); cp->container(this); } else if ( cp != nullptr && cp == remove ) { cp->container(nullptr); } item = item->getNext(); } } // --- // Add the optional component // --- if (add != nullptr) { const auto cp = dynamic_cast<Component*>( add->object() ); if ( cp != nullptr && (skipFilter || cp->isClassType(filter)) ) { newList->put(add); cp->container(this); } } // --- // Swap lists // --- components = newList; newList->unref(); // --- // Anything selected? // --- if (selection != nullptr) { if (selection->isClassType(typeid(String))) { const auto str = new String(*(static_cast<String*>(selection))); select(str); str->unref(); } else { const auto num = new Integer((static_cast<Number*>(selection))->getInt()); select(num); num->unref(); } } if (oldList != nullptr) { oldList->unref(); } }
//------------------------------------------------------------------------------ // processComponents() -- process our new components list; // -- Add the components from the input list, 'list', to a new list, 'newList' // make sure they are all of type Component (or derived from it) // tell them that we are their container // -- Add an optional component to the end of the new list // -- Swap our 'components' list with the new list, newList // -- Handle selections. //------------------------------------------------------------------------------ void Component::processComponents( PairStream* const list, const std::type_info& filter, Pair* const add, Component* const remove ) { PairStream* oldList = components.getRefPtr(); // --- // Our dynamic_cast (see below) already filters on the Component class // --- bool skipFilter = false; if (&filter == 0) skipFilter = true; else if (filter == typeid(Component)) skipFilter = true; // --- // Create a new list, copy (filter) the component pairs and set their container pointers // --- PairStream* newList = new PairStream(); if (list != 0) { // Add the (filtered) components to the new list and set their container List::Item* item = list->getFirstItem(); while (item != 0) { Pair* pair = (Pair*) item->getValue(); Component* cp = dynamic_cast<Component*>( pair->object() ); if ( cp != 0 && cp != remove && (skipFilter || cp->isClassType(filter)) ) { newList->put(pair); cp->container(this); } else if ( cp != 0 && cp == remove ) { cp->container(0); } item = item->getNext(); } } // --- // Add the optional component // --- if (add != 0) { Component* cp = dynamic_cast<Component*>( add->object() ); if ( cp != 0 && (skipFilter || cp->isClassType(filter)) ) { newList->put(add); cp->container(this); } } // --- // Swap lists // --- components = newList; newList->unref(); // --- // Anything selected? // --- if (selection != 0) { if (selection->isClassType(typeid(String))) { String str(*((String*)selection)); select(&str); } else { Integer num(((Number*)selection)->getInt()); select(&num); } } if (oldList != 0) { oldList->unref(); } }