diff options
Diffstat (limited to 'cpp/broker/inc/TopicExchange.h')
-rw-r--r-- | cpp/broker/inc/TopicExchange.h | 71 |
1 files changed, 55 insertions, 16 deletions
diff --git a/cpp/broker/inc/TopicExchange.h b/cpp/broker/inc/TopicExchange.h index d9ff62ecc6..68a4026ee7 100644 --- a/cpp/broker/inc/TopicExchange.h +++ b/cpp/broker/inc/TopicExchange.h @@ -18,7 +18,7 @@ #ifndef _TopicExchange_ #define _TopicExchange_ -#include <map> +#include <tr1/unordered_map> #include <vector> #include "Exchange.h" #include "FieldTable.h" @@ -28,28 +28,67 @@ namespace qpid { namespace broker { - class TopicExchange : public virtual Exchange{ - const string name; - std::map<string, std::vector<Queue::shared_ptr> > bindings;//NOTE: pattern matching not yet supported - qpid::concurrent::MonitorImpl lock; - public: - static const std::string typeName; - - TopicExchange(const string& name); +/** A vector of string tokens */ +class Tokens : public std::vector<std::string> { + public: + Tokens() {}; + // Default copy, assign, dtor are sufficient. + + /** Tokenize s, provides automatic conversion of string to Tokens */ + Tokens(const std::string& s) { operator=(s); } + /** Tokenize s */ + Tokens & operator=(const std::string& s); + + struct Hash { size_t operator()(const Tokens&) const; }; + typedef std::equal_to<Tokens> Equal; +}; + +/** + * Tokens that have been normalized as a pattern and can be matched + * with topic Tokens. Normalized meands all sequences of mixed * and + * # are reduced to a series of * followed by at most one #. + */ +class TopicPattern : public Tokens +{ + public: + TopicPattern() {} + // Default copy, assign, dtor are sufficient. + TopicPattern(const Tokens& tokens) { operator=(tokens); } + TopicPattern(const std::string& str) { operator=(str); } + TopicPattern& operator=(const Tokens&); + TopicPattern& operator=(const std::string& str) { operator=(Tokens(str)); } + + /** Match a topic */ + bool match(const std::string& topic) { return match(Tokens(topic)); } + bool match(const Tokens& topic) const; + + private: + void normalize(); +}; + +class TopicExchange : public virtual Exchange{ + typedef std::tr1::unordered_map<TopicPattern, Queue::vector, TopicPattern::Hash> BindingMap; + BindingMap bindings; + qpid::concurrent::MonitorImpl lock; + + public: + static const std::string typeName; + + TopicExchange(const string& name); - inline virtual const string& getName(){ return name; } + virtual void bind(Queue::shared_ptr queue, const string& routingKey, qpid::framing::FieldTable* args); - virtual void bind(Queue::shared_ptr queue, const string& routingKey, qpid::framing::FieldTable* args); + virtual void unbind(Queue::shared_ptr queue, const string& routingKey, qpid::framing::FieldTable* args); + + virtual void route(Message::shared_ptr& msg, const string& routingKey, qpid::framing::FieldTable* args); + + virtual ~TopicExchange(); +}; - virtual void unbind(Queue::shared_ptr queue, const string& routingKey, qpid::framing::FieldTable* args); - virtual void route(Message::shared_ptr& msg, const string& routingKey, qpid::framing::FieldTable* args); - virtual ~TopicExchange(); - }; } } - #endif |