1 #include <msp/strings/format.h>
2 #include <msp/strings/regex.h>
13 Zone::Zone(Layout &l):
25 void Zone::set_name(const string &n)
27 Regex r_name("(.+) ([^ ]+) ([1-9][0-9]*)");
28 RegMatch m = r_name.match(n);
30 throw invalid_argument("Zone::set_name");
32 set_name(m[1].str, m[2].str, lexical_cast<unsigned>(m[3].str));
35 void Zone::set_name(const string &g, const string &q, unsigned n)
44 void Zone::update_name()
46 string full_name = group;
47 if(!qualifier.empty())
50 full_name += qualifier;
53 full_name += format(" %d", number);
54 TrackChain::set_name(full_name);
57 void Zone::save(list<DataFile::Statement> &st) const
59 st.push_back((DataFile::Statement("group"), group));
60 if(!qualifier.empty())
61 st.push_back((DataFile::Statement("qualifier"), qualifier));
63 st.push_back((DataFile::Statement("number"), number));
65 set<unsigned> block_ids;
66 for(TrackSet::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
67 block_ids.insert((*i)->get_block().get_id());
69 for(set<unsigned>::const_iterator i=block_ids.begin(); i!=block_ids.end(); ++i)
70 st.push_back((DataFile::Statement("block"), *i));
73 DataFile::Statement Zone::save_reference() const
75 return (DataFile::Statement("zone"), group, number);
79 Zone::Loader::Loader(Zone &z):
80 DataFile::ObjectLoader<Zone>(z)
82 add("block", &Loader::block);
83 add("group", &Zone::group);
84 add("number", &Zone::number);
85 add("qualifier", &Zone::qualifier);
88 void Zone::Loader::finish()
93 void Zone::Loader::block(unsigned b)
95 Block &blk = obj.layout.get_block(b);
96 const set<Track *> &btracks = blk.get_tracks();
97 obj.tracks.insert(btracks.begin(), btracks.end());