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 void Catalogue::add_track(TrackType &track)
35 if(tracks.count(track.get_article_number()))
36 throw Exception("Duplicate track type");
38 tracks[track.get_article_number()] = &track;
39 signal_track_added.emit(track);
42 void Catalogue::add_locomotive(LocoType &loco)
44 if(locos.count(loco.get_article_number()))
45 throw Exception("Duplicate track type");
47 locos[loco.get_article_number()] = &loco;
48 signal_loco_added.emit(loco);
51 const TrackType &Catalogue::get_track(unsigned art_nr) const
53 map<unsigned, TrackType *>::const_iterator i=tracks.find(art_nr);
55 throw KeyError("Unknown track type");
60 const LocoType &Catalogue::get_locomotive(unsigned art_nr) const
62 map<unsigned, LocoType *>::const_iterator i=locos.find(art_nr);
64 throw KeyError("Unknown locomotive type");
70 Catalogue::Loader::Loader(Catalogue &c):
71 DataFile::BasicLoader<Catalogue>(c)
73 add("ballast_profile", &Loader::ballast_profile);
74 add("gauge", &Loader::gauge);
75 add("layout", &Loader::layout);
76 add("locomotive", &Loader::locomotive);
77 add("rail_profile", &Loader::rail_profile);
78 add("scale", &Loader::scale);
79 add("track", &Loader::track);
82 void Catalogue::Loader::ballast_profile()
84 load_sub(obj.ballast_profile);
87 void Catalogue::Loader::gauge(float g)
92 void Catalogue::Loader::layout()
97 void Catalogue::Loader::locomotive(unsigned art_nr)
99 RefPtr<LocoType> loco = new LocoType(art_nr);
101 obj.add_locomotive(*loco);
105 void Catalogue::Loader::rail_profile()
107 load_sub(obj.rail_profile);
110 void Catalogue::Loader::scale(float n, float d)
115 void Catalogue::Loader::track(unsigned art_nr)
117 RefPtr<TrackType> trk = new TrackType(art_nr);
123 } // namespace Marklin