]> git.tdb.fi Git - r2c2.git/commitdiff
Be stricter with const qualifiers
authorMikko Rasa <tdb@tdb.fi>
Sun, 30 Mar 2014 13:34:03 +0000 (16:34 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 30 Mar 2014 16:35:53 +0000 (19:35 +0300)
source/libr2c2/trainrouteplanner.cpp
source/libr2c2/trainrouteplanner.h

index c115d924bed8e0603436c0705a0a4bd46deab364..45e83e267fb2b37e8b260630442e4a055089f667 100644 (file)
@@ -29,7 +29,7 @@ TrainRoutePlanner::TrainRoutePlanner(Layout &layout)
 
 void TrainRoutePlanner::plan()
 {
-       RoutingStep *goal = 0;
+       const RoutingStep *goal = 0;
        for(list<RoutingStep>::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<RoutingStep> 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<TrainRoutingInfo>::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<TrainRoutingState>::iterator j=i->trains.begin(); j!=i->trains.end(); ++j)
+               for(vector<TrainRoutingState>::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<TrainRoutingInfo>::iterator i=routed_trains.begin(); i!=routed_trains.end(); ++i)
        {
                i->router->set_route(i->route);
-               TrainRoutingState *current_wait = 0;
-               for(list<TrainRoutingState *>::iterator j=i->waits.begin(); j!=i->waits.end(); ++j)
+               const TrainRoutingState *current_wait = 0;
+               for(list<const TrainRoutingState *>::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<RoutingStep> &new_steps)
+void TrainRoutePlanner::RoutingStep::create_successors(list<RoutingStep> &new_steps) const
 {
        RoutingStep next(this);
        if(next.update_states())
index de88302d3f6c8e0a22d79fedd7edebf9580a32c0..d24c3dc6a2ae54903bd4f6dd731861f9e000e110 100644 (file)
@@ -25,7 +25,7 @@ private:
                float speed;
                TrainRouter *router;
                Route *route;
-               std::list<TrainRoutingState *> waits;
+               std::list<const TrainRoutingState *> waits;
 
                TrainRoutingInfo(Train &);
        };
@@ -79,12 +79,12 @@ private:
        {
                Msp::Time::TimeDelta time;
                std::vector<TrainRoutingState> trains;
-               RoutingStep *prev;
+               const RoutingStep *prev;
 
                RoutingStep();
-               RoutingStep(RoutingStep *);
+               RoutingStep(const RoutingStep *);
 
-               void create_successors(std::list<RoutingStep> &);
+               void create_successors(std::list<RoutingStep> &) 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