From c47f3fad07af11210c9cbd65d87964794189065e Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 20 Dec 2009 00:30:50 +0000 Subject: [PATCH] Consider failed track or block traversal a fatal error --- source/libmarklin/block.cpp | 11 ++++------- source/libmarklin/block.h | 2 +- source/libmarklin/track.cpp | 4 ++-- source/libmarklin/track.h | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/source/libmarklin/block.cpp b/source/libmarklin/block.cpp index 9a9164e..e9c170c 100644 --- a/source/libmarklin/block.cpp +++ b/source/libmarklin/block.cpp @@ -68,7 +68,7 @@ int Block::get_endpoint_by_link(const Block &other) const return -1; } -int Block::traverse(unsigned epi, float *len) const +unsigned Block::traverse(unsigned epi, float *len) const { if(epi>=endpoints.size()) throw InvalidParameterValue("Endpoint index out of range"); @@ -93,17 +93,14 @@ int Block::traverse(unsigned epi, float *len) const if(len) *len += track->get_type().get_path_length(cur_path); - int other_ep = track->traverse(track_ep, cur_path); - if(other_ep<0) - return -1; - + unsigned other_ep = track->traverse(track_ep, cur_path); for(unsigned i=0; i(other_ep)) return i; Track *next = track->get_link(other_ep); - if(tracks.count(next)==0) - return -1; + if(!tracks.count(next)) + throw LogicError("Block traversal strayed out of the block"); track_ep = next->get_endpoint_by_link(*track); track = next; } diff --git a/source/libmarklin/block.h b/source/libmarklin/block.h index 64f02e5..7c0f8ac 100644 --- a/source/libmarklin/block.h +++ b/source/libmarklin/block.h @@ -47,7 +47,7 @@ public: const std::set &get_tracks() const { return tracks; } const std::vector &get_endpoints() const { return endpoints; } int get_endpoint_by_link(const Block &) const; - int traverse(unsigned, float * =0) const; + unsigned traverse(unsigned, float * =0) const; void check_link(Block &); Block *get_link(unsigned) const; bool reserve(const Train *); diff --git a/source/libmarklin/track.cpp b/source/libmarklin/track.cpp index 6c72c46..3c2a410 100644 --- a/source/libmarklin/track.cpp +++ b/source/libmarklin/track.cpp @@ -223,7 +223,7 @@ Track *Track::get_link(unsigned i) const return links[i]; } -int Track::traverse(unsigned i, unsigned path) const +unsigned Track::traverse(unsigned i, unsigned path) const { const vector &eps = type.get_endpoints(); if(i>=eps.size()) @@ -246,7 +246,7 @@ int Track::traverse(unsigned i, unsigned path) const return j; } - return -1; + throw Exception("Track endpoint did not have a counterpart"); } Point Track::get_point(unsigned epi, unsigned path, float d) const diff --git a/source/libmarklin/track.h b/source/libmarklin/track.h index b000e34..21c505f 100644 --- a/source/libmarklin/track.h +++ b/source/libmarklin/track.h @@ -71,7 +71,7 @@ public: void break_links(); const std::vector &get_links() const { return links; } Track *get_link(unsigned) const; - int traverse(unsigned, unsigned) const; + unsigned traverse(unsigned, unsigned) const; Point get_point(unsigned, unsigned, float) const; /** -- 2.43.0