CGateObserver

Name

CGateObserver -- Observe changes in the gate dictionary.

Synopsis


#include <Histogrammer.h>

template <class T>
class DictionaryObserver 
{
public:
  virtual void onAdd(std::string   name,   T& item) {}
  virtual void onRemove( std::string name,    T& item) {}

};
typedef CDictionary<CGateContainer>             CGateDictionary;
typedef CGateDictionary::DictionaryIterator     CGateDictionaryIterator;
typedef DictionaryObserver<CGateContainer>      GateDictionaryObserver;

class CGateObserver : public GateDictionaryObserver {
public:
  virtual void onChange(std::string name, CGateContainer& gateContainer) = 0;
};

#include <SpecTcl.h>
class SpecTcl
{
public:
...
    void addGateDictionaryObserver(GateObserver* observer);
    void remove GateDictionaryObserver(Gateobservr* observer);
};

        

DESCRIPTION

Before looking at the documentation for the gate observer; if you are not familiar with the Observer software pattern, it's worth taking some time to udnerstand it. On introduction is available at the wikipedia at: https://en.wikipedia.org/wiki/Observer_pattern.

Gate dictionary observers allow you to become aware of changes made to the gate dictionary. The changes you can observer are:

As the synopsis shows, gate containers are added and removed fromt he gate dictionary via the SpecTcl API class SpecTcl. Observers consitute an ordered list of objects attached to the gate dictionary. When an observable change occurs, each of these observers is invoked in the order in which they were added

METHODS

The CGateObserver is derived from the more general templated base class DictionaryObserver. This section documents, not only the methods defined in CGateObserver but the methods of CDictionaryObserver a concrete class can override.

virtual void onAdd(std::string name, CGateContainer& item);

Called when a new gate container is added to the dictionary. name is the name of the item in the dictionary (this need not be but currently always is the same as the name of the gate container).

item is a reference to the gate container being added to the dictionary. The base class implements this as an empty method.

virtual void onRemove( std::string name, CGateContainer& item);

Called when an item is removed from the dictionary. At present this does not happen as gate deletion simply replaces the gate with a False gate. The name of the gate and the gate container item are passed in as parameters.

virtual = 0 void onChange(std::string name, CGateContainer& gateContainer);

Called when an item in the dictionary is changed. For the gate dictionary. This means a gate container is encapsulating a new gate object because the gate has been modified.

EXAMPLE

This toy example just prints out some text when for each gate observation. The example includes the class definition for the gate dictionary observer as well as a snippet of code that registers an instance of that observer with the SpecTcl gate dictionary.