/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Calibration/facilities/facilities-00-00-04/facilities/Observer.h

Go to the documentation of this file.
00001 //## begin module%352D11EA00FB.cm preserve=no
00002 //        %X% %Q% %Z% %W%
00003 //## end module%352D11EA00FB.cm
00004 
00005 //## Module: Observer%352D11EA00FB; Package specification
00006 //      Implementation of the Observer class.
00007 //## Subsystem: facilities%3550CC6801AC
00008 //## Source file: D:\code\glastsim\facilities\Observer.h
00009 
00010 #ifndef Observer_h
00011 #define Observer_h 1
00012 
00013 #include "facilities/Adapter.h"
00014 //## begin module%352D11EA00FB.declarations preserve=yes
00015 #ifdef _MSC_VER
00016 # pragma warning(disable: 4786)
00017 #endif
00018 
00019 #include <vector>
00020 //## end module%352D11EA00FB.declarations
00021 
00022 
00023 //## Class: Observer%352D0D8F02E2
00024 //      Abstract observer class. Encapsulates the update()
00025 //      behavior.
00026 //## Category: facilities%3550CC5302A6
00027 //## Subsystem: facilities%3550CC6801AC
00028 //## Persistence: Transient
00029 //## Cardinality/Multiplicity: n
00030 
00031 class Observer 
00032 {
00033   public:
00034     //## Constructors (specified)
00035       //## Operation: Observer%894312585
00036       //        constructor
00037       Observer ()
00038         //## begin Observer::Observer%894312585.initialization preserve=yes
00039         //## end Observer::Observer%894312585.initialization
00040       {
00041         //## begin Observer::Observer%894312585.body preserve=yes
00042         //## end Observer::Observer%894312585.body
00043       }
00044 
00045 
00046     //## Other Operations (specified)
00047       //## Operation: update%892143866
00048       //        Encapsulate the update behavior for the Subject-Observer
00049       //        pattern. Respond to a change in the state of the Subject
00050       //        to which this observer (when instatiated) is attached.
00051       virtual void update () = 0;
00052 
00053   protected:
00054 
00055 };
00056 
00057 //## Class: Subject%352D0AF10220; Abstract
00058 //      Abstract subject pattern. Follows Observer behavioral
00059 //      pattern described in 'Design Patterns'.
00060 //## Category: facilities%3550CC5302A6
00061 //## Subsystem: facilities%3550CC6801AC
00062 //## Persistence: Transient
00063 //## Cardinality/Multiplicity: n
00064 
00065 //## Uses: <unnamed>%352D101A02D4;Observer { -> }
00066 
00067 class Subject 
00068 {
00069   public:
00070     //## Constructors (specified)
00071       //## Operation: Subject%894312586
00072       //        constructor
00073       Subject ()
00074         //## begin Subject::Subject%894312586.initialization preserve=yes
00075         : m_observers()
00076         //## end Subject::Subject%894312586.initialization
00077       {
00078         //## begin Subject::Subject%894312586.body preserve=yes
00079         //## end Subject::Subject%894312586.body
00080       }
00081 
00082 
00083     //## Other Operations (specified)
00084       //## Operation: attach%892143867
00085       //        Attach an observer to this subject.
00086       void attach (Observer* anObserver)
00087       {
00088         //## begin Subject::attach%892143867.body preserve=yes
00089           m_observers.push_back(anObserver);
00090         //## end Subject::attach%892143867.body
00091       }
00092 
00093       //## Operation: detach%892143868
00094       //        Detach an observer from this subject.
00095       void detach (Observer* )
00096       {
00097         //## begin Subject::detach%892143868.body preserve=yes
00098           //std::vector<Observer*>::const_iterator      it = m_observers.find(anObserver);
00099           //if (it != m_observers.end())        m_observers.erase(it);
00100         //## end Subject::detach%892143868.body
00101       }
00102 
00103       //## Operation: notify%892143869
00104       //        Notify all subjects of a change.
00105       void notify ()
00106       {
00107         //## begin Subject::notify%892143869.body preserve=yes
00108           std::vector<Observer*>::iterator      it = m_observers.begin();
00109           while (it != m_observers.end()) {
00110             if (*it)    (*it)->update();
00111             it++;
00112           }
00113         //## end Subject::notify%892143869.body
00114       }
00115 
00116   protected:
00117   private:
00118   private:  //## implementation
00119     // Data Members for Class Attributes
00120 
00121       //## Attribute: m_observers%352D1996009B
00122       //        List of all of the observers of this subject.
00123       //## begin Subject::m_observers%352D1996009B.attr preserve=no  private: set<Observer*> {U} 
00124       std::vector<Observer*> m_observers;
00125       //## end Subject::m_observers%352D1996009B.attr
00126 
00127 };
00128 
00129 //## Class: ObserverAdapter%3552473D03A8; Parameterized Class
00130 //      Subclass of Observer which incorporates a callback
00131 //      Adapter to another object.
00132 //## Category: facilities%3550CC5302A6
00133 //## Subsystem: facilities%3550CC6801AC
00134 //## Persistence: Transient
00135 //## Cardinality/Multiplicity: n
00136 
00137 template <class T, class Y = int>
00138 class ObserverAdapter : public Observer  //## Inherits: <unnamed>%3552488300D6
00139 {
00140   public:
00141     //## Constructors (specified)
00142       //## Operation: ObserverAdapter%894312604
00143       //        constructor
00144       ObserverAdapter (Adapter<Y>* anAdapter = 0)
00145         //## begin ObserverAdapter::ObserverAdapter%894312604.initialization preserve=yes
00146         : itsAdapter(anAdapter)
00147         //## end ObserverAdapter::ObserverAdapter%894312604.initialization
00148       {
00149         //## begin ObserverAdapter::ObserverAdapter%894312604.body preserve=yes
00150         //## end ObserverAdapter::ObserverAdapter%894312604.body
00151       }
00152 
00153       virtual ~ObserverAdapter ()
00154       {
00155                 delete itsAdapter;
00156                 itsAdapter = 0;
00157       }
00158 
00159 
00160     //## Other Operations (specified)
00161       //## Operation: setAdapter%894312605
00162       //        sets the adapter to use
00163       void setAdapter (Adapter<Y>* anAdapter = 0)
00164       {
00165         //## begin ObserverAdapter::setAdapter%894312605.body preserve=yes
00166         delete itsAdapter;
00167         itsAdapter = anAdapter;
00168         //## end ObserverAdapter::setAdapter%894312605.body
00169       }
00170 
00171       //## Operation: getAdapter%894312606
00172       //        access to the adapter object
00173       Adapter<Y>* getAdapter ()
00174       {
00175         //## begin ObserverAdapter::getAdapter%894312606.body preserve=yes
00176         return itsAdapter;
00177         //## end ObserverAdapter::getAdapter%894312606.body
00178       }
00179 
00180       //## Operation: update%894312607
00181       //        update overload. calls itsAdapter to execute the adapted
00182       //        function
00183       void update ()
00184       {
00185         //## begin ObserverAdapter::update%894312607.body preserve=yes
00186         if (itsAdapter) (*itsAdapter)();
00187         //## end ObserverAdapter::update%894312607.body
00188       }
00189 
00190   protected:
00191   private:
00192   private:  //## implementation
00193     // Data Members for Associations
00194 
00195       //## Association: facilities::<unnamed>%3550D15301CA
00196       //## Role: ObserverAdapter::itsAdapter%3550D1540059
00197       //        adapter to call upon notification of a change in a
00198       //        Subject
00199       //## begin ObserverAdapter::itsAdapter%3550D1540059.role preserve=no  private: ActionAdapter { -> 0..1RHN}
00200       Adapter<Y> *itsAdapter;
00201       //## end ObserverAdapter::itsAdapter%3550D1540059.role
00202 
00203 };
00204 
00205 
00206 
00207 #endif

Generated on Tue Nov 29 22:57:55 2016 for BOSS_7.0.2 by  doxygen 1.4.7