]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/trackchain.h
Don't use bool for a counter variable
[r2c2.git] / source / libr2c2 / trackchain.h
1 #ifndef LIBR2C2_TRACKCHAIN_H_
2 #define LIBR2C2_TRACKCHAIN_H_
3
4 #include <set>
5 #include <stdexcept>
6 #include <sigc++/trackable.h>
7 #include <msp/datafile/statement.h>
8 #include "trackiter.h"
9
10 namespace R2C2 {
11
12 class Layout;
13 class Object;
14
15 class bad_chain: public std::logic_error
16 {
17 public:
18         bad_chain(const std::string &w): std::logic_error(w) { }
19         virtual ~bad_chain() throw() { }
20 };
21
22
23 class TrackChain: public sigc::trackable
24 {
25 public:
26         typedef std::set<Track *> TrackSet;
27
28 protected:
29         enum Validity
30         {
31                 VALID,
32                 UNLINKED,
33                 BAD_PATH,
34                 INCOMPATIBLE
35         };
36
37 public:
38         sigc::signal<void, const std::string &> signal_name_changed;
39         sigc::signal<void, Track &> signal_track_added;
40         sigc::signal<void, Track &> signal_track_removed;
41
42 protected:
43         Layout &layout;
44         std::string name;
45         TrackSet tracks;
46         TrackIter ends[2];
47
48         TrackChain(Layout &);
49 public:
50         virtual ~TrackChain() { }
51
52         virtual void set_name(const std::string &);
53         const std::string &get_name() const { return name; }
54
55         void add_track(Track &);
56         void add_tracks(const TrackSet &);
57 protected:
58         virtual void on_track_added(Track &) { }
59         virtual Validity check_validity(Track &) const;
60         static void throw_bad_chain(Validity);
61 private:
62         void update_ends(Track &);
63 public:
64         const TrackSet &get_tracks() const { return tracks; }
65         bool has_track(Track &) const;
66         bool is_loop() const;
67
68 private:
69         void object_removed(Object &);
70
71 public:
72         virtual Msp::DataFile::Statement save_reference() const = 0;
73 };
74
75 } // namespace R2C2
76
77 #endif