.. _program_listing_file__tmp_ws_src_ecl_core_ecl_sigslots_include_ecl_sigslots_manager.hpp: Program Listing for File manager.hpp ==================================== |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/ecl_core/ecl_sigslots/include/ecl/sigslots/manager.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /***************************************************************************** ** Ifdefs *****************************************************************************/ #ifndef ECL_SIGSLOTS_MANAGER_HPP_ #define ECL_SIGSLOTS_MANAGER_HPP_ /***************************************************************************** ** Includes *****************************************************************************/ #include #include #include #include #include #include #include "topic.hpp" /***************************************************************************** ** Namespaces *****************************************************************************/ namespace ecl { /***************************************************************************** ** Interface *****************************************************************************/ template class SigSlotsManager { public: friend class SigSlot; static void printStatistics() { std::cout << "Topics" << std::endl; typename std::map< std::string, Topic >::iterator iter; for ( iter = topics().begin(); iter != topics().end(); ++iter ) { std::cout << iter->second; } } private: typedef typename Topic::Subscribers Subscribers; static const Subscribers* connectSignal(const std::string& topic, SigSlot* sigslot) { // Try and insert a new topic in case it doesn't already exist // In any case, we always get the iterator back (to new or existing) // // Maybe improve the efficiency of this by specifying position // refer to http://www.cplusplus.com/reference/stl/map/insert/ std::pair< typename std::map< std::string, Topic >::iterator,bool> ret = topics().insert( std::pair< std::string, Topic >(topic, Topic(topic)) ); Topic& current_topic = (ret.first)->second; current_topic.addPublisher(sigslot); return current_topic.subscribers(); } static void connectSlot(const std::string& topic, SigSlot* sigslot) { // Try and insert a new topic in case it doesn't already exist // In any case, we always get the iterator back (to new or existing) // // Maybe improve the efficiency of this by specifying position // refer to http://www.cplusplus.com/reference/stl/map/insert/ std::pair< typename std::map< std::string, Topic >::iterator,bool> ret = topics().insert(std::pair< std::string, Topic >(topic, Topic(topic)) ); Topic& current_topic = (ret.first)->second; current_topic.addSubscriber(sigslot); } static void disconnect(const std::string& topic, SigSlot* sigslot) { typename std::map >::iterator iter = topics().find(topic); if ( iter != topics().end() ) { iter->second.disconnect(sigslot); } if ( iter->second.empty() ) { topics().erase(iter); } } static bool isTopic(const std::string& topic) { return !( topics().find(topic) == topics().end() ); } static std::map< std::string, Topic >& topics() { static std::map< std::string, Topic > topic_list; return topic_list; } static const Subscribers& subscribers(const std::string& topic) { typename std::map< std::string, Topic >::const_iterator iter = topics().find(topic); /* * Note that this is called only by SigSlotsManager::connectSignal which * makes sure the topic name exists, so we don't need to do any error * handling here. */ // ecl_assert_throw( iter != topics().end(), StandardException(LOC,InvalidInputError,std::string("No sigslots topic with name:")+topic) ); return *iter->second.subscribers(); } }; } // namespace ecl #endif /* ECL_SIGSLOTS_MANAGER_HPP_ */