00001 //------------------------------------------------------------------------------ 00002 // This file is part of the OpenStructure project <www.openstructure.org> 00003 // 00004 // Copyright (C) 2008-2010 by the OpenStructure authors 00005 // Copyright (C) 2003-2010 by the IPLT authors 00006 // 00007 // This library is free software; you can redistribute it and/or modify it under 00008 // the terms of the GNU Lesser General Public License as published by the Free 00009 // Software Foundation; either version 3.0 of the License, or (at your option) 00010 // any later version. 00011 // This library is distributed in the hope that it will be useful, but WITHOUT 00012 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00013 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00014 // details. 00015 // 00016 // You should have received a copy of the GNU Lesser General Public License 00017 // along with this library; if not, write to the Free Software Foundation, Inc., 00018 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 //------------------------------------------------------------------------------ 00020 00021 /* 00022 data observer 00023 00024 Author: Ansgar Philippsen 00025 */ 00026 00027 #ifndef IMG_DATA_OBSERVER 00028 #define IMG_DATA_OBSERVER 00029 00030 #include <boost/ref.hpp> 00031 00032 #include "data.hh" 00033 00034 namespace ost { namespace img { 00035 00036 00037 class DLLEXPORT InvalidObserver: public Error { 00038 public: 00039 InvalidObserver(const String& s = String("unknown")): 00040 Error(String("InvalidObserver exception occured: ") + s) 00041 {} 00042 }; 00043 00045 /* 00046 Based on the pattern of same name (293). The expression Observer or 00047 Observed is part of the method names in purpose, in order to avoid 00048 conflict with other interfaces (such as in wxWidgets) 00049 00050 ObserverUpdate() and ObserverRelease() are the abstract methods and 00051 must be implemented by a derived class. It is important to note that 00052 the reference to Data given to the ctor should not be saved in the 00053 derived class, but rather the GetObservedData method should be used. 00054 00055 If the observed data goes out-of-scope, a call to ObserverRelease will 00056 be followed by a call to ObserverInvalidate, which will mark the data 00057 reference as invalidated. A further call to GetObserved Data will throw 00058 an InvalidObserver exception! 00059 */ 00060 class DLLEXPORT_OST_IMG_BASE DataObserver { 00061 public: 00063 00066 DataObserver(const Data& d); 00067 00068 DataObserver(const DataObserver& o); 00069 00070 DataObserver& operator=(const DataObserver& o); 00071 00072 virtual ~DataObserver(); 00073 00075 virtual void ObserverUpdate(); 00076 00078 virtual void ObserverUpdate(const Extent&); 00079 00081 virtual void ObserverUpdate(const Point&); 00082 00084 virtual void ObserverRelease() = 0; 00085 00087 /* 00088 This will automatically invalidate the observer so that 00089 a next call to GetData() will throw an InvalidObserver 00090 exception 00091 */ 00092 void ObserverInvalidate(); 00093 00095 virtual const Data& GetObservedData() const; 00096 00097 bool IsDataValid() const {return is_valid();} 00098 00099 protected: 00100 00102 00105 void SetObservedData(const Data& d); 00106 00107 bool is_valid() const; 00108 00109 private: 00110 boost::reference_wrapper<const Data> data_; 00111 00112 }; 00113 00114 }} // namespace img 00115 00116 #endif 00117
1.5.8