3 This file is part of the MSP Märklin suite
4 Copyright © 2006-2010 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():
25 Catalogue::~Catalogue()
27 for(map<unsigned, TrackType *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
29 for(map<unsigned, LocoType *>::iterator i=locos.begin(); i!=locos.end(); ++i)
33 TrackType &Catalogue::get_track(unsigned art_nr) const
35 map<unsigned, TrackType *>::const_iterator i=tracks.find(art_nr);
37 throw KeyError("Unknown track type");
42 LocoType &Catalogue::get_locomotive(unsigned art_nr) const
44 map<unsigned, LocoType *>::const_iterator i=locos.find(art_nr);
46 throw KeyError("Unknown locomotive type");
52 Catalogue::Loader::Loader(Catalogue &c):
53 DataFile::BasicLoader<Catalogue>(c)
55 add("ballast_profile", &Loader::ballast_profile);
56 add("gauge", &Loader::gauge);
57 add("layout", &Loader::layout);
58 add("locomotive", &Loader::locomotive);
59 add("rail_profile", &Loader::rail_profile);
60 add("scale", &Loader::scale);
61 add("track", &Loader::track);
64 void Catalogue::Loader::ballast_profile()
66 load_sub(obj.ballast_profile);
69 void Catalogue::Loader::gauge(float g)
74 void Catalogue::Loader::layout()
79 void Catalogue::Loader::locomotive(unsigned art_nr)
81 if(obj.locos.count(art_nr))
82 throw Exception("Duplicate locomotive number");
84 RefPtr<LocoType> loco = new LocoType(art_nr);
86 obj.locos[art_nr] = loco.release();
89 void Catalogue::Loader::rail_profile()
91 load_sub(obj.rail_profile);
94 void Catalogue::Loader::scale(float n, float d)
99 void Catalogue::Loader::track(unsigned art_nr)
101 if(obj.tracks.count(art_nr))
102 throw Exception("Duplicate track number");
104 RefPtr<TrackType> trk = new TrackType(art_nr);
106 obj.tracks[art_nr] = trk.release();
109 } // namespace Marklin