X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Fblock.h;fp=source%2Flibr2c2%2Fblock.h;h=e13e58b7da510703c57834a232619bd6f1076db3;hb=1ff06c5bc46a677fa389ef86c6b26664368f1653;hp=0000000000000000000000000000000000000000;hpb=9b05c573a38639827697fe393d55b7c76f5bde45;p=r2c2.git diff --git a/source/libr2c2/block.h b/source/libr2c2/block.h new file mode 100644 index 0000000..e13e58b --- /dev/null +++ b/source/libr2c2/block.h @@ -0,0 +1,70 @@ +/* $Id$ + +This file is part of R²C² +Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa +Distributed under the GPL +*/ + +#ifndef LIBR2C2_BLOCK_H_ +#define LIBR2C2_BLOCK_H_ + +#include +#include +#include "track.h" + +namespace R2C2 { + +class Layout; +class Route; +class TrackIter; +class Train; + +class Block +{ +public: + struct Endpoint + { + Track *track; + unsigned track_ep; + Block *link; + unsigned paths; + + Endpoint(Track *, unsigned); + }; + +private: + Layout &layout; + unsigned id; + unsigned sensor_id; + unsigned turnout_id; + std::set tracks; + std::vector endpoints; + Train *train; + +public: + Block(Layout &, Track &); + ~Block(); + + unsigned get_id() const { return id; } + unsigned get_sensor_id() const { return sensor_id; } + unsigned get_turnout_id() const { return turnout_id; } + const std::set &get_tracks() const { return tracks; } + bool has_track(Track &) const; + const std::vector &get_endpoints() const { return endpoints; } + const Endpoint &get_endpoint(unsigned) const; + int get_endpoint_by_link(Block &) const; + float get_path_length(unsigned, const Route * = 0) const; + void check_link(Block &); + void break_link(Block &); + Block *get_link(unsigned) const; + bool reserve(Train *); + Train *get_train() const { return train; } + void print_debug(); +private: + void find_paths(TrackIter, unsigned); + void determine_id(); +}; + +} // namespace R2C2 + +#endif