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():
24 Catalogue::~Catalogue()
26 for(map<unsigned, TrackType *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
28 for(map<unsigned, LocoType *>::iterator i=locos.begin(); i!=locos.end(); ++i)
32 TrackType &Catalogue::get_track(unsigned art_nr) const
34 map<unsigned, TrackType *>::const_iterator i=tracks.find(art_nr);
36 throw KeyError("Unknown track type");
41 LocoType &Catalogue::get_locomotive(unsigned art_nr) const
43 map<unsigned, LocoType *>::const_iterator i=locos.find(art_nr);
45 throw KeyError("Unknown locomotive type");
51 Catalogue::Loader::Loader(Catalogue &c):
52 DataFile::BasicLoader<Catalogue>(c)
54 add("ballast_profile", &Loader::ballast_profile);
55 add("gauge", &Loader::gauge);
56 add("locomotive", &Loader::locomotive);
57 add("rail_profile", &Loader::rail_profile);
58 add("scale", &Loader::scale);
59 add("track", &Loader::track);
62 void Catalogue::Loader::ballast_profile()
64 load_sub(obj.ballast_profile);
67 void Catalogue::Loader::gauge(float g)
72 void Catalogue::Loader::locomotive(unsigned art_nr)
74 if(obj.locos.count(art_nr))
75 throw Exception("Duplicate locomotive number");
77 RefPtr<LocoType> loco = new LocoType(art_nr);
79 obj.locos[art_nr] = loco.release();
82 void Catalogue::Loader::rail_profile()
84 load_sub(obj.rail_profile);
87 void Catalogue::Loader::scale(float n, float d)
92 void Catalogue::Loader::track(unsigned art_nr)
94 if(obj.tracks.count(art_nr))
95 throw Exception("Duplicate track number");
97 RefPtr<TrackType> trk = new TrackType(art_nr);
99 obj.tracks[art_nr] = trk.release();
102 } // namespace Marklin