OpenStructure
Main Page
Related Pages
Modules
Namespaces
Data Structures
Files
Examples
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
stage
include
ost
img
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
#include <boost/ref.hpp>
31
32
#include "
data.hh
"
33
34
namespace
ost {
namespace
img {
35
36
37
class
DLLEXPORT
InvalidObserver
:
public
Error
{
38
public
:
39
InvalidObserver
(
const
String
& s =
String
(
"unknown"
)):
40
Error
(
String
(
"InvalidObserver exception occured: "
) + s)
41
{}
42
};
43
45
/*
46
Based on the pattern of same name (293). The expression Observer or
47
Observed is part of the method names in purpose, in order to avoid
48
conflict with other interfaces (such as in wxWidgets)
49
50
ObserverUpdate() and ObserverRelease() are the abstract methods and
51
must be implemented by a derived class. It is important to note that
52
the reference to Data given to the ctor should not be saved in the
53
derived class, but rather the GetObservedData method should be used.
54
55
If the observed data goes out-of-scope, a call to ObserverRelease will
56
be followed by a call to ObserverInvalidate, which will mark the data
57
reference as invalidated. A further call to GetObserved Data will throw
58
an InvalidObserver exception!
59
*/
60
class
DLLEXPORT_OST_IMG_BASE
DataObserver
{
61
public
:
63
66
DataObserver
(
const
Data
& d);
67
68
DataObserver
(
const
DataObserver
& o);
69
70
DataObserver
& operator=(
const
DataObserver
& o);
71
72
virtual
~
DataObserver
();
73
75
virtual
void
ObserverUpdate();
76
78
virtual
void
ObserverUpdate(
const
Extent
&);
79
81
virtual
void
ObserverUpdate(
const
Point
&);
82
84
virtual
void
ObserverRelease() = 0;
85
87
/*
88
This will automatically invalidate the observer so that
89
a next call to GetData() will throw an InvalidObserver
90
exception
91
*/
92
void
ObserverInvalidate();
93
95
virtual
const
Data
& GetObservedData()
const
;
96
97
bool
IsDataValid
()
const
{
return
is_valid();}
98
99
protected
:
100
102
105
void
SetObservedData(
const
Data
& d);
106
107
bool
is_valid()
const
;
108
109
private
:
110
boost::reference_wrapper<const Data> data_;
111
112
};
113
114
}}
// namespace img
115
116
#endif
117
Generated on Mon Nov 5 2012 13:31:01 for OpenStructure by
1.8.1.1