X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Fblockallocator.cpp;h=7dcc15b57acdf268ab6dc92ecf5bad2f91570158;hb=457e55c807755eae456633812ff3f3be888e97d5;hp=acb59aeae808beab4a212b245435bf7f9c181c93;hpb=59bae8acd679127602cf35d22bcd37e316a5a056;p=r2c2.git diff --git a/source/libr2c2/blockallocator.cpp b/source/libr2c2/blockallocator.cpp index acb59ae..7dcc15b 100644 --- a/source/libr2c2/blockallocator.cpp +++ b/source/libr2c2/blockallocator.cpp @@ -15,6 +15,16 @@ using namespace Msp; namespace R2C2 { +struct BlockAllocator::BlockMatch +{ + const Block █ + + BlockMatch(const Block &b): block(b) { } + + bool operator()(const BlockIter &bi) const { return &*bi==█ } +}; + + BlockAllocator::BlockAllocator(Train &t): train(t), cur_blocks_end(blocks.end()), @@ -26,7 +36,7 @@ BlockAllocator::BlockAllocator(Train &t): layout.signal_block_reserved.connect(sigc::mem_fun(this, &BlockAllocator::block_reserved)); layout.signal_sensor_state_changed.connect(sigc::mem_fun(this, &BlockAllocator::sensor_state_changed)); - const set &tracks = layout.get_tracks(); + const set &tracks = layout.get_all(); for(set::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) if((*i)->get_turnout_id()) (*i)->signal_path_changed.connect(sigc::hide(sigc::bind(sigc::mem_fun(this, &BlockAllocator::turnout_path_changed), sigc::ref(**i)))); @@ -82,7 +92,7 @@ const BlockIter &BlockAllocator::last_current() const const BlockIter &BlockAllocator::iter_for(const Block &block) const { - BlockList::const_iterator i = find_block(blocks.begin(), blocks.end(), block); + BlockList::const_iterator i = find_if(blocks.begin(), blocks.end(), IterBlockMatch(block)); if(i==blocks.end()) throw key_error(&block); return *i; @@ -90,19 +100,12 @@ const BlockIter &BlockAllocator::iter_for(const Block &block) const bool BlockAllocator::has_block(const Block &block) const { - return find_block(blocks.begin(), blocks.end(), block)!=blocks.end(); + return find_if(blocks.begin(), blocks.end(), IterBlockMatch(block))!=blocks.end(); } bool BlockAllocator::is_block_current(const Block &block) const { - return find_block(blocks.begin(), cur_blocks_end, block)!=cur_blocks_end; -} - -BlockAllocator::BlockList::const_iterator BlockAllocator::find_block(const BlockList::const_iterator &begin, const BlockList::const_iterator &end, const Block &block) const -{ - BlockList::const_iterator i; - for(i=begin; (i!=end && &**i!=&block); ++i) ; - return i; + return find_if(blocks.begin(), cur_blocks_end, IterBlockMatch(block))!=cur_blocks_end; } void BlockAllocator::reserve_more()