-/* $Id: package.cpp,v 1.4 2006-01-09 13:43:59 adam Exp $
+/* $Id: package.cpp,v 1.5 2006-01-09 13:53:13 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include "package.hpp"
yp2::Package::Package()
- :
-#if ROUTE_POS
- m_route_pos(0),
-#else
- m_filter(0), m_router(0),
-#endif
- m_data(0)
+ : m_route_pos(0), m_data(0)
{
}
yp2::Package::~Package()
{
-#if ROUTE_POS
delete m_route_pos;
-#endif
}
yp2::Package::Package(yp2::Session &session, yp2::Origin &origin)
: m_session(session), m_origin(origin),
-#if ROUTE_POS
- m_route_pos(0),
-#else
- m_filter(0), m_router(0),
-#endif
- m_data(0)
+ m_route_pos(0), m_data(0)
{
}
yp2::Package & yp2::Package::copy_filter(const Package &p)
{
-#if ROUTE_POS
m_route_pos = p.m_route_pos->clone();
-#else
- m_router = p.m_router;
- m_filter = p.m_filter;
-#endif
return *this;
}
void yp2::Package::move()
{
-#if ROUTE_POS
if (m_route_pos)
{
const filter::Base *next_filter = m_route_pos->move();
if (next_filter)
next_filter->process(*this);
}
-#else
- m_filter = m_router->move(m_filter, this);
- if (m_filter)
- m_filter->process(*this);
-#endif
}
yp2::Session & yp2::Package::session()
yp2::Package & yp2::Package::router(const yp2::Router &router)
{
-#if ROUTE_POS
m_route_pos = router.createpos();
-#else
- m_filter = 0;
- m_router = &router;
-#endif
return *this;
}
-/* $Id: package.hpp,v 1.12 2006-01-09 13:43:59 adam Exp $
+/* $Id: package.hpp,v 1.13 2006-01-09 13:53:13 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
Session m_session;
Origin m_origin;
-#if ROUTE_POS
RoutePos *m_route_pos;
-#else
- const filter::Base *m_filter;
- const Router *m_router;
-#endif
+
int m_data;
yazpp_1::GDU m_request_gdu;
-/* $Id: router.hpp,v 1.8 2006-01-09 13:43:59 adam Exp $
+/* $Id: router.hpp,v 1.9 2006-01-09 13:53:13 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
#include <string>
#include <stdexcept>
-#define ROUTE_POS 1
-
namespace yp2
{
namespace filter {
class Base;
}
-#if ROUTE_POS
class RoutePos;
-#else
- class Package;
-#endif
class RouterException : public std::runtime_error {
public:
Router(){};
virtual ~Router(){};
-#if ROUTE_POS
virtual RoutePos *createpos() const = 0;
-#else
- /// determines next Filter to use from current Filter and Package
- virtual const filter::Base *move(const filter::Base *filter,
- const Package *package) const = 0;
-#endif
};
-
-#if ROUTE_POS
- class RoutePos {
+ class RoutePos : boost::noncopyable {
public:
virtual const filter::Base *move() = 0;
virtual RoutePos *clone() = 0;
virtual ~RoutePos() {};
};
-#endif
-
}
#endif
/*
-/* $Id: router_chain.cpp,v 1.3 2006-01-09 13:43:59 adam Exp $
+/* $Id: router_chain.cpp,v 1.4 2006-01-09 13:53:13 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
friend class RouterChain::Pos;
std::list<const filter::Base *> m_filter_list;
};
-
-#if ROUTE_POS
class RouterChain::Pos : public RoutePos {
public:
virtual const filter::Base *move();
std::list<const filter::Base *>::const_iterator it;
yp2::RouterChain::Rep *m_p;
};
-#endif
-};
+}
yp2::RouterChain::RouterChain() : m_p(new yp2::RouterChain::Rep)
{
{
}
-#if ROUTE_POS
const yp2::filter::Base *yp2::RouterChain::Pos::move()
{
if (it == m_p->m_filter_list.end())
yp2::RouterChain::Pos::~Pos()
{
}
-#else
-const yp2::filter::Base *yp2::RouterChain::move(const filter::Base *filter,
- const Package *package) const {
- std::list<const filter::Base *>::const_iterator it;
- it = m_p->m_filter_list.begin();
- if (filter)
- {
- for (; it != m_p->m_filter_list.end(); it++)
- if (*it == filter)
- {
- it++;
- break;
- }
- }
- if (it == m_p->m_filter_list.end())
- {
- //throw RouterException("no routing rules known");
- return 0;
- }
- return *it;
-}
-#endif
yp2::RouterChain & yp2::RouterChain::append(const filter::Base &filter)
{
-/* $Id: router_chain.hpp,v 1.4 2006-01-09 13:43:59 adam Exp $
+/* $Id: router_chain.hpp,v 1.5 2006-01-09 13:53:13 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
public:
RouterChain();
virtual ~RouterChain();
-#if ROUTE_POS
virtual RoutePos *createpos() const;
-#else
- virtual const filter::Base *move(const filter::Base *filter,
- const Package *package) const;
-#endif
RouterChain & append(const filter::Base &filter);
private:
boost::scoped_ptr<Rep> m_p;
-/* $Id: router_flexml.cpp,v 1.11 2006-01-09 13:43:59 adam Exp $
+/* $Id: router_flexml.cpp,v 1.12 2006-01-09 13:53:13 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
std::string m_start_route;
-#if ROUTE_POS
-#else
- std::map<std::string,
- RouterFleXML::Route>::iterator m_cur_route_it;
-
- std::list<boost::shared_ptr <const yp2::filter::Base> >::iterator m_cur_filter_it;
-#endif
void parse_xml_config_dom(xmlDocPtr doc);
bool check_element_yp2(const xmlNode *ptr,
FactoryFilter *m_factory; // TODO shared_ptr
};
-#if ROUTE_POS
class RouterFleXML::Pos : public RoutePos {
public:
virtual const filter::Base *move();
RouterFleXML::Route>::iterator m_route_it;
std::list<boost::shared_ptr <const yp2::filter::Base> >::iterator m_filter_it;
};
-#endif
}
const xmlNode* yp2::RouterFleXML::Rep::jump_to_children(const xmlNode* node,
{
}
-#if ROUTE_POS
const yp2::filter::Base *yp2::RouterFleXML::Pos::move()
{
if (m_filter_it == m_route_it->second.m_list.end())
{
}
-#else
-const yp2::filter::Base *
-yp2::RouterFleXML::move(const yp2::filter::Base *filter,
- const yp2::Package *package) const
-{
- if (!filter)
- { // Initial move. find start route
- m_p->m_cur_route_it = m_p->m_routes.find("start");
- if (m_p->m_cur_route_it == m_p->m_routes.end())
- return 0;
- m_p->m_cur_filter_it = m_p->m_cur_route_it->second.m_list.begin();
- }
- else
- {
- const yp2::filter::Base *f = (*m_p->m_cur_filter_it).get();
- if (f != filter)
- (m_p->m_cur_filter_it)++;
- else
- {
- // TOTO: should search all routes (not only start)!
- m_p->m_cur_filter_it = m_p->m_cur_route_it->second.m_list.begin();
- while (m_p->m_cur_filter_it !=
- m_p->m_cur_route_it->second.m_list.end())
- {
- const yp2::filter::Base *f = (*m_p->m_cur_filter_it).get();
- (m_p->m_cur_filter_it)++;
- if (filter == f)
- break;
- }
- }
- }
- if (m_p->m_cur_filter_it == m_p->m_cur_route_it->second.m_list.end())
- return 0;
- return (*m_p->m_cur_filter_it).get();
-}
-#endif
/*
* Local variables:
-/* $Id: router_flexml.hpp,v 1.11 2006-01-09 13:43:59 adam Exp $
+/* $Id: router_flexml.hpp,v 1.12 2006-01-09 13:53:13 adam Exp $
Copyright (c) 2005, Index Data.
%LICENSE%
~RouterFleXML();
-#if ROUTE_POS
virtual RoutePos *createpos() const;
-#else
- /// determines next Filter to use from current Filter and Package
- virtual const filter::Base *move(const filter::Base *filter,
- const Package *package) const;
-#endif
class XMLError : public std::runtime_error {
public:
XMLError(const std::string msg) :