X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Flayout.cpp;h=de61b1bca4d5eb7e7ed5593af108ee34a2709abb;hb=64340dad429ba4040538fc06b6882aabdb489925;hp=df6989d3320cd3c7cbf4fb0f850915920f8ff431;hpb=b14059de03324aecde3efc649293d98ce5b7aaf2;p=r2c2.git diff --git a/source/libr2c2/layout.cpp b/source/libr2c2/layout.cpp index df6989d..de61b1b 100644 --- a/source/libr2c2/layout.cpp +++ b/source/libr2c2/layout.cpp @@ -1,11 +1,5 @@ -/* $Id$ - -This file is part of R²C² -Copyright © 2006-2011 Mikkosoft Productions, Mikko Rasa -Distributed under the GPL -*/ - #include +#include #include #include #include @@ -63,7 +57,7 @@ Layout::~Layout() Driver &Layout::get_driver() const { if(!driver) - throw InvalidState("No driver"); + throw logic_error("!driver"); return *driver; } @@ -126,7 +120,7 @@ Block &Layout::get_block(unsigned id) const if((*i)->get_id()==id) return **i; - throw KeyError("Unknown block", lexical_cast(id)); + throw key_error(id); } void Layout::create_blocks() @@ -186,7 +180,7 @@ Route &Layout::get_route(const string &name) const for(set::const_iterator i=routes.begin(); i!=routes.end(); ++i) if((*i)->get_name()==name) return **i; - throw KeyError("Unknown route", name); + throw key_error(name); } void Layout::update_routes() @@ -225,7 +219,7 @@ Zone &Layout::get_zone(const string &group, unsigned num) const if((*i)->get_group()==group && (*i)->get_number()==num) return **i; - throw KeyError("Unknown zone", format("%s %d", group, num)); + throw key_error(format("%s %d", group, num)); } void Layout::remove_zone(Zone &z) @@ -236,19 +230,13 @@ void Layout::remove_zone(Zone &z) void Layout::add_train(Train &t) { - if(trains.count(t.get_address())) - throw KeyError("Duplicate train address", lexical_cast(t.get_address())); - - trains[t.get_address()] = &t; + insert_unique(trains, t.get_address(), &t); signal_train_added.emit(t); } Train &Layout::get_train(unsigned addr) const { - map::const_iterator i = trains.find(addr); - if(i==trains.end()) - throw KeyError("Unknown train", lexical_cast(addr)); - return *i->second; + return *get_item(trains, addr); } void Layout::remove_train(Train &t) @@ -356,7 +344,7 @@ void Layout::block_state_changed(Block &block, Block::State state) Layout::Loader::Loader(Layout &l): - DataFile::BasicLoader(l), + DataFile::ObjectLoader(l), new_tracks(false) { add("base", &Layout::base);