SubjectImp.h

Go to the documentation of this file.
00001 /*
00002  * The information in this file is
00003  * Copyright(c) 2007 Ball Aerospace & Technologies Corporation
00004  * and is subject to the terms and conditions of the
00005  * GNU Lesser General Public License Version 2.1
00006  * The license text is available from   
00007  * http://www.gnu.org/licenses/lgpl.html
00008  */
00009 
00010 #ifndef SUBJECTIMP_H
00011 #define SUBJECTIMP_H
00012 
00013 #include "SafeSlot.h"
00014 #include "TypesFile.h"
00015 
00016 #include <boost/any.hpp>
00017 #include <list>
00018 #include <map>
00019 #include <string>
00020 #include <vector>
00021 
00022 class SubjectImpPrivate;
00023 
00024 /**
00025  *  Implementation of the interface for generalized registration of
00026  *  objects intereseted in mutations of the subclasses of this interface.
00027  */
00028 class SubjectImp
00029 {
00030    friend class Signal::SignalValue;
00031 
00032 public:
00033    SubjectImp();
00034    virtual ~SubjectImp();
00035 
00036    virtual bool attach(const std::string& signal, const Slot& slot);
00037    virtual bool detach(const std::string& signal, const Slot& slot);
00038 
00039    /**
00040     *  Inherited obligation from TypeAwareObject. Allow observers to
00041     *  determine the type of mutating object notifying them.
00042     *
00043     *  @return  The name of the subclass of this interface.
00044     */
00045    virtual const std::string& getObjectType() const;
00046 
00047    /**
00048     *  Inherited obligation from TypeAwareObject. Allow observers to
00049     *  determine the type of mutating object notifying them.
00050     *
00051     *  @param   className
00052     *           Name of the class which is being inquired about.
00053     *
00054     *  @return  True if the subclass matches of this interface matches or
00055     *           is a parent of the class identified in the argument.
00056     */
00057    virtual bool isKindOf(const std::string& className) const;
00058 
00059    /**
00060     *  Gets the list of Slots attached to the specified signal.
00061     *
00062     *  @param   signal
00063     *           The signal to get the slots for.
00064     *
00065     *  @return  A (possibly empty) list containing slots attached to the 
00066     *           specified signal.
00067     */
00068    const std::list<SafeSlot>& getSlots(const std::string& signal);
00069 
00070    /**
00071     *  Indicates whether the Subject's notification mechanism is enabled or not.
00072     *
00073     *  @return   true if the Subject's notification is enabled, or false otherwise.
00074     */
00075    bool signalsEnabled() const;
00076 
00077 protected:
00078    void notify(const std::string& signal, const boost::any& data = boost::any());
00079 
00080    /**
00081     *  Allows the notification of signals by a Subject to be enabled or disabled.
00082     *
00083     *  @param   enabled
00084     *           Controls whether the Subject will notify or not when its notify
00085     *           method is called.
00086     */
00087    void enableSignals(bool enabled);
00088 
00089    SubjectImpPrivate* mpImpPrivate;
00090 };
00091 
00092 #define SUBJECTADAPTEREXTENSION_CLASSES
00093 
00094 #define SUBJECTADAPTER_METHODS(impClass) \
00095    bool attach(const std::string& signal, const Slot& slot) \
00096    { \
00097       return impClass::attach(signal, slot); \
00098    } \
00099    bool detach(const std::string& signal, const Slot& slot) \
00100    { \
00101       return impClass::detach(signal, slot); \
00102    } \
00103    private: \
00104    void enableSignals(bool enabled) \
00105    { \
00106       impClass::enableSignals(enabled); \
00107    } \
00108    public: \
00109    bool signalsEnabled() const \
00110    { \
00111       return impClass::signalsEnabled(); \
00112    }
00113 
00114 #endif

Software Development Kit - Opticks 4.9.0 Build 16218