00001 /* 00002 * The information in this file is 00003 * Copyright(c) 2007 Ball Aerospace & Technologies Corporation 00004 * and is subject to the terms and conditions of the 00005 * GNU Lesser General Public License Version 2.1 00006 * The license text is available from 00007 * http://www.gnu.org/licenses/lgpl.html 00008 */ 00009 00010 #ifndef DATA_ACCESSOR_H 00011 #define DATA_ACCESSOR_H 00012 00013 class DataAccessorImpl; 00014 00015 /** 00016 * Provides safe deletion of the DataAccessorImpl. 00017 * 00018 * A plug-in developer does not use this class directly. This class is used 00019 * to safely delete the DataAccessorImpl class. When the DataAccessor loses scope, 00020 * the DataAccessorImpl class is deleted. 00021 * 00022 * @see DataAccessor, DataAccessorImpl 00023 */ 00024 class DataAccessorDeleter 00025 { 00026 public: 00027 /** 00028 * Provides support for deleting the DataAcessorImpl. 00029 * 00030 * @param pImpl 00031 * A pointer to the managed DataAcessorImpl instance. 00032 */ 00033 virtual void operator()(DataAccessorImpl* pImpl) = 0; 00034 }; 00035 00036 /** 00037 * Provides reference counting for the DataAccessorImpl. 00038 * 00039 * A plug-in developer does not use this class directly. The %DataAccessor exists 00040 * for the sole purpose of managing the lifespan of the DataAccessorImpl. This 00041 * class is used to create a wrapper around the DataAccessorImpl class to provide 00042 * safe reference counting. When the %DataAccessor loses scope the DataAccessorImpl 00043 * class is deleted, causing its associated RasterPager to release its held RasterPage. 00044 * If the RasterPager has already been deleted (e.g.: by deleting its RasterElement), 00045 * the destruction of the DataAccessorImpl will cause undefined behavior. Therefore, 00046 * the deletion of a RasterElement must occur after the deletion of its associated %DataAccessors. 00047 * 00048 * @see DataAccessorDeleter, DataAccessorImpl 00049 */ 00050 class DataAccessor 00051 { 00052 public: 00053 /** 00054 * Creates a %DataAccessor. 00055 * 00056 * This class is not called directly by a plug-in developer. This creates an 00057 * instance of a class that manages the lifespan of the DataAccessorImpl. 00058 * 00059 * @param pDeleter 00060 * A class that manages the deletion of the DataAccessorImpl. 00061 * @param pImpl 00062 * The DataAccessorImpl class to manage. 00063 */ 00064 DataAccessor(DataAccessorDeleter *pDeleter, DataAccessorImpl*pImpl); 00065 00066 /** 00067 * Default copy constructor. 00068 */ 00069 DataAccessor(const DataAccessor &da); 00070 00071 /** 00072 * Destructor for the DataAccessor. 00073 */ 00074 ~DataAccessor(); 00075 00076 /** 00077 * The equals operator. 00078 * 00079 * @param rhs 00080 * The DataAccessor from which to set this accessor's values. 00081 */ 00082 DataAccessor& operator=(const DataAccessor& rhs); 00083 00084 /** 00085 * Provides access to the real DataAccessorImpl. 00086 * 00087 * The overloaded operator-> allows us to continue to use pointer notation to 00088 * directly access the internally held pointer to the DataAccessorImpl. 00089 * See also the Boost smart pointers. You will see the same thing. 00090 * 00091 * @return Returns a pointer to the DataAccessorImpl. 00092 */ 00093 inline DataAccessorImpl* operator->() { return mpImpl; } 00094 00095 /** 00096 * Determines if the DataAccessor references a valid DataAccessorImpl. 00097 * 00098 * @return Returns true if the DataAccessorImpl is valid. 00099 */ 00100 bool isValid() const; 00101 00102 private: 00103 /** 00104 * Increases the number of references by one. 00105 */ 00106 void incrementRefCount(); 00107 00108 /** 00109 * Decreases the number of references by one. 00110 */ 00111 void decrementRefCount(); 00112 00113 DataAccessorDeleter *mpDeleter; 00114 DataAccessorImpl *mpImpl; 00115 }; 00116 00117 #endif