#include "DeliverableObject.h" #include "boost/functional/hash.hpp" #include "common/container/SubscriberSet.h" #include "event/ObjectListener.h" namespace ubeeme { namespace moversight { /** * @brief Constructor. */ DeliverableObject::DeliverableObject() : name(""), recipient(NULL) { } /** * @brief Destructor */ DeliverableObject::~DeliverableObject(){ } /** * @brief Copy Constructor. * @param other Object to copy. */ DeliverableObject::DeliverableObject( const DeliverableObject& other) { operator=(other); } /** * @brief Assignment operator. * @param other Object to copy. * @return This object with new values. */ DeliverableObject& DeliverableObject::operator=( const DeliverableObject& other) { name = other.getName(); groups = other.getGroups(); return *this; } /** * @brief Specify that this object has to be delivered only to the given listener. * @param ol The object listener that shall receive this object. */ void DeliverableObject::deliverOnlyTo( ObjectListener* ol) { this->recipient = ol; } /** * @brief Check if this object has recipient information attached to it. * @return True, if this object has recipient information attached to it. False otherwise. */ bool DeliverableObject::hasRecipient() const { return (recipient != NULL ? true : false); } /** * @brief Remove the recipient information leaving it as a NULL value. * @return The removed recipient. * * After this operation the object can be delivered to any subscriber. */ ObjectListener* DeliverableObject::removeRecipient() { ObjectListener* tmp = recipient; recipient = NULL; return tmp; } /** * @brief Retrieve the recipient of this message. * @return The specified recipient. NULL if unspecified. * @retval NULL There was no recipient specified. */ ObjectListener* DeliverableObject::getRecipient() { return const_cast( static_cast(this->getRecipient()) ); } /** * @brief Retrieve the recipient of this message. * @return The specified recipient. NULL if unspecified. * @retval NULL There was no recipient specified. */ const ObjectListener* const DeliverableObject::getRecipient() const { return this->recipient; } /** * @brief Return this object's type name. * @return This object's type name. */ std::string DeliverableObject::getName() const { return name; } /** * @brief Set this object's type name and corresponding hash value. * * The hash value is later used within the object delivery service * to identify the list of subscribers for that object. * * @param s Type name as returned by . */ void DeliverableObject::setName( const std::string& s) { name = s; } /** * @brief Return the list of groups this object belongs to. * @return The list of groups. */ const GroupList& DeliverableObject::getGroups() const { return groups; } /** * @brief Add to the list of groups this object belongs to. * @param g The group to add. */ void DeliverableObject::addToGroup( const std::string& g) { groups.push_back( g); } /** * @brief Create and return a string representation of this object. * @return String representation of this object. */ std::string DeliverableObject::toString() const { std::stringstream buf; buf << "DeliverableObject [" << this->getName() << "]"; return buf.str(); } /** * @brief Output a string representation of this object * @param out The output stream to manipulate. * @param e The object to interpret * @return The modified output stream. */ std::ostream& operator<<( std::ostream& out, const DeliverableObject& e) { return out << e.toString(); } /** * @brief Output a string representation of this object * @param out The output stream to manipulate. * @param e The object to interpret * @return The modified output stream. */ std::ostream& operator<<( std::ostream& out, const DeliverableObject* e) { return out << e->toString(); } } }