Go to the documentation of this file.00001
00010
00011
00012
00013
00014 #ifndef ECL_SIGSLOTS_MANAGER_HPP_
00015 #define ECL_SIGSLOTS_MANAGER_HPP_
00016
00017
00018
00019
00020
00021 #include <iostream>
00022 #include <map>
00023 #include <string>
00024 #include <ecl/exceptions/standard_exception.hpp>
00025 #include <ecl/config/macros.hpp>
00026 #include <ecl/utilities/void.hpp>
00027 #include "topic.hpp"
00028
00029
00030
00031
00032
00033 namespace ecl {
00034
00035
00036
00037
00048 template<typename Data = Void>
00049 class SigSlotsManager {
00050 public:
00051
00052 friend class SigSlot<Data>;
00053
00059 static void printStatistics() {
00060 std::cout << "Topics" << std::endl;
00061 typename std::map< std::string, Topic<Data> >::iterator iter;
00062 for ( iter = topics().begin(); iter != topics().end(); ++iter ) {
00063 std::cout << iter->second;
00064 }
00065 }
00066
00067 private:
00071 typedef typename Topic<Data>::Subscribers Subscribers;
00072
00082 static const Subscribers* connectSignal(const std::string& topic, SigSlot<Data>* sigslot) {
00083
00084
00085
00086
00087
00088 std::pair< typename std::map< std::string, Topic<Data> >::iterator,bool> ret = topics().insert( std::pair< std::string, Topic<Data> >(topic, Topic<Data>(topic)) );
00089 Topic<Data>& current_topic = (ret.first)->second;
00090 current_topic.addPublisher(sigslot);
00091 return current_topic.subscribers();
00092 }
00093
00101 static void connectSlot(const std::string& topic, SigSlot<Data>* sigslot) {
00102
00103
00104
00105
00106
00107 std::pair< typename std::map< std::string, Topic<Data> >::iterator,bool> ret = topics().insert(std::pair< std::string, Topic<Data> >(topic, Topic<Data>(topic)) );
00108 Topic<Data>& current_topic = (ret.first)->second;
00109 current_topic.addSubscriber(sigslot);
00110 }
00111
00120 static void disconnect(const std::string& topic, SigSlot<Data>* sigslot) {
00121 typename std::map<std::string, Topic<Data> >::iterator iter = topics().find(topic);
00122 if ( iter != topics().end() ) {
00123 iter->second.disconnect(sigslot);
00124 }
00125 if ( iter->second.empty() ) {
00126 topics().erase(iter);
00127 }
00128 }
00129
00136 static bool isTopic(const std::string& topic) {
00137 return !( topics().find(topic) == topics().end() );
00138 }
00139
00147 static std::map< std::string, Topic<Data> >& topics() {
00148 static std::map< std::string, Topic<Data> > topic_list;
00149 return topic_list;
00150 }
00151
00162 static const Subscribers& subscribers(const std::string& topic) {
00163 typename std::map< std::string, Topic<Data> >::const_iterator iter = topics().find(topic);
00164
00165
00166
00167
00168
00169
00170 return *iter->second.subscribers();
00171 }
00172
00173 };
00174
00175 }
00176
00177
00178 #endif