3 This file is part of the MSP Märklin suite
4 Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #include <msp/core/refptr.h>
9 #include <msp/datafile/parser.h>
10 #include "catalogue.h"
12 #include "tracktype.h"
19 Catalogue::~Catalogue()
21 for(map<unsigned, TrackType *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
23 for(map<unsigned, LocoType *>::iterator i=locos.begin(); i!=locos.end(); ++i)
27 TrackType &Catalogue::get_track(unsigned art_nr) const
29 map<unsigned, TrackType *>::const_iterator i=tracks.find(art_nr);
31 throw KeyError("Unknown track type");
36 LocoType &Catalogue::get_locomotive(unsigned art_nr) const
38 map<unsigned, LocoType *>::const_iterator i=locos.find(art_nr);
40 throw KeyError("Unknown locomotive type");
46 Catalogue::Loader::Loader(Catalogue &c):
47 DataFile::BasicLoader<Catalogue>(c)
49 add("locomotive", &Loader::locomotive);
50 add("track", &Loader::track);
53 void Catalogue::Loader::locomotive(unsigned art_nr)
55 if(obj.locos.count(art_nr))
56 throw Exception("Duplicate locomotive number");
58 RefPtr<LocoType> loco = new LocoType(art_nr);
60 obj.locos[art_nr] = loco.release();
63 void Catalogue::Loader::track(unsigned art_nr)
65 if(obj.tracks.count(art_nr))
66 throw Exception("Duplicate track number");
68 RefPtr<TrackType> trk = new TrackType(art_nr);
70 obj.tracks[art_nr] = trk.release();
73 } // namespace Marklin