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


C++ Strategy::getInstanceName方法代码示例

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


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

示例1: clearStrategyInfo

void
StrategyChoice::changeStrategy(Entry& entry, Strategy& oldStrategy, Strategy& newStrategy)
{
  const Name& oldInstanceName = oldStrategy.getInstanceName();
  const Name& newInstanceName = newStrategy.getInstanceName();
  if (Strategy::areSameType(oldInstanceName, newInstanceName)) {
    // same Strategy subclass type: no need to clear StrategyInfo
    NFD_LOG_INFO("changeStrategy(" << entry.getPrefix() << ") "
                 << oldInstanceName << " -> " << newInstanceName << " same-type");
    return;
  }

  NFD_LOG_INFO("changeStrategy(" << entry.getPrefix() << ") "
               << oldInstanceName << " -> " << newInstanceName);

  // reset StrategyInfo on a portion of NameTree,
  // where entry's effective strategy is covered by the changing StrategyChoice entry
  const name_tree::Entry* rootNte = m_nameTree.getEntry(entry);
  BOOST_ASSERT(rootNte != nullptr);
  const auto& ntChanged = m_nameTree.partialEnumerate(entry.getPrefix(),
    [&rootNte] (const name_tree::Entry& nte) -> std::pair<bool, bool> {
      if (&nte == rootNte) {
        return {true, true};
      }
      if (nte.getStrategyChoiceEntry() != nullptr) {
        return {false, false};
      }
      return {true, true};
    });
  for (const auto& nte : ntChanged) {
    clearStrategyInfo(nte);
  }
}
开发者ID:named-data,项目名称:NFD,代码行数:33,代码来源:strategy-choice.cpp

示例2: InsertResult

StrategyChoice::InsertResult
StrategyChoice::insert(const Name& prefix, const Name& strategyName)
{
  if (prefix.size() > NameTree::getMaxDepth()) {
    return InsertResult::DEPTH_EXCEEDED;
  }

  unique_ptr<Strategy> strategy;
  try {
    strategy = Strategy::create(strategyName, m_forwarder);
  }
  catch (const std::invalid_argument& e) {
    NFD_LOG_ERROR("insert(" << prefix << "," << strategyName << ") cannot create strategy: " << e.what());
    return InsertResult(InsertResult::EXCEPTION, e.what());
  }

  if (strategy == nullptr) {
    NFD_LOG_ERROR("insert(" << prefix << "," << strategyName << ") strategy not registered");
    return InsertResult::NOT_REGISTERED;
  }

  name_tree::Entry& nte = m_nameTree.lookup(prefix);
  Entry* entry = nte.getStrategyChoiceEntry();
  Strategy* oldStrategy = nullptr;
  if (entry != nullptr) {
    if (entry->getStrategyInstanceName() == strategy->getInstanceName()) {
      NFD_LOG_TRACE("insert(" << prefix << ") not changing " << strategy->getInstanceName());
      return InsertResult::OK;
    }
    oldStrategy = &entry->getStrategy();
    NFD_LOG_TRACE("insert(" << prefix << ") changing from " << oldStrategy->getInstanceName() <<
                  " to " << strategy->getInstanceName());
  }
  else {
    oldStrategy = &this->findEffectiveStrategy(prefix);
    auto newEntry = make_unique<Entry>(prefix);
    entry = newEntry.get();
    nte.setStrategyChoiceEntry(std::move(newEntry));
    ++m_nItems;
    NFD_LOG_TRACE("insert(" << prefix << ") new entry " << strategy->getInstanceName());
  }

  this->changeStrategy(*entry, *oldStrategy, *strategy);
  entry->setStrategy(std::move(strategy));
  return InsertResult::OK;
}
开发者ID:named-data,项目名称:NFD,代码行数:46,代码来源:strategy-choice.cpp


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