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


C++ Strategy类代码示例

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


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

示例1: apply

    static inline void apply(Point const& point,
                             iterator_type first,
                             iterator_type last,
                             Strategy const& strategy,
                             iterator_type& it_min1,
                             iterator_type& it_min2,
                             Distance& dist_min)
    {
        BOOST_ASSERT( first != last );

        base_type::apply(point, first, last, strategy,
                         it_min1, it_min2, dist_min);

        iterator_type it_back = --last;
        Distance const zero = Distance(0);
        Distance dist = strategy.apply(point, *it_back, *first);

        if (geometry::math::equals(dist, zero))
        {
            dist_min = zero;
            it_min1 = it_back;
            it_min2 = first;
        }
        else if (dist < dist_min)
        {
            dist_min = dist;
            it_min1 = it_back;
            it_min2 = first;
        }
    }    
开发者ID:Bloodyaugust,项目名称:SugarLabCPP,代码行数:30,代码来源:point_to_range.hpp

示例2: removeStrategy

void Engine::addStrategy(string name)
{
    removeStrategy(name);

    Strategy* strategy = aiObjectContext->GetStrategy(name);
    if (strategy)
    {
        set<string> siblings = aiObjectContext->GetSiblingStrategy(name);
        for (set<string>::iterator i = siblings.begin(); i != siblings.end(); i++)
            removeStrategy(*i);

        LogAction("S:+%s", strategy->getName().c_str());
        strategies[strategy->getName()] = strategy;
    }
    Init();
}
开发者ID:beyourself,项目名称:LordPsyanBots,代码行数:16,代码来源:Engine.cpp

示例3: apply

    static inline void apply(Ring const& ring,
                             PointTransformer const& transformer,
                             Strategy const& strategy,
                             typename Strategy::state_type& state)
    {
        geofeatures_boost::ignore_unused(strategy);

        typedef typename geometry::point_type<Ring const>::type point_type;
        typedef typename closeable_view<Ring const, Closure>::type view_type;

        typedef typename geofeatures_boost::range_iterator<view_type const>::type iterator_type;

        view_type view(ring);
        iterator_type it = geofeatures_boost::begin(view);
        iterator_type end = geofeatures_boost::end(view);

        typename PointTransformer::result_type
            previous_pt = transformer.apply(*it);

        for ( ++it ; it != end ; ++it)
        {
            typename PointTransformer::result_type
                pt = transformer.apply(*it);

            strategy.apply(static_cast<point_type const&>(previous_pt),
                           static_cast<point_type const&>(pt),
                           state);
            
            previous_pt = pt;
        }
    }
开发者ID:Niko-r,项目名称:geofeatures,代码行数:31,代码来源:centroid.hpp

示例4: apply

    static inline return_type apply(
            Range const& range, Strategy const& strategy)
    {
        boost::ignore_unused_variable_warning(strategy);
        typedef typename closeable_view<Range const, Closure>::type view_type;
        typedef typename boost::range_iterator
            <
                view_type const
            >::type iterator_type;

        return_type sum = return_type();
        view_type view(range);
        iterator_type it = boost::begin(view), end = boost::end(view);
        if(it != end)
        {
            for(iterator_type previous = it++;
                    it != end;
                    ++previous, ++it)
            {
                // Add point-point distance using the return type belonging
                // to strategy
                sum += strategy.apply(*previous, *it);
            }
        }

        return sum;
    }
开发者ID:AlexMioMio,项目名称:boost,代码行数:27,代码来源:length.hpp

示例5: apply

    static inline
    typename distance_result
        <
            typename point_type<Point>::type,
            typename point_type<Range>::type,
            Strategy
        >::type
    apply(Point const& pnt, Range const& rng, Strategy const& strategy)
    {
        typedef typename distance_result
            <
                typename point_type<Point>::type,
                typename point_type<Range>::type,
                Strategy
            >::type result_type;
        typedef typename boost::range_size<Range>::type size_type;

        size_type const n = boost::size(rng);
        result_type dis_min = 0;
        bool is_dis_min_set = false;

        for (size_type i = 0 ; i < n ; i++)
        {
            result_type dis_temp = strategy.apply(pnt, range::at(rng, i));
            if (! is_dis_min_set || dis_temp < dis_min)
            {
                dis_min = dis_temp;
                is_dis_min_set = true;
            }
        }
        return dis_min;
    }
开发者ID:boostorg,项目名称:geometry,代码行数:32,代码来源:discrete_hausdorff_distance.hpp

示例6: init

    void Request::process( int attempt ) {
        init();
        int op = _m.operation();
        verify( op > dbMsg );

        int msgId = (int)(_m.header()->id);

        Timer t;
        LOG(3) << "Request::process begin ns: " << getns()
               << " msg id: " << msgId
               << " op: " << op
               << " attempt: " << attempt
               << endl;

        Strategy * s = SHARDED;

        _d.markSet();

        bool iscmd = false;
        if ( op == dbKillCursors ) {
            cursorCache.gotKillCursors( _m );
        }
        else if ( op == dbQuery ) {
            iscmd = isCommand();
            if (iscmd) {
                SINGLE->queryOp(*this);
            }
            else {
                s->queryOp( *this );
            }
        }
        else if ( op == dbGetMore ) {
            s->getMore( *this );
        }
        else {
            s->writeOp( op, *this );
        }

        LOG(3) << "Request::process end ns: " << getns()
               << " msg id: " << msgId
               << " op: " << op
               << " attempt: " << attempt
               << " " << t.millis() << "ms"
               << endl;

        globalOpCounters.gotOp( op , iscmd );
    }
开发者ID:10genReviews,项目名称:mongo,代码行数:47,代码来源:request.cpp

示例7: catch

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

示例8: apply

    static inline void apply(Point const& point,
                             iterator_type first,
                             iterator_type last,
                             Strategy const& strategy,
                             iterator_type& it_min1,
                             iterator_type& it_min2,
                             Distance& dist_min)
    {
        BOOST_GEOMETRY_ASSERT( first != last );

        Distance const zero = Distance(0);

        iterator_type it = first;
        iterator_type prev = it++;
        if (it == last)
        {
            it_min1 = it_min2 = first;
            dist_min = strategy.apply(point, *first, *first);
            return;
        }

        // start with first segment distance
        dist_min = strategy.apply(point, *prev, *it);
        iterator_type prev_min_dist = prev;

        // check if other segments are closer
        for (++prev, ++it; it != last; ++prev, ++it)
        {
            Distance dist = strategy.apply(point, *prev, *it);
            if (geometry::math::equals(dist, zero))
            {
                dist_min = zero;
                it_min1 = prev;
                it_min2 = it;
                return;
            }
            else if (dist < dist_min)
            {
                dist_min = dist;
                prev_min_dist = prev;
            }
        }

        it_min1 = it_min2 = prev_min_dist;
        ++it_min2;
    }
开发者ID:ngzHappy,项目名称:cpc2,代码行数:46,代码来源:point_to_range.hpp

示例9: CmiAbort

/// Method invoked upon receipt a message routed through comlib.
void *strategyHandler(void *msg) {
    CmiMsgHeaderExt *conv_header = (CmiMsgHeaderExt *) msg;
    int instid = conv_header->stratid;

#ifndef CMK_OPTIMIZE
    // check that the instid is not zero, meaning a possibly uninitialized value
    if (instid == 0) {
      CmiAbort("Comlib strategy ID is zero, did you forget to initialize a variable?\n");
    }
#endif
    
    // when handling a message always call the lowest level
    Strategy *strat = ConvComlibGetStrategy(instid);
    
    strat->handleMessage(msg);
    return NULL;
}
开发者ID:davidheryanto,项目名称:sc14,代码行数:18,代码来源:convcomlibmanager.C

示例10: block

void SocketMonitor::block( Strategy& strategy, bool poll, double timeout )
{
  while ( m_dropped.size() )
  {
    strategy.onError( *this, m_dropped.front() );
    m_dropped.pop();
    if ( m_dropped.size() == 0 )
      return ;
  }

  fd_set readSet;
  FD_ZERO( &readSet );
  buildSet( m_readSockets, readSet );
  fd_set writeSet;
  FD_ZERO( &writeSet );
  buildSet( m_connectSockets, writeSet );
  buildSet( m_writeSockets, writeSet );
  fd_set exceptSet;
  FD_ZERO( &exceptSet );
  buildSet( m_connectSockets, exceptSet );

  if ( sleepIfEmpty(poll) )
  {
    strategy.onTimeout( *this );
    return;
  }

  int result = select( FD_SETSIZE, &readSet, &writeSet, &exceptSet, getTimeval(poll, timeout) );

  if ( result == 0 )
  {
    strategy.onTimeout( *this );
    return;
  }
  else if ( result > 0 )
  {
    processExceptSet( strategy, exceptSet );
    processWriteSet( strategy, writeSet );
    processReadSet( strategy, readSet );
  }
  else
  {
    strategy.onError( *this );
  }
}
开发者ID:Iron-Bound,项目名称:quickfix,代码行数:45,代码来源:SocketMonitor.cpp

示例11: NFD_LOG_ERROR

bool
StrategyChoice::insert(const Name& prefix, const Name& strategyName)
{
  Strategy* strategy = this->getStrategy(strategyName);
  if (strategy == nullptr) {
    NFD_LOG_ERROR("insert(" << prefix << "," << strategyName << ") strategy not installed");
    return false;
  }

  shared_ptr<name_tree::Entry> nte = m_nameTree.lookup(prefix);
  shared_ptr<Entry> entry = nte->getStrategyChoiceEntry();
  Strategy* oldStrategy = nullptr;
  if (entry != nullptr) {
    if (entry->getStrategy().getName() == strategy->getName()) {
      NFD_LOG_TRACE("insert(" << prefix << ") not changing " << strategy->getName());
      return true;
    }
    oldStrategy = &entry->getStrategy();
    NFD_LOG_TRACE("insert(" << prefix << ") changing from " << oldStrategy->getName() <<
                  " to " << strategy->getName());
  }

  if (entry == nullptr) {
    oldStrategy = &this->findEffectiveStrategy(prefix);
    entry = make_shared<Entry>(prefix);
    nte->setStrategyChoiceEntry(entry);
    ++m_nItems;
    NFD_LOG_TRACE("insert(" << prefix << ") new entry " << strategy->getName());
  }

  this->changeStrategy(*entry, *oldStrategy, *strategy);
  entry->setStrategy(*strategy);
  return true;
}
开发者ID:bombomstory,项目名称:NFD,代码行数:34,代码来源:strategy-choice.cpp

示例12: apply

 static inline typename default_length_result<Segment>::type apply(
         Segment const& segment, Strategy const& strategy)
 {
     typedef typename point_type<Segment>::type point_type;
     point_type p1, p2;
     geometry::detail::assign_point_from_index<0>(segment, p1);
     geometry::detail::assign_point_from_index<1>(segment, p2);
     return strategy.apply(p1, p2);
 }
开发者ID:AndresGalaviz,项目名称:NAO,代码行数:9,代码来源:length.hpp

示例13: apply

        static void apply()
        {
            Strategy *str = 0;
            state_type *st = 0;

            // 4) must implement a static method apply,
            // getting two segment-points
            spoint_type const* sp = 0;
            str->apply(*sp, *sp, *st);

            // 5) must implement a static method result
            //  getting the centroid
            point_type *c = 0;
            bool r = str->result(*st, *c);

            boost::ignore_unused_variable_warning(str);
            boost::ignore_unused_variable_warning(r);
        }
开发者ID:AbhinavJain13,项目名称:turicreate,代码行数:18,代码来源:centroid_concept.hpp

示例14: apply

 static inline typename return_type<Strategy>::type apply(Point const& point,
             Segment const& segment, Strategy const& strategy)
 {
     
     typename point_type<Segment>::type p[2];
     geometry::detail::assign_point_from_index<0>(segment, p[0]);
     geometry::detail::assign_point_from_index<1>(segment, p[1]);
     return strategy.apply(point, p[0], p[1]);
 }
开发者ID:BackupTheBerlios,项目名称:airdc-svn,代码行数:9,代码来源:distance.hpp

示例15: time_compare_s

void time_compare_s(int const n)
{
    boost::timer t;
    P p1, p2;
    bg::assign_values(p1, 1, 1);
    bg::assign_values(p2, 2, 2);
    Strategy strategy;
    typename bg::strategy::distance::services::return_type<Strategy, P, P>::type s = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            bg::set<0>(p2, bg::get<0>(p2) + 0.001);
            s += strategy.apply(p1, p2);
        }
    }
    std::cout << "s: " << s << " t: " << t.elapsed() << std::endl;
}
开发者ID:Adikteev,项目名称:rtbkit-deps,代码行数:18,代码来源:pythagoras.cpp


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