From: Mikko Rasa Date: Sun, 30 Mar 2014 13:34:03 +0000 (+0300) Subject: Be stricter with const qualifiers X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=a1c3c054707fc65d497dd13da59b37a9ddb369cc;p=r2c2.git Be stricter with const qualifiers --- diff --git a/source/libr2c2/trainrouteplanner.cpp b/source/libr2c2/trainrouteplanner.cpp index c115d92..45e83e2 100644 --- a/source/libr2c2/trainrouteplanner.cpp +++ b/source/libr2c2/trainrouteplanner.cpp @@ -29,7 +29,7 @@ TrainRoutePlanner::TrainRoutePlanner(Layout &layout) void TrainRoutePlanner::plan() { - RoutingStep *goal = 0; + const RoutingStep *goal = 0; for(list::iterator i=steps.begin(); i!=steps.end(); ++i) { if(i->is_goal()) @@ -45,7 +45,7 @@ void TrainRoutePlanner::plan() create_routes(*goal); } -void TrainRoutePlanner::add_steps(RoutingStep &step) +void TrainRoutePlanner::add_steps(const RoutingStep &step) { list new_steps; step.create_successors(new_steps); @@ -53,7 +53,7 @@ void TrainRoutePlanner::add_steps(RoutingStep &step) steps.merge(new_steps); } -void TrainRoutePlanner::create_routes(RoutingStep &goal) +void TrainRoutePlanner::create_routes(const RoutingStep &goal) { for(vector::iterator i=routed_trains.begin(); i!=routed_trains.end(); ++i) { @@ -62,9 +62,9 @@ void TrainRoutePlanner::create_routes(RoutingStep &goal) i->route->set_temporary(true); } - for(RoutingStep *i=&goal; i; i=i->prev) + for(const RoutingStep *i=&goal; i; i=i->prev) { - for(vector::iterator j=i->trains.begin(); j!=i->trains.end(); ++j) + for(vector::const_iterator j=i->trains.begin(); j!=i->trains.end(); ++j) { if(j->state==WAITING || j->state==BLOCKED) j->info->waits.push_front(&*j); @@ -75,8 +75,8 @@ void TrainRoutePlanner::create_routes(RoutingStep &goal) for(vector::iterator i=routed_trains.begin(); i!=routed_trains.end(); ++i) { i->router->set_route(i->route); - TrainRoutingState *current_wait = 0; - for(list::iterator j=i->waits.begin(); j!=i->waits.end(); ++j) + const TrainRoutingState *current_wait = 0; + for(list::const_iterator j=i->waits.begin(); j!=i->waits.end(); ++j) if(!current_wait || (*j)->track.track()!=current_wait->track.track()) { Block &block = (*j)->track.next()->get_block(); @@ -250,13 +250,13 @@ TrainRoutePlanner::RoutingStep::RoutingStep(): prev(0) { } -TrainRoutePlanner::RoutingStep::RoutingStep(RoutingStep *p): +TrainRoutePlanner::RoutingStep::RoutingStep(const RoutingStep *p): time(p->time), trains(p->trains), prev(p) { } -void TrainRoutePlanner::RoutingStep::create_successors(list &new_steps) +void TrainRoutePlanner::RoutingStep::create_successors(list &new_steps) const { RoutingStep next(this); if(next.update_states()) diff --git a/source/libr2c2/trainrouteplanner.h b/source/libr2c2/trainrouteplanner.h index de88302..d24c3dc 100644 --- a/source/libr2c2/trainrouteplanner.h +++ b/source/libr2c2/trainrouteplanner.h @@ -25,7 +25,7 @@ private: float speed; TrainRouter *router; Route *route; - std::list waits; + std::list waits; TrainRoutingInfo(Train &); }; @@ -79,12 +79,12 @@ private: { Msp::Time::TimeDelta time; std::vector trains; - RoutingStep *prev; + const RoutingStep *prev; RoutingStep(); - RoutingStep(RoutingStep *); + RoutingStep(const RoutingStep *); - void create_successors(std::list &); + void create_successors(std::list &) const; bool update_states(); bool check_deadlocks() const; int get_occupant(Track &) const; @@ -104,8 +104,8 @@ public: void plan(); private: - void add_steps(RoutingStep &); - void create_routes(RoutingStep &); + void add_steps(const RoutingStep &); + void create_routes(const RoutingStep &); }; } // namespace R2C2