void Vehicle::attach_back(Vehicle &veh)
{
if(next || veh.prev)
- throw InvalidState("Already attached");
+ throw attachment_error("already attached");
next = &veh;
veh.prev = this;
void Vehicle::attach_front(Vehicle &veh)
{
if(prev || veh.next)
- throw InvalidState("Already attached");
+ throw attachment_error("already attached");
prev = &veh;
veh.next = this;
void Vehicle::detach_back()
{
if(!next)
- throw InvalidState("Not attached");
+ throw attachment_error("not attached");
next->prev = 0;
next = 0;
void Vehicle::detach_front()
{
if(!prev)
- throw InvalidState("Not attached");
+ throw attachment_error("not attached");
prev->next = 0;
prev = 0;
class Layout;
class Track;
+class attachment_error: public std::logic_error
+{
+public:
+ attachment_error(const std::string &w): std::logic_error(w) { }
+ virtual ~attachment_error() throw() { }
+};
+
+
class Vehicle
{
public: