diff options
author | randomdan <randomdan@localhost> | 2013-03-15 00:39:41 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2013-03-15 00:39:41 +0000 |
commit | 02860860e0b9d31ba29b2d70ab7314b2244e1968 (patch) | |
tree | 21b1b4de4204b2aba8fd91e863d2b8e38062ef62 | |
parent | Move component loader constructor/destructors into their own unique machine g... (diff) | |
download | project2-02860860e0b9d31ba29b2d70ab7314b2244e1968.tar.bz2 project2-02860860e0b9d31ba29b2d70ab7314b2244e1968.tar.xz project2-02860860e0b9d31ba29b2d70ab7314b2244e1968.zip |
Add a rowset that lists the routes configured in a programable router
-rw-r--r-- | project2/cgi/cgiProgRouter.cpp | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/project2/cgi/cgiProgRouter.cpp b/project2/cgi/cgiProgRouter.cpp index 9218c89..ff7c864 100644 --- a/project2/cgi/cgiProgRouter.cpp +++ b/project2/cgi/cgiProgRouter.cpp @@ -36,7 +36,7 @@ class RoutingTable { std::string routeScriptPath; const std::string & present(const std::string & path, VarMap & vars) const { - BOOST_FOREACH(const auto route, routes) { + BOOST_FOREACH(const auto & route, routes) { vars.clear(); if (route->matches(path, vars)) { return route->present; @@ -74,12 +74,13 @@ class RoutingTable { public: Route(ScriptNodePtr s) : SourceObject(s), - present(s->value("present").as<std::string>()) + present(s->value("present").as<std::string>()), + path(s->value("path").as<std::string>()) { - boost::filesystem::path path = s->value("path").as<std::string>(); - boost::filesystem::path::iterator p = path.begin(); + boost::filesystem::path fspath = path; + boost::filesystem::path::iterator p = fspath.begin(); p++; - while(p != path.end() && p->string() != ".") { + while(p != fspath.end() && p->string() != ".") { switch (p->string().front()) { case '{': routeElems.push_back(new RouteVar(p->string())); @@ -105,6 +106,7 @@ class RoutingTable { typedef std::list<RouteElemPtr> RouteElems; RouteElems routeElems; const std::string present; + const std::string path; }; typedef boost::intrusive_ptr<Route> RoutePtr; @@ -184,3 +186,34 @@ class ProgRouter : public Router { }; DECLARE_CUSTOM_COMPONENT_LOADER("progRouter", ProgRouter, ProgRouterLoader, RouterLoader); + +class Routes : public RowSet { + public: + Routes(ScriptNodePtr s) : + RowSet(s) { } + class RouteRowState : public RowState { + public: + RouteRowState() { + columns.insert(new Column(0, "present")); + columns.insert(new Column(1, "path")); + fields.resize(2); + } + const Columns & getColumns() const { return columns; } + mutable Columns columns; + friend class Routes; + }; + void execute(const Glib::ustring & filter, const RowProcessor * rp) const + { + RouteRowState rs; + BOOST_FOREACH(const auto & r, ProgRouterLoader::routingTable.routes) { + if (boost::algorithm::starts_with(r->path, filter)) { + rs.fields[0] = VariableType(r->present); + rs.fields[1] = VariableType(r->path); + rs.process(rp); + } + } + } +}; + +DECLARE_LOADER("routes", Routes); + |