.. _program_listing_file__tmp_ws_src_ecl_core_ecl_sigslots_include_ecl_sigslots_topic.hpp: Program Listing for File topic.hpp ================================== |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/ecl_core/ecl_sigslots/include/ecl/sigslots/topic.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /***************************************************************************** ** Ifdefs *****************************************************************************/ #ifndef ECL_SIGSLOTS_TOPIC_HPP_ #define ECL_SIGSLOTS_TOPIC_HPP_ /***************************************************************************** ** Includes *****************************************************************************/ #include #include #include /***************************************************************************** ** Namespaces *****************************************************************************/ namespace ecl { /***************************************************************************** ** Forward Declarations *****************************************************************************/ template class SigSlot; /***************************************************************************** ** Interface *****************************************************************************/ template class ECL_LOCAL Topic { public: /********************* ** Typedefs **********************/ typedef std::set*> Subscribers; Topic(const std::string& name) : topic_name(name) {} const Subscribers* subscribers() const { return &topic_subscribers; } void addSubscriber(SigSlot* sigslot) { topic_subscribers.insert(sigslot); } void addPublisher(SigSlot* sigslot) { topic_publishers.insert(sigslot); } void disconnect(SigSlot* sigslot) { typename std::set*>::const_iterator iter = topic_publishers.find(sigslot); if ( iter != topic_publishers.end() ) { topic_publishers.erase(iter); } iter = topic_subscribers.find(sigslot); if ( iter != topic_subscribers.end() ) { topic_subscribers.erase(iter); } } bool empty() const { return ( ( topic_publishers.size() == 0 ) && ( topic_subscribers.size() == 0 ) ); } /********************* ** Streaming **********************/ template friend OutputStream& operator<<(OutputStream &ostream , const Topic& topic); private: std::string topic_name; std::set*> topic_publishers; std::set*> topic_subscribers; }; /***************************************************************************** ** Implementation [Streaming] *****************************************************************************/ template OutputStream& operator<<(OutputStream &ostream , const Topic &topic) { ostream << " Name: " << topic.topic_name << "\n"; ostream << " # Subscribers: " << topic.topic_subscribers.size() << "\n"; ostream << " # Publishers : " << topic.topic_publishers.size() << "\n"; ostream.flush(); return ostream; } } // namespace ecl #endif /* ECL_SIGSLOTS_TOPIC_HPP_ */