#include <msp/core/refptr.h>
#include <msp/datafile/parser.h>
#include "catalogue.h"
-#include "locotype.h"
#include "tracktype.h"
+#include "vehicletype.h"
using namespace std;
using namespace Msp;
Catalogue::~Catalogue()
{
- for(map<unsigned, TrackType *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
+ for(TrackMap::iterator i=tracks.begin(); i!=tracks.end(); ++i)
delete i->second;
- for(map<unsigned, LocoType *>::iterator i=locos.begin(); i!=locos.end(); ++i)
+ for(VehicleMap::iterator i=vehicles.begin(); i!=vehicles.end(); ++i)
delete i->second;
}
+float Catalogue::get_rail_elevation() const
+{
+ return ballast_profile.get_height()+rail_profile.get_height();
+}
+
void Catalogue::add_track(TrackType &track)
{
if(tracks.count(track.get_article_number()))
signal_track_added.emit(track);
}
-void Catalogue::add_locomotive(LocoType &loco)
+const TrackType &Catalogue::get_track(const ArticleNumber &art_nr) const
{
- if(locos.count(loco.get_article_number()))
- throw Exception("Duplicate track type");
+ TrackMap::const_iterator i=tracks.find(art_nr);
+ if(i==tracks.end())
+ throw KeyError("Unknown track type");
- locos[loco.get_article_number()] = &loco;
- signal_loco_added.emit(loco);
+ return *i->second;
}
-const TrackType &Catalogue::get_track(unsigned art_nr) const
+void Catalogue::add_vehicle(VehicleType &veh)
{
- map<unsigned, TrackType *>::const_iterator i=tracks.find(art_nr);
- if(i==tracks.end())
- throw KeyError("Unknown track type");
+ if(vehicles.count(veh.get_article_number()))
+ throw Exception("Duplicate vehicle type");
- return *i->second;
+ vehicles[veh.get_article_number()] = &veh;
+ signal_vehicle_added.emit(veh);
}
-const LocoType &Catalogue::get_locomotive(unsigned art_nr) const
+const VehicleType &Catalogue::get_vehicle(const ArticleNumber &art_nr) const
{
- map<unsigned, LocoType *>::const_iterator i=locos.find(art_nr);
- if(i==locos.end())
- throw KeyError("Unknown locomotive type");
+ VehicleMap::const_iterator i = vehicles.find(art_nr);
+ if(i==vehicles.end())
+ throw KeyError("Unknown vehicle type");
return *i->second;
}
add("ballast_profile", &Loader::ballast_profile);
add("gauge", &Loader::gauge);
add("layout", &Loader::layout);
- add("locomotive", &Loader::locomotive);
add("rail_profile", &Loader::rail_profile);
add("scale", &Loader::scale);
- add("track", &Loader::track);
+ add("track", static_cast<void (Loader::*)(unsigned)>(&Loader::track));
+ add("track", static_cast<void (Loader::*)(ArticleNumber)>(&Loader::track));
+ add("vehicle", static_cast<void (Loader::*)(unsigned)>(&Loader::vehicle));
+ add("vehicle", static_cast<void (Loader::*)(ArticleNumber)>(&Loader::vehicle));
}
void Catalogue::Loader::ballast_profile()
load_sub(obj.layout);
}
-void Catalogue::Loader::locomotive(unsigned art_nr)
-{
- RefPtr<LocoType> loco = new LocoType(art_nr);
- load_sub(*loco);
- obj.add_locomotive(*loco);
- loco.release();
-}
-
void Catalogue::Loader::rail_profile()
{
load_sub(obj.rail_profile);
}
void Catalogue::Loader::track(unsigned art_nr)
+{
+ track(ArticleNumber(art_nr));
+}
+
+void Catalogue::Loader::track(ArticleNumber art_nr)
{
RefPtr<TrackType> trk = new TrackType(art_nr);
load_sub(*trk);
trk.release();
}
+void Catalogue::Loader::vehicle(unsigned art_nr)
+{
+ vehicle(ArticleNumber(art_nr));
+}
+
+void Catalogue::Loader::vehicle(ArticleNumber art_nr)
+{
+ RefPtr<VehicleType> veh = new VehicleType(art_nr);
+ load_sub(*veh);
+ obj.add_vehicle(*veh);
+ veh.release();
+}
+
} // namespace Marklin