From 78bc40c2d1a5fcc5715143bd2326716fbb143730 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 15 Jul 2007 10:47:23 +0000 Subject: [PATCH] Rename Section to Block for a closer match with real railway terminology --- source/engineer/engineer.cpp | 2 +- source/libmarklin/{section.cpp => block.cpp} | 22 +++--- source/libmarklin/{section.h => block.h} | 12 ++-- source/libmarklin/trafficmanager.cpp | 14 ++-- source/libmarklin/trafficmanager.h | 6 +- source/libmarklin/train.cpp | 74 ++++++++++---------- source/libmarklin/train.h | 20 +++--- 7 files changed, 75 insertions(+), 75 deletions(-) rename source/libmarklin/{section.cpp => block.cpp} (85%) rename source/libmarklin/{section.h => block.h} (81%) diff --git a/source/engineer/engineer.cpp b/source/engineer/engineer.cpp index 573ef6f..bb29591 100644 --- a/source/engineer/engineer.cpp +++ b/source/engineer/engineer.cpp @@ -276,7 +276,7 @@ void Engineer::button_press(int x, int y, unsigned btn) { if(placing_train) { - Section *sect=trfc_man->get_section_by_track(track->get_track()); + Block *block=trfc_man->get_block_by_track(&track->get_track()); } else { diff --git a/source/libmarklin/section.cpp b/source/libmarklin/block.cpp similarity index 85% rename from source/libmarklin/section.cpp rename to source/libmarklin/block.cpp index 17a0ce4..f96e295 100644 --- a/source/libmarklin/section.cpp +++ b/source/libmarklin/block.cpp @@ -1,5 +1,5 @@ #include "control.h" -#include "section.h" +#include "block.h" #include "trafficmanager.h" #include "turnout.h" @@ -10,7 +10,7 @@ using namespace std; namespace Marklin { -Section::Section(TrafficManager &tm, Track *start): +Block::Block(TrafficManager &tm, Track *start): trfc_mgr(tm), id(next_id++), sensor_id(0), @@ -60,7 +60,7 @@ Section::Section(TrafficManager &tm, Track *start): } } -const Section::Endpoint *Section::get_endpoint_by_link(const Section *other) const +const Block::Endpoint *Block::get_endpoint_by_link(const Block *other) const { for(EndpointSeq::const_iterator i=endpoints.begin(); i!=endpoints.end(); ++i) if(i->link==other) @@ -69,7 +69,7 @@ const Section::Endpoint *Section::get_endpoint_by_link(const Section *other) con return 0; } -const Section::Endpoint *Section::traverse(const Endpoint *ep) const +const Block::Endpoint *Block::traverse(const Endpoint *ep) const { Track *track=ep->track; const Track::Endpoint *track_ep=ep->track_ep; @@ -101,7 +101,7 @@ const Section::Endpoint *Section::traverse(const Endpoint *ep) const } } -void Section::check_link(Section &other) +void Block::check_link(Block &other) { for(EndpointSeq::iterator i=endpoints.begin(); i!=endpoints.end(); ++i) { @@ -117,7 +117,7 @@ void Section::check_link(Section &other) } } -bool Section::reserve(const Train *t) +bool Block::reserve(const Train *t) { if(!t || !train) { @@ -128,9 +128,9 @@ bool Section::reserve(const Train *t) return false; } -void Section::print_debug() +void Block::print_debug() { - cout<<"Section "<get_sensor_id()) cout<<", sensor="<<(*tracks.begin())->get_sensor_id(); cout<<'\n'; @@ -145,7 +145,7 @@ void Section::print_debug() } } -void Section::find_routes(Track *track, const Track::Endpoint *track_ep, unsigned route, std::set &visited) +void Block::find_routes(Track *track, const Track::Endpoint *track_ep, unsigned route, std::set &visited) { visited.insert(track); @@ -170,10 +170,10 @@ void Section::find_routes(Track *track, const Track::Endpoint *track_ep, unsigne visited.erase(--visited.end()); } -unsigned Section::next_id=1; +unsigned Block::next_id=1; -Section::Endpoint::Endpoint(Track *t, const Track::Endpoint *e): +Block::Endpoint::Endpoint(Track *t, const Track::Endpoint *e): track(t), track_ep(e), link(0), diff --git a/source/libmarklin/section.h b/source/libmarklin/block.h similarity index 81% rename from source/libmarklin/section.h rename to source/libmarklin/block.h index 679466f..df3ed4a 100644 --- a/source/libmarklin/section.h +++ b/source/libmarklin/block.h @@ -10,26 +10,26 @@ namespace Marklin { class Train; class TrafficManager; -class Section +class Block { public: struct Endpoint { Track *track; const Track::Endpoint *track_ep; - Section *link; + Block *link; unsigned routes; Endpoint(Track *, const Track::Endpoint *); }; typedef std::list EndpointSeq; - Section(TrafficManager &, Track *); + Block(TrafficManager &, Track *); unsigned get_sensor_id() const { return sensor_id; } const TrackSet &get_tracks() const { return tracks; } - const Endpoint *get_endpoint_by_link(const Section *) const; + const Endpoint *get_endpoint_by_link(const Block *) const; const Endpoint *traverse(const Endpoint *) const; - void check_link(Section &); + void check_link(Block &); bool reserve(const Train *); void print_debug(); private: @@ -44,7 +44,7 @@ private: static unsigned next_id; }; -typedef std::list
SectionSeq; +typedef std::list BlockSeq; } // namespace Marklin diff --git a/source/libmarklin/trafficmanager.cpp b/source/libmarklin/trafficmanager.cpp index 7a47f14..31e8542 100644 --- a/source/libmarklin/trafficmanager.cpp +++ b/source/libmarklin/trafficmanager.cpp @@ -31,24 +31,24 @@ TrafficManager::TrafficManager(Control &c, Layout &l): } if(used_tracks.count(*i)==0) { - Section *sect=new Section(*this, *i); - sections.push_back(sect); - used_tracks.insert(sect->get_tracks().begin(), sect->get_tracks().end()); + Block *block=new Block(*this, *i); + blocks.push_back(block); + used_tracks.insert(block->get_tracks().begin(), block->get_tracks().end()); } } - for(SectionSeq::iterator i=sections.begin(); i!=sections.end(); ++i) + for(BlockSeq::iterator i=blocks.begin(); i!=blocks.end(); ++i) { - for(SectionSeq::iterator j=i; j!=sections.end(); ++j) + for(BlockSeq::iterator j=i; j!=blocks.end(); ++j) if(j!=i) (*i)->check_link(**j); (*i)->print_debug(); } } -Section *TrafficManager::get_section_by_track(const Track *t) const +Block *TrafficManager::get_block_by_track(const Track *t) const { - for(SectionSeq::const_iterator i=sections.begin(); i!=sections.end(); ++i) + for(BlockSeq::const_iterator i=blocks.begin(); i!=blocks.end(); ++i) { const TrackSet &tracks=(*i)->get_tracks(); if(tracks.count(const_cast(t))) diff --git a/source/libmarklin/trafficmanager.h b/source/libmarklin/trafficmanager.h index 11ecc95..6e210bc 100644 --- a/source/libmarklin/trafficmanager.h +++ b/source/libmarklin/trafficmanager.h @@ -1,7 +1,7 @@ #ifndef LIBMARKLIN_TRAFFICMANAGER_H_ #define LIBMARKLIN_TRAFFICMANAGER_H_ -#include "section.h" +#include "block.h" #include "train.h" namespace Marklin { @@ -15,12 +15,12 @@ class TrafficManager public: TrafficManager(Control &, Layout &); Control &get_control() const { return control; } - Section *get_section_by_track(const Track *) const; + Block *get_block_by_track(const Track *) const; void add_train(Train *); private: Control &control; Layout &layout; - SectionSeq sections; + BlockSeq blocks; TrainSeq trains; void turnout_route_changed(unsigned, Turnout *); diff --git a/source/libmarklin/train.cpp b/source/libmarklin/train.cpp index 73b2823..f69849d 100644 --- a/source/libmarklin/train.cpp +++ b/source/libmarklin/train.cpp @@ -16,40 +16,40 @@ Train::Train(TrafficManager &tm, Locomotive &l): void Train::set_speed(unsigned speed) { target_speed=speed; - if(rsv_sections.empty() && !reserve_more()) + if(rsv_blocks.empty() && !reserve_more()) return; loco.set_speed(speed); } -void Train::place(Section *sect, const Section::Endpoint *entry) +void Train::place(Block *block, const Block::Endpoint *entry) { - for(SectRefSeq::iterator i=rsv_sections.begin(); i!=rsv_sections.end();) + for(BlockRefSeq::iterator i=rsv_blocks.begin(); i!=rsv_blocks.end();) { - i->section->reserve(0); - i=rsv_sections.erase(i); + i->block->reserve(0); + i=rsv_blocks.erase(i); } - for(SectRefSeq::iterator i=cur_sections.begin(); i!=cur_sections.end();) + for(BlockRefSeq::iterator i=cur_blocks.begin(); i!=cur_blocks.end();) { - i->section->reserve(0); - i=cur_sections.erase(i); + i->block->reserve(0); + i=cur_blocks.erase(i); } - if(!sect->reserve(this)) + if(!block->reserve(this)) return; - cur_sections.push_back(SectionRef(sect, entry)); + cur_blocks.push_back(BlockRef(block, entry)); } -bool Train::free_section(Section *sect) +bool Train::free_block(Block *block) { - for(SectRefSeq::iterator i=rsv_sections.begin(); i!=rsv_sections.end(); ++i) - if(i->section==sect) + for(BlockRefSeq::iterator i=rsv_blocks.begin(); i!=rsv_blocks.end(); ++i) + if(i->block==block) { - while(i!=rsv_sections.end()) + while(i!=rsv_blocks.end()) { - i->section->reserve(0); - i=rsv_sections.erase(i); + i->block->reserve(0); + i=rsv_blocks.erase(i); } return true; } @@ -61,28 +61,28 @@ void Train::sensor_event(unsigned addr, bool state) { if(state) { - SectRefSeq::iterator i; - for(i=rsv_sections.begin(); i!=rsv_sections.end(); ++i) - if(i->section->get_sensor_id() && i->section->get_sensor_id()!=addr) + BlockRefSeq::iterator i; + for(i=rsv_blocks.begin(); i!=rsv_blocks.end(); ++i) + if(i->block->get_sensor_id() && i->block->get_sensor_id()!=addr) break; - cur_sections.splice(cur_sections.begin(), rsv_sections, rsv_sections.begin(), i); + cur_blocks.splice(cur_blocks.begin(), rsv_blocks, rsv_blocks.begin(), i); reserve_more(); - if(rsv_sections.empty()) + if(rsv_blocks.empty()) loco.set_speed(0); } else { - SectRefSeq::iterator i; - for(i=cur_sections.begin(); i!=cur_sections.end(); ++i) - if(i->section->get_sensor_id()==addr) + BlockRefSeq::iterator i; + for(i=cur_blocks.begin(); i!=cur_blocks.end(); ++i) + if(i->block->get_sensor_id()==addr) break; - if(i!=cur_sections.end()) + if(i!=cur_blocks.end()) { ++i; - for(SectRefSeq::iterator j=cur_sections.begin(); j!=i; ++j) - j->section->reserve(0); - cur_sections.erase(cur_sections.begin(), i); + for(BlockRefSeq::iterator j=cur_blocks.begin(); j!=i; ++j) + j->block->reserve(0); + cur_blocks.erase(cur_blocks.begin(), i); } reserve_more(); @@ -91,23 +91,23 @@ void Train::sensor_event(unsigned addr, bool state) bool Train::reserve_more() { - SectionRef *last=0; - if(!rsv_sections.empty()) - last=&rsv_sections.back(); - else if(!cur_sections.empty()) - last=&cur_sections.back(); + BlockRef *last=0; + if(!rsv_blocks.empty()) + last=&rsv_blocks.back(); + else if(!cur_blocks.empty()) + last=&cur_blocks.back(); if(!last) return false; bool result=false; - unsigned size=rsv_sections.size(); + unsigned size=rsv_blocks.size(); while(size<5) { - const Section::Endpoint *exit=last->section->traverse(last->entry); + const Block::Endpoint *exit=last->block->traverse(last->entry); if(exit->link->reserve(this)) { - rsv_sections.push_back(SectionRef(exit->link, exit->link->get_endpoint_by_link(last->section))); - last=&rsv_sections.back(); + rsv_blocks.push_back(BlockRef(exit->link, exit->link->get_endpoint_by_link(last->block))); + last=&rsv_blocks.back(); ++size; result=true; } diff --git a/source/libmarklin/train.h b/source/libmarklin/train.h index 363fb55..96f4870 100644 --- a/source/libmarklin/train.h +++ b/source/libmarklin/train.h @@ -2,7 +2,7 @@ #define LIBMARKLIN_TRAIN_H_ #include -#include "section.h" +#include "block.h" namespace Marklin { @@ -15,24 +15,24 @@ public: Train(TrafficManager &, Locomotive &); const std::string &get_name() const { return name; } void set_speed(unsigned); - void place(Section *, const Section::Endpoint *); - bool free_section(Section *); + void place(Block *, const Block::Endpoint *); + bool free_block(Block *); void tick(); private: - struct SectionRef + struct BlockRef { - Section *section; - const Section::Endpoint *entry; + Block *block; + const Block::Endpoint *entry; - SectionRef(Section *s, const Section::Endpoint *e): section(s), entry(e) { } + BlockRef(Block *s, const Block::Endpoint *e): block(s), entry(e) { } }; - typedef std::list SectRefSeq; + typedef std::list BlockRefSeq; TrafficManager &trfc_mgr; std::string name; Locomotive &loco; - SectRefSeq cur_sections; - SectRefSeq rsv_sections; + BlockRefSeq cur_blocks; + BlockRefSeq rsv_blocks; unsigned target_speed; void sensor_event(unsigned, bool); -- 2.45.2