]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/block.h
Rename the project to R²C²
[r2c2.git] / source / libr2c2 / block.h
diff --git a/source/libr2c2/block.h b/source/libr2c2/block.h
new file mode 100644 (file)
index 0000000..e13e58b
--- /dev/null
@@ -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 <list>
+#include <set>
+#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<Track *> tracks;
+       std::vector<Endpoint> 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<Track *> &get_tracks() const { return tracks; }
+       bool has_track(Track &) const;
+       const std::vector<Endpoint> &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