IFeatures.h
Go to the documentation of this file.00001 /**<!--------------------------------------------------------------------> 00002 @class IFeatures 00003 @author Travis Fischer (fisch0920@gmail.com) 00004 @date Summer 2008 00005 00006 @brief 00007 Utility base class for managing large amounts of (possibly) optional 00008 functionality in a clean and consistent manner. The template type 00009 'Feature' needs to support bitwise computations. 00010 <!-------------------------------------------------------------------->**/ 00011 00012 #ifndef IFEATURES_H_ 00013 #define IFEATURES_H_ 00014 00015 typedef long Feature; 00016 00017 class IFeatures { 00018 public: 00019 virtual ~IFeatures() { } 00020 00021 /** 00022 * @brief 00023 * Initializes nonstandard features to speedup performance. 00024 * 00025 * If some or all of the requested features have already been 00026 * initialized, they can optionally be reinitialized by setting 00027 * 'forceInit' to true 00028 * 00029 * @returns whether or not requested features were all successfully 00030 * initialized 00031 */ 00032 virtual bool initializeFeatures(Feature features = Feature(), bool forceInit = false) = 0; 00033 00034 /** 00035 * @brief 00036 * Cleanups any data associated with the given features and 00037 * disables them until they are reinitialized by initializeFeatures 00038 */ 00039 virtual void cleanupFeatures(Feature features = Feature()) = 0; 00040 00041 /** 00042 * @returns all of the features supported by this class ORed together 00043 */ 00044 virtual Feature getSupportedFeatures() const = 0; 00045 00046 /** 00047 * @returns all of the features which have been initialized by a call 00048 * to initializeFeatures 00049 */ 00050 virtual Feature getInitializedFeatures() const = 0; 00051 00052 /** 00053 * @returns all of the features which are not currently initialized 00054 */ 00055 inline Feature getUninitializedFeatures() const { 00056 return (getSupportedFeatures() & ~getInitializedFeatures()); 00057 } 00058 00059 /** 00060 * @returns whether or not all of the requrested features have been 00061 * initialized 00062 */ 00063 inline bool areFeaturesInitialized(Feature requestedFeatures) const { 00064 Feature initializedFeatures = getInitializedFeatures(); 00065 00066 return ((initializedFeatures & requestedFeatures) == requestedFeatures); 00067 } 00068 00069 /** 00070 * @returns whether or not all of the requrested features have been 00071 * initialized (pseudonym for areFeaturesInitialized) 00072 */ 00073 inline bool hasFeature(Feature requestedFeatures) const { 00074 return areFeaturesInitialized(requestedFeatures); 00075 } 00076 00077 protected: 00078 inline IFeatures() 00079 : m_features(Feature()) 00080 { } 00081 00082 protected: 00083 Feature m_features; 00084 }; 00085 00086 #endif // IFEATURES_H_ 00087
Generated on 28 Feb 2009 for Milton by
1.5.6