1 #include <msp/strings/format.h>
12 Zone::Zone(Layout &l):
16 layout.add_zone(*this);
21 layout.remove_zone(*this);
24 void Zone::set_name(const string &g, const string &q, unsigned n)
30 signal_name_changed.emit(group, qualifier, number);
33 string Zone::get_name() const
35 string result = group;
36 if(!qualifier.empty())
42 result += format(" %d", number);
46 void Zone::add_track(Track &track)
49 throw logic_error("unconnected");
51 tracks.insert(&track);
54 bool Zone::add_tracks(const TrackSet &trks)
56 TrackSet pending = trks;
61 for(TrackSet::const_iterator i=pending.begin(); i!=pending.end(); ++i)
73 throw logic_error("unconnected");
74 return pending.empty();
81 void Zone::save(list<DataFile::Statement> &st) const
83 st.push_back((DataFile::Statement("group"), group));
84 if(!qualifier.empty())
85 st.push_back((DataFile::Statement("qualifier"), qualifier));
87 st.push_back((DataFile::Statement("number"), number));
89 set<unsigned> block_ids;
90 for(TrackSet::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
91 block_ids.insert((*i)->get_block().get_id());
93 for(set<unsigned>::const_iterator i=block_ids.begin(); i!=block_ids.end(); ++i)
94 st.push_back((DataFile::Statement("block"), *i));
97 bool Zone::is_valid(Track &t) const
102 const vector<Track *> &links = t.get_links();
103 for(vector<Track *>::const_iterator i=links.begin(); i!=links.end(); ++i)
104 if(*i && tracks.count(*i))
111 Zone::Loader::Loader(Zone &z):
112 DataFile::ObjectLoader<Zone>(z)
114 add("block", &Loader::block);
115 add("group", &Zone::group);
116 add("number", &Zone::number);
117 add("qualifier", &Zone::qualifier);
120 void Zone::Loader::block(unsigned b)
122 Block &blk = obj.layout.get_block(b);
123 const set<Track *> &btracks = blk.get_tracks();
124 obj.tracks.insert(btracks.begin(), btracks.end());