Listing 6
(a)class Requisite { public: int resource_type; time_t range[2]; }; class Request { public: std::list<Requisite> requisites; int user_id; int event_type; }; int schedule(const Request &request, std::list<Reservation> &reservations);(b)
template<class Src, class Dst> class Error { public: std::string description; Handle source; Chain<Src, Dst> chain; };(c)
try { schedule(req, res); } catch (Error<Request, int> &e) { // ... } catch (Error<Request, User> &e) { // ... } catch (Error<Request, time_t[2]> &e) { // ... }(d)
template<class Src> class Handle_Link : public Typed_Link<Src, Handle> { public: Handle &traverse(Src &id) { static Handle h(id); return h = Handle(id); } //... }; template<class Src> class Error_Base { public: virtual Chain<Src,Handle> get_link(void) = 0; std::string description; Handle source; // ... }; template<class Src, class Dst> class Error : public Error_Base<Src> { public: Chain<Src,Handle> get_link(void) { return chain + Handle_Link<Dst>(); } Chain<Src, Dst> chain; // ... };(e)
... } catch (Error_Base<Request> &e) { Chain<Request, Handle> c = e.get_link(); if (c.get_distance(some_user) < c.get_distance(some_requisite)) { // smells like trouble in the requisite! } }