if(FS::exists(path))
return path;
- throw Exception("Can't locate "+name);
+ throw runtime_error("Can't locate "+name);
}
template<typename T>
{
DataFile::load(*grf, (FS::Path("icons")/(name+".mesh")).str());
}
- catch(const Exception &e)
+ catch(const exception &e)
{
IO::print("Error loading overlay graphic '%s': %s\n", name, e.what());
delete grf;
#include "track.h"
#include "tracktype.h"
+using namespace std;
using namespace Msp;
namespace R2C2 {
void Path3D::set_path(unsigned p)
{
if(!(track.get_track().get_type().get_paths()&(1<<p)))
- throw InvalidParameterValue("Invalid path");
+ throw invalid_argument("Path3D::set_path");
automatic = false;
paths = 1<<p;
}
void Path3D::set_mask(unsigned p)
{
if(p&~track.get_track().get_type().get_paths())
- throw InvalidParameterValue("Invalid path mask");
+ throw invalid_argument("Path3D::set_mask");
automatic = false;
paths = p;
}
const GL::Mesh &TrackType3D::get_path_mesh(unsigned p) const
{
- if(p>=path_meshes.size() || !path_meshes[p])
- throw InvalidParameterValue("Invalid path");
+ if(p>=path_meshes.size())
+ throw out_of_range("TrackType3D::get_path_mesh");
+ if(!path_meshes[p])
+ throw invalid_argument("TrackType3D::get_path_mesh");
return *path_meshes[p];
}
const GL::Object *VehicleType3D::get_fixed_axle_object(unsigned i) const
{
if(i>=axle_objects[0].size())
- throw InvalidParameterValue("Axle index out of range");
+ throw out_of_range("VehicleType3D::get_fixed_axle_object");
return axle_objects[0][i];
}
const GL::Object *VehicleType3D::get_bogie_object(unsigned i) const
{
if(i>=bogie_objects.size())
- throw InvalidParameterValue("Bogie index out of range");
+ throw out_of_range("VehicleType3D::get_bogie_object");
return bogie_objects[i];
}
const GL::Object *VehicleType3D::get_bogie_axle_object(unsigned i, unsigned j) const
{
if(i>=bogie_objects.size())
- throw InvalidParameterValue("Bogie index out of range");
+ throw out_of_range("VehicleType3D::get_bogie_axle_object");
if(j>=axle_objects[i+1].size())
- throw InvalidParameterValue("Axle index out of range");
+ throw out_of_range("VehicleType3D::get_bogie_axle_object");
return axle_objects[i+1][j];
}
const GL::Object *VehicleType3D::get_rod_object(unsigned i) const
{
if(i>=rod_objects.size())
- throw InvalidParameterValue("Rod index out of range");
+ throw out_of_range("VehicleType3D::get_rod_object");
return rod_objects[i];
}
{
cur_route->add_tracks(selection.get_tracks());
}
- catch(const Exception &e)
+ catch(const exception &e)
{
lbl_status->set_text(e.what());
}
{
cur_zone->add_tracks(selection.get_tracks());
}
- catch(const Exception &e)
+ catch(const exception &e)
{
lbl_status->set_text(e.what());
}
#include <cstdlib>
#include <limits>
#include <signal.h>
-#include <msp/core/except.h>
#include <msp/fs/stat.h>
#include <msp/fs/utils.h>
#include <msp/graphics/display.h>
screen_h = lexical_cast<unsigned>(m[2].str);
}
else
- throw UsageError("Invalid resolution");
+ throw usage_error("Invalid resolution");
}
const vector<string> &args = getopt.get_args();
if(args.empty())
- throw UsageError("No layout given");
+ throw usage_error("No layout given");
layout_fn = args[0];
for(vector<Timetable::Row>::const_iterator i=rows.begin(); i!=rows.end(); ++i)
timetable.append(*i);
}
- catch(const Exception &e)
+ catch(const exception &e)
{
// XXX Need a better way to report errors. Also, should not let the dialog close.
IO::print("%s\n", e.what());
++i;
}
- throw InvalidParameterValue("Vehicle type index out of range");
+ throw out_of_range("TrainProperties::get_vehicle_type");
}
for(vector<string>::iterator i=sparts.begin(); i!=sparts.end(); ++i)
{
if(i->empty())
- throw InvalidParameterValue("Malformed article number");
+ throw invalid_argument("ArticleNumber::ArticleNumber");
unsigned nondigit = i->size();
for(unsigned j=0; j<i->size(); ++j)
}
if(!nondigit || nondigit<i->size()-1)
- throw InvalidParameterValue("Malformed article number");
+ throw invalid_argument("ArticleNumber::ArticleNumber");
Part part;
part.number = lexical_cast<unsigned>(i->substr(0, nondigit));
const Block::Endpoint &Block::get_endpoint(unsigned i) const
{
if(i>=endpoints.size())
- throw InvalidParameterValue("Endpoint index out of range");
+ throw out_of_range("Block::get_endpoint");
return endpoints[i];
}
float Block::get_path_length(unsigned entry, const Route *route) const
{
if(entry>=endpoints.size())
- throw InvalidParameterValue("Endpoint index out of range");
+ throw out_of_range("Block::get_path_length");
TrackIter t_iter(endpoints[entry].track, endpoints[entry].track_ep);
Block *Block::get_link(unsigned epi) const
{
if(epi>=endpoints.size())
- throw InvalidParameterValue("Endpoint index out of range");
+ throw out_of_range("Block::get_link");
return endpoints[epi].link;
}
-#include <msp/core/except.h>
#include "block.h"
#include "blockiter.h"
#include "route.h"
_entry(b ? e : 0)
{
if(_block && _entry>_block->get_endpoints().size())
- throw InvalidParameterValue("Endpoint index not valid for block");
+ throw out_of_range("BlockIter::BlockIter");
}
TrackIter BlockIter::track_iter() const
const Block::Endpoint &BlockIter::endpoint() const
{
if(!_block)
- throw InvalidState("BlockIter is null");
+ throw logic_error("null block");
return _block->get_endpoint(_entry);
}
while(t_iter)
{
if(!_block->has_track(*t_iter))
- throw LogicError("Block traversal strayed out of the block");
+ throw logic_error("internal error (block traversal escaped the block)");
unsigned path = (route ? route->get_path(*t_iter) : t_iter->get_active_path());
TrackIter t_exit = t_iter.reverse(path);
Block &BlockIter::operator*() const
{
if(!_block)
- throw InvalidState("BlockIter is null");
+ throw logic_error("null block");
return *_block;
}
else if(name=="MFX")
return MFX;
else
- throw InvalidParameterValue("Unknown protocol");
+ throw invalid_argument("CentralStation::map_protocol");
}
template<typename T>
#include <cmath>
-#include <msp/core/except.h>
#include "controller.h"
using namespace std;
-using namespace Msp;
namespace R2C2 {
Controller::Control Controller::Control::discrete(const string &n, float m, float x, float s)
{
if(x<m)
- throw InvalidParameterValue("Max value must be greater than min value");
+ throw invalid_argument("Controller::Control::discrete");
Controller::Control tc;
tc.name = n;
Controller::Control Controller::Control::continuous(const string &n, float m, float x)
{
if(x<m)
- throw InvalidParameterValue("Max value must be greater than min value");
+ throw invalid_argument("Controller::Control::continuous");
Controller::Control tc;
tc.name = n;
-#include <msp/core/except.h>
#include "centralstation.h"
#include "driver.h"
#include "dummy.h"
else if(type=="dummy")
return new Dummy;
- throw Msp::InvalidParameterValue("Unknown driver");
+ throw invalid_argument("Driver::create");
}
} // namespace R2C2
}
if(!ok)
- throw Exception("IB not detected");
+ throw runtime_error("IB not detected");
if(p50)
serial.write("xZzA1\r", 6);
else if(name=="MM-27")
return MM_27;
else
- throw InvalidParameterValue("Unknown protocol");
+ throw invalid_argument("Intellibox::map_protocol");
}
void Intellibox::command(Command cmd)
Driver &Layout::get_driver() const
{
if(!driver)
- throw InvalidState("No driver");
+ throw logic_error("!driver");
return *driver;
}
const Profile::Vertex &Profile::get_vertex(unsigned i) const
{
if(i>=vertices.size())
- throw InvalidParameterValue("Index out of range");
+ throw out_of_range("Profile::get_vertex");
return vertices[i];
}
void Route::set_turnout(unsigned addr, unsigned path)
{
if(!addr)
- throw InvalidParameterValue("Invalid turnout address");
+ throw invalid_argument("Route::set_turnout");
int &state = get_item(turnouts, addr);
if(state>=0 && path!=static_cast<unsigned>(state))
- throw InvalidState("Setting conflicts with route");
+ throw logic_error("route conflict");
state = path;
}
-#include <msp/core/except.h>
#include <msp/core/maputils.h>
#include <msp/time/units.h>
#include "simplecontroller.h"
else if(name==reverse.name)
{
if(target_speed.value || speed)
- throw InvalidState("Must be stopped to change reverse");
+ throw logic_error("Must be stopped to change reverse");
reverse.set(v);
signal_control_changed.emit(reverse);
}
weight_limit(10)
{
if(n<1)
- throw InvalidParameterValue("Must have at leats one speed step");
+ throw invalid_argument("SpeedQuantizer::SpeedQuantizer");
}
void SpeedQuantizer::learn(unsigned i, float s, float w)
{
if(i>=steps.size())
- throw InvalidParameterValue("Speed step index out of range");
+ throw out_of_range("SpeedQuantizer::learn");
steps[i].add(s, w);
}
void Timetable::insert(unsigned i, const Row &row)
{
if(i>rows.size())
- throw InvalidParameterValue("Insert position out of range");
+ throw out_of_range("Timetable::insert");
rows.insert(rows.begin()+i, row);
if(i<=current_row)
const Timetable::Row &Timetable::get_row(unsigned i) const
{
if(i>=rows.size())
- throw InvalidParameterValue("Row index out of range");
+ throw out_of_range("Timetable::get_row");
return rows[i];
}
{
string::size_type space = name.rfind(' ');
if(space==string::npos || space==0)
- throw InvalidParameterValue("Invalid zone name");
+ throw invalid_argument("Timetable::get_zone");
unsigned number = lexical_cast<unsigned>(name.substr(space+1));
return train.get_layout().get_zone(name.substr(0, space), number);
}
const T &Timetable::Row::get_param(unsigned i) const
{
if(i>=params.size())
- throw InvalidParameterValue("Parameter index out of range");
+ throw out_of_range("Timetable::Row::get_param");
return params[i].value<T>();
}
return Row(ROUTE, s.substr(10));
}
- throw InvalidParameterValue("Invalid row");
+ throw invalid_argument("Timetable::Row::parse");
}
void Track::set_block(Block *b)
{
if(b && !b->has_track(*this))
- throw InvalidParameterValue("Track is not in the Block");
+ throw logic_error("track not in block");
if(!b && block && block->has_track(*this))
- throw InvalidState("Track is still in a Block");
+ throw logic_error("track still in block");
block = b;
}
Block &Track::get_block() const
{
if(!block)
- throw InvalidState("No Block");
+ throw logic_error("!block");
return *block;
}
void Track::set_turnout_id(unsigned i)
{
if(!type.is_turnout())
- throw InvalidState("Not a turnout");
+ throw logic_error("not a turnout");
turnout_id = i;
layout.create_blocks(*this);
void Track::set_sensor_id(unsigned i)
{
if(type.is_turnout())
- throw InvalidState("Can't set sensor on a turnout");
+ throw logic_error("is a turnout");
sensor_id = i;
layout.create_blocks(*this);
void Track::set_active_path(unsigned p)
{
if(!turnout_id)
- throw InvalidState("Not a turnout");
+ throw logic_error("not a turnout");
if(!(type.get_paths()&(1<<p)))
- throw InvalidParameterValue("Invalid path");
+ throw invalid_argument("Track::set_active_path");
layout.get_driver().set_turnout(turnout_id, p);
}
{
const vector<TrackType::Endpoint> &eps = type.get_endpoints();
if(epi>=eps.size())
- throw InvalidParameterValue("TrackType::Endpoint index out of range");
+ throw out_of_range("Track::get_endpoint_position");
const TrackType::Endpoint &ep = eps[epi];
{
const vector<TrackType::Endpoint> &eps = type.get_endpoints();
if(epi>=eps.size())
- throw InvalidParameterValue("TrackType::Endpoint index out of range");
+ throw out_of_range("Track::get_endpoint_direction");
const TrackType::Endpoint &ep = eps[epi];
Track *Track::get_link(unsigned i) const
{
if(i>links.size())
- throw InvalidParameterValue("Link index out of range");
+ throw out_of_range("Track::get_link");
return links[i];
}
#include <algorithm>
-#include <msp/core/except.h>
#include "track.h"
#include "trackiter.h"
#include "tracktype.h"
_entry(t ? e : 0)
{
if(_track && _entry>_track->get_type().get_endpoints().size())
- throw InvalidParameterValue("Endpoint index not valid for track");
+ throw out_of_range("TrackIter::TrackIter");
}
const TrackType::Endpoint &TrackIter::endpoint() const
{
if(!_track)
- throw InvalidState("TrackIter is null");
+ throw logic_error("null track");
return _track->get_type().get_endpoint(_entry);
}
Track &TrackIter::operator*() const
{
if(!_track)
- throw InvalidState("TrackIter is null");
+ throw logic_error("null track");
return *_track;
}
TrackPart *TrackPart::get_link(unsigned i) const
{
if(i>=2)
- throw InvalidParameterValue("Index out of range");
+ throw out_of_range("TrackPart::get_link");
return links[i];
}
const TrackType::Endpoint &TrackType::get_endpoint(unsigned i) const
{
if(i>=endpoints.size())
- throw InvalidParameterValue("Endpoint index out of range");
+ throw out_of_range("TrackType::get_endpoint");
return endpoints[i];
}
TrackPoint TrackType::get_point(unsigned epi, unsigned path, float d) const
{
if(epi>=endpoints.size())
- throw InvalidParameterValue("Endpoint index out of range");
+ throw out_of_range("TrackType::get_point");
const TrackPart *part = 0;
unsigned part_ep = 0;
}
if(!part)
- throw Exception("Internal error (endpoint does not match any part)");
+ throw logic_error("internal error (endpoint does not match any part)");
while(1)
{
d -= plen;
TrackPart *next = part->get_link(1-part_ep);
if(!next)
- throw InvalidParameterValue("Distance out of range");
+ throw invalid_argument("TrackType::get_point");
part_ep = (next->get_link(0)==part ? 0 : 1);
part = next;
}
overshoot_dist(false)
{
if(!loco_type.is_locomotive())
- throw InvalidParameterValue("Initial vehicle must be a locomotive");
+ throw invalid_argument("Train::Train");
unsigned speed_steps = layout.get_driver().get_protocol_speed_steps(protocol);
if(speed_steps)
void Train::remove_vehicle(unsigned i)
{
if(i>=vehicles.size())
- throw InvalidParameterValue("Vehicle index out of range");
+ throw out_of_range("Train::remove_vehicle");
if(i==0)
- throw InvalidParameterValue("Can't remove the locomotive");
+ throw logic_error("can't remove locomotive");
delete vehicles[i];
vehicles.erase(vehicles.begin()+i);
if(i<vehicles.size())
Vehicle &Train::get_vehicle(unsigned i)
{
if(i>=vehicles.size())
- throw InvalidParameterValue("Vehicle index out of range");
+ throw out_of_range("Train::get_vehicle");
return *vehicles[i];
}
const Vehicle &Train::get_vehicle(unsigned i) const
{
if(i>=vehicles.size())
- throw InvalidParameterValue("Vehicle index out of range");
+ throw out_of_range("Train::get_vehicle");
return *vehicles[i];
}
if(a==active)
return;
if(!a && controller->get_speed())
- throw InvalidState("Can't deactivate while moving");
+ throw logic_error("moving");
active = a;
if(active)
void Train::set_function(unsigned func, bool state)
{
if(!loco_type.get_functions().count(func))
- throw InvalidParameterValue("Invalid function");
+ throw invalid_argument("Train::set_function");
layout.get_driver().set_loco_function(address, func, state);
}
bool Train::divert(Track &from)
{
if(!from.get_turnout_id())
- throw InvalidParameterValue("Can't divert from a non-turnout");
+ throw invalid_argument("Train::divert");
if(routes.empty())
return false;
if(end!=routes.end())
break;
else if(!diversion->has_track(*track))
- throw LogicError("Pathfinder returned a bad route");
+ throw logic_error("bad diversion");
track = track.next(diversion->get_path(*track));
}
void Train::place(Block &block, unsigned entry)
{
if(controller->get_speed())
- throw InvalidState("Must be stopped before placing");
+ throw logic_error("moving");
release_blocks();
void Train::unplace()
{
if(controller->get_speed())
- throw InvalidState("Must be stopped before unplacing");
+ throw logic_error("moving");
release_blocks();
Train *other_train = block->get_train();
int other_entry = other_train->get_entry_to_block(*block);
if(other_entry<0)
- throw LogicError("Block reservation inconsistency");
+ throw logic_error("block reservation inconsistency");
unsigned exit = block.reverse().entry();
unsigned other_exit = BlockIter(block.block(), other_entry).reverse().entry();
const Vehicle::Axle &Vehicle::get_fixed_axle(unsigned i) const
{
if(i>=axles.size())
- throw InvalidParameterValue("Axle index out of range");
+ throw out_of_range("Vehicle::get_fixed_axle");
return axles[i];
}
const Vehicle::Bogie &Vehicle::get_bogie(unsigned i) const
{
if(i>=bogies.size())
- throw InvalidParameterValue("Bogie index out of range");
+ throw out_of_range("Vehicle::get_bogie");
return bogies[i];
}
const Vehicle::Axle &Vehicle::get_bogie_axle(unsigned i, unsigned j) const
{
if(i>=bogies.size())
- throw InvalidParameterValue("Bogie index out of range");
+ throw out_of_range("Vehicle::get_bogie_axle");
if(j>=bogies[i].axles.size())
- throw InvalidParameterValue("Axle index out of range");
+ throw out_of_range("Vehicle::get_bogie_axle");
return bogies[i].axles[j];
}
const Vehicle::Rod &Vehicle::get_rod(unsigned i) const
{
if(i>=rods.size())
- throw InvalidParameterValue("Rod index out of range");
+ throw out_of_range("Vehicle::get_rod");
return rods[i];
}
#include <msp/core/maputils.h>
+#include <msp/strings/format.h>
#include "vehicletype.h"
using namespace std;
const VehicleType::Axle &VehicleType::get_fixed_axle(unsigned i) const
{
if(i>=axles.size())
- throw InvalidParameterValue("Axle index out of range");
+ throw out_of_range("VehicleType::get_fixed_axle");
return axles[i];
}
const VehicleType::Bogie &VehicleType::get_bogie(unsigned i) const
{
if(i>=bogies.size())
- throw InvalidParameterValue("Axle index out of range");
+ throw out_of_range("VehicleType::get_bogie");
return bogies[i];
}
const VehicleType::Axle &VehicleType::get_bogie_axle(unsigned i, unsigned j) const
{
if(i>=bogies.size())
- throw InvalidParameterValue("Axle index out of range");
+ throw out_of_range("VehicleType::get_bogie_axle");
if(j>=bogies[i].axles.size())
- throw InvalidParameterValue("Axle index out of range");
+ throw out_of_range("VehicleType::get_bogie_axle");
return bogies[i].axles[j];
}
const VehicleType::Rod &VehicleType::get_rod(unsigned i) const
{
if(i>=rods.size())
- throw InvalidParameterValue("Rod index out of range");
+ throw out_of_range("VehicleType::get_rod");
return rods[i];
}
else if(s=="SLIDE_X")
l = VehicleType::Rod::SLIDE_X;
else
- throw LexicalError("Invalid value for Rod::Limit");
+ throw lexical_error(format("conversion of '%s' to Rod::Limit", s));
}
} // namespace R2C2
void Zone::add_track(Track &track)
{
if(!is_valid(track))
- throw InvalidParameterValue("Can't add track to zone");
+ throw logic_error("unconnected");
tracks.insert(&track);
}
if(!ok)
{
if(first)
- throw InvalidParameterValue("Cound not add any tracks to zone");
+ throw logic_error("unconnected");
return pending.empty();
}
Train &train = server.layout.get_train(pkt.address);
train.set_control(pkt.control, pkt.value);
}
- catch(const Exception &e)
+ catch(const exception &e)
{
error(e.what());
}
if(((pkt.functions^train.get_functions())>>i)&1)
train.set_function(i, (pkt.functions>>i)&1);
}
- catch(const Exception &e)
+ catch(const exception &e)
{
error(e.what());
}
train.set_route(&route);
}
}
- catch(const Exception &e)
+ catch(const exception &e)
{
error(e.what());
}
#include <gtkmm/scrolledwindow.h>
#include <gtkmm/separator.h>
+#include <msp/core/getopt.h>
#include <msp/net/resolve.h>
#include <msp/time/units.h>
#include "mainpanel.h"
gtk(argc, argv)
{
if(argc<2)
- throw UsageError("No address given");
+ throw usage_error("No address given");
DataFile::load(catalogue, "locos.dat");