otbMVCModel.h 2.33 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*=========================================================================

Program:   ORFEO Toolbox
Language:  C++
Date:      $Date$
Version:   $Revision$


Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.


This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
18
19
#ifndef __otbMVCModel_h
#define __otbMVCModel_h
20
21

#include <set>
22
23
#include "itkObject.h"
#include "itkObjectFactory.h"
24
25
26

namespace otb
{
27
28
29
/** \class MVCModel
 *
 * Base class for MVC based modelling. Implements the registration and
30
31
32
33
 * Unregistration of listeners, as well as the NotifyAll method. A valid listener must
 * implement a Notify() method.
 */
template <class TListener>
34
class MVCModel
35
36
{
public:
37
38
39
40
41
42
  /** Standard class typedefs */
  typedef MVCModel    Self;
  typedef itk::Object Superclass;
  typedef itk::SmartPointer<Self> Pointer;
  typedef itk::SmartPointer<const Self> ConstPointer;

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
  // Define the listener type
  typedef TListener ListenerType;

  /** PreprocessingViewInterface storage */
  typedef std::set<ListenerType *> ListenersSetType;

  /** Register a new listener */
  virtual bool RegisterListener(ListenerType * listener)
  {
    return(m_RegisteredListeners.insert(listener).second);
  }

  /** Unregister a listener */
  virtual void UnRegisterListener(ListenerType * listener)
  {
    m_RegisteredListeners.erase(listener);
  }

  virtual void UnRegisterAllListeners()
  {
    m_RegisteredListeners.clear();
  }

  /** Notify changes to all registered listeners */
  virtual void NotifyAll()
  {
    for (typename ListenersSetType::iterator it = m_RegisteredListeners.begin();
         it!=m_RegisteredListeners.end();
         ++it)
    {
73
      this->NotifyListener(*it);
74
75
76
77
    }
  }

  /** Notify changes to a given listerner */
78
  virtual void NotifyListener(ListenerType * listener)
79
80
81
  {
     listener->Notify();
  };
82
83
84

protected:
  /** Constructor */
85
  MVCModel() {}
86
  /** Destructor */
87
  virtual ~MVCModel() {}
88
89

private:
90
91
92
93
  MVCModel(const Self&); //purposely not implemented
  void operator=(const Self&); //purposely not implemented


94
95
96
97
98
  /** Registered liteners */
  ListenersSetType m_RegisteredListeners;
};
}
#endif