00001 //------------------------------------------------------------------------------ 00002 // This file is part of the OpenStructure project <www.openstructure.org> 00003 // 00004 // Copyright (C) 2008-2011 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 00031 #include "image_handle.hh" 00032 00033 namespace ost { namespace img { 00034 00035 00036 class DLLEXPORT InvalidObserver: public Error { 00037 public: 00038 InvalidObserver(const String& s = String("unknown")): 00039 Error(String("InvalidObserver exception occured: ") + s) 00040 {} 00041 }; 00042 00044 /* 00045 Based on the pattern of same name (293). The expression Observer or 00046 Observed is part of the method names in purpose, in order to avoid 00047 conflict with other interfaces (such as in wxWidgets) 00048 00049 ObserverUpdate() and ObserverRelease() are the abstract methods and 00050 must be implemented by a derived class. It is important to note that 00051 the reference to Data given to the ctor should not be saved in the 00052 derived class, but rather the GetObservedData method should be used. 00053 00054 If the observed data goes out-of-scope, a call to ObserverRelease will 00055 be followed by a call to ObserverInvalidate, which will mark the data 00056 reference as invalidated. A further call to GetObserved Data will throw 00057 an InvalidObserver exception! 00058 */ 00059 class DLLEXPORT_OST_IMG_BASE DataObserver { 00060 public: 00062 00065 DataObserver(const ImageHandle& d); 00066 00067 DataObserver(const DataObserver& o); 00068 00069 DataObserver& operator=(const DataObserver& o); 00070 00071 virtual ~DataObserver(); 00072 00074 virtual void ObserverUpdate(); 00075 00077 virtual void ObserverUpdate(const Extent&); 00078 00080 virtual void ObserverUpdate(const Point&); 00081 00083 virtual void ObserverRelease() = 0; 00084 00086 /* 00087 This will automatically invalidate the observer so that 00088 a next call to GetData() will throw an InvalidObserver 00089 exception 00090 */ 00091 void ObserverInvalidate(); 00092 00094 virtual const ImageHandle& GetObservedData() const; 00095 00096 bool IsDataValid() const {return is_valid();} 00097 00098 protected: 00099 00101 00104 void SetObservedData(const ImageHandle& d); 00105 00106 bool is_valid() const; 00107 00108 private: 00109 ImageHandle data_; 00110 00111 }; 00112 00113 }} // namespace img 00114 00115 #endif 00116