示例#1
0
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();
   }
}
示例#2
0
//------------------------------------------------------------------------------
// 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;
}
示例#3
0
//------------------------------------------------------------------------------
// 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);
    }
}
示例#4
0
//------------------------------------------------------------------------------
// 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();
    }
}
示例#5
0
// 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;
}
示例#6
0
//------------------------------------------------------------------------------
// 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;
   }
}
示例#7
0
Pair* Component::findByIndex(const int slotindex)
{
   Pair* p {};

   PairStream* subcomponents = getComponents();
   if (subcomponents != nullptr) {
      p = subcomponents->getPosition(slotindex);
      subcomponents->unref();
      subcomponents = nullptr;
   }

   return p;
}
示例#8
0
//------------------------------------------------------------------------------
// 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;
}
示例#9
0
//------------------------------------------------------------------------------
// 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;
}
示例#10
0
//------------------------------------------------------------------------------
// 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;
    }
}
示例#11
0
//------------------------------------------------------------------------------
// 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;
    }
}
示例#12
0
//------------------------------------------------------------------------------
// 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();
   }
}
示例#13
0
//------------------------------------------------------------------------------
// 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();
   }
}