OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
data_observer.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2011 by the OpenStructure authors
5 // Copyright (C) 2003-2010 by the IPLT authors
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the Free
9 // Software Foundation; either version 3.0 of the License, or (at your option)
10 // any later version.
11 // This library is distributed in the hope that it will be useful, but WITHOUT
12 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 // details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with this library; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 //------------------------------------------------------------------------------
20 
21 /*
22  data observer
23 
24  Author: Ansgar Philippsen
25 */
26 
27 #ifndef IMG_DATA_OBSERVER
28 #define IMG_DATA_OBSERVER
29 
30 
31 #include "image_handle.hh"
32 
33 namespace ost { namespace img {
34 
35 
36 class DLLEXPORT InvalidObserver: public Error {
37 public:
38  InvalidObserver(const String& s = String("unknown")):
39  Error(String("InvalidObserver exception occured: ") + s)
40  {}
41 };
42 
44 /*
45  Based on the pattern of same name (293). The expression Observer or
46  Observed is part of the method names in purpose, in order to avoid
47  conflict with other interfaces (such as in wxWidgets)
48 
49  ObserverUpdate() and ObserverRelease() are the abstract methods and
50  must be implemented by a derived class. It is important to note that
51  the reference to Data given to the ctor should not be saved in the
52  derived class, but rather the GetObservedData method should be used.
53 
54  If the observed data goes out-of-scope, a call to ObserverRelease will
55  be followed by a call to ObserverInvalidate, which will mark the data
56  reference as invalidated. A further call to GetObserved Data will throw
57  an InvalidObserver exception!
58 */
60  public:
62 
65  DataObserver(const ImageHandle& d);
66 
67  DataObserver(const DataObserver& o);
68 
69  DataObserver& operator=(const DataObserver& o);
70 
71  virtual ~DataObserver();
72 
74  virtual void ObserverUpdate();
75 
77  virtual void ObserverUpdate(const Extent&);
78 
80  virtual void ObserverUpdate(const Point&);
81 
83  virtual void ObserverRelease() = 0;
84 
86  /*
87  This will automatically invalidate the observer so that
88  a next call to GetData() will throw an InvalidObserver
89  exception
90  */
91  void ObserverInvalidate();
92 
94  virtual const ImageHandle& GetObservedData() const;
95 
96  bool IsDataValid() const {return is_valid();}
97 
98  protected:
99 
101 
104  void SetObservedData(const ImageHandle& d);
105 
106  bool is_valid() const;
107 
108 private:
109  ImageHandle data_;
110 
111 };
112 
113 }} // namespace img
114 
115 #endif
116 
std::string String
Definition: base.hh:54
Defines lower and upper valid indices.
Definition: extent.hh:60
Abstract base class of data observer.
bool IsDataValid() const
Manage shared instances of images.
InvalidObserver(const String &s=String("unknown"))
class encapsulating 1D to 3D point
Definition: point.hh:43
#define DLLEXPORT_OST_IMG_BASE