当前位置: 首页>>代码示例>>C++>>正文


C++ PairStream::addTail方法代码示例

本文整理汇总了C++中basic::PairStream::addTail方法的典型用法代码示例。如果您正苦于以下问题:C++ PairStream::addTail方法的具体用法?C++ PairStream::addTail怎么用?C++ PairStream::addTail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在basic::PairStream的用法示例。


在下文中一共展示了PairStream::addTail方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: insertSteerpoint

//------------------------------------------------------------------------------
// insertSteerpoint() -
//------------------------------------------------------------------------------
bool Route::insertSteerpoint(Steerpoint* const newStpt, const int pos)
{
    bool ok = false;
    unsigned int num = getNumberOfSteerpoints();
    // make a new character string
    char numString[10];

    // this tells us the number of the next steerpoint to be created in the slot list
    std::sprintf(numString,"%i",(num+1));

    // now we have the slot name, which is the next number in the steerpoint list
    // now create a new pair, and if we have a component list, add it to it, if
    // not, then create a new component list
    Basic::Pair* p = new Basic::Pair(numString, newStpt);
    if (p != nullptr) {

        // We're its container
        newStpt->container(this);

        // Get our steerpoints
        Basic::PairStream* steerpoints = getComponents();

        // now we have to add it to our component list
        if (steerpoints != nullptr && num != 0) {

            // Copy the current steerpoint list
            Basic::PairStream* tempList = new Basic::PairStream();
            {
               Basic::List::Item* item = steerpoints->getFirstItem();
               while (item != nullptr) {
                  Basic::Pair* pair = (Basic::Pair*) item->getValue();
                  tempList->put(pair);
                  item = item->getNext();
               }
            }

            if (pos == -1) {
               tempList->addHead(p);
               ok = true;
            }

            else if (pos == 0 || pos > num) {
               tempList->addTail(p);
               ok = true;
            }

            else if (pos > 0 && pos <= static_cast<int>(num)) {

                // count to our position, then insert it
                int counter = 1;
                Basic::List::Item* item = tempList->getFirstItem();
                while (counter < pos && item != nullptr) {
                    item = item->getNext();
                    counter++;
                }

                // now we should have the reference pair at the 'pos' position
                if (item != nullptr) {
                    Basic::List::Item* newItem = new Basic::List::Item;
                    newItem->value = p;
                    p->ref();
                    // insert 'newItem' just before 'item'
                    ok = tempList->insert(newItem, item);
                }
            }

            // swap our current steerpoint (components) list for this new one
            if (ok) {
               Basic::Component::processComponents(tempList,typeid(Steerpoint));
            }

            tempList->unref();
            tempList = nullptr;

        }

        // if we have no components, we need to start a new component list
        else {
            Basic::Component::processComponents(nullptr, typeid(Steerpoint), p);
            ok = true;
        }

        // Unref the original steerpoint list
        if (steerpoints != nullptr) {
            steerpoints->unref();
            steerpoints = nullptr;
        }

        p->unref();  // Our component list has it now.
    }

    // ---
    // Call directTo() to reset the steerpoint index, or if we were going nowhere
    // then go direct-to steerpoint one.
    // ---
    if (ok) {
       if (to != nullptr) {
//.........这里部分代码省略.........
开发者ID:derekworth,项目名称:afit-swarm-simulation,代码行数:101,代码来源:Route.cpp


注:本文中的basic::PairStream::addTail方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。