00001 00016 /* 00017 * Copyright (c) 2005, Matt Beard 00018 * 00019 * This software is provided 'as-is', without any express or implied warranty. 00020 * In no event will the authors be held liable for any damages arising from 00021 * the use of this software. 00022 * 00023 * Permission is granted to anyone to use this software for any purpose, 00024 * including commercial applications, and to alter it and redistribute it 00025 * freely, subject to the following restrictions: 00026 * 00027 * 1. The origin of this software must not be misrepresented; you must 00028 * not claim that you wrote the original software. If you use this 00029 * software in a product, an acknowledgment in the product 00030 * documentation would be appreciated but is not required. 00031 * 00032 * 2. Altered source versions must be plainly marked as such, and must 00033 * not be misrepresented as being the original software. 00034 * 00035 * 3. This notice may not be removed or altered from any source 00036 * distribution. 00037 */ 00038 00039 00040 /************************/ 00041 /* Comile-time settings */ 00042 /************************/ 00043 /* 00044 * The following macros may be defined on the compiler command-line: 00045 * 00046 * MXFLIB_FEATURE_MASK - Only those features that match this mask are compiled 00047 * Default setting is to allow all features 00048 * 00049 * MXFLIB_FEATURE_DEFAULT - The initial state of the feature bitmap 00050 * Default setting is all features off 00051 * 00052 * MXFLIB_FEATURE_LOCK - Selects features that cannot be changed from their default state at run-time 00053 * Default setting is all features unlocked 00054 */ 00055 00056 00057 // Those features that may be enabled 00058 #ifndef MXFLIB_FEATURE_MASK 00059 #define MXFLIB_FEATURE_MASK (~UINT64_C(0)) 00060 #endif 00061 00062 // Those features that are enabled by default 00063 #ifndef MXFLIB_FEATURE_DEFAULT 00064 #define MXFLIB_FEATURE_DEFAULT (UINT64_C(0)) 00065 #endif 00066 00067 // Those features that cannot be changed at run-time 00068 #ifndef MXFLIB_FEATURE_LOCK 00069 #define MXFLIB_FEATURE_LOCK (UINT64_C(0)) 00070 #endif 00071 00072 00073 namespace mxflib 00074 { 00075 /* Standard library features (bits 0 to 30) */ 00076 00077 const UInt64 FeatureVersion1KLVFill = UINT64_C(1) << 0; 00078 00079 /* This sub-range is currently used by temporary fixes (bits 16 to 30) */ 00080 00081 const UInt64 FeatureNegPrechargeIndex = UINT64_C(1) << 16; 00082 00083 // Reserve a bit for user-extensions 00084 const UInt64 UserExtension = UINT64_C(1) << 31; 00085 00086 00087 /* Non-Standard library functions - may cause non-complient behaviour (bits 32 to 63) */ 00088 00089 const UInt64 Feature32 = UINT64_C(1) << 32; 00090 00091 // Declare the features bitmap 00092 extern UInt64 Features; 00093 00094 00096 00105 inline bool SetFeature(const UInt64 SetValue) 00106 { 00107 // Fail if any of the features are disabled 00108 if((SetValue & MXFLIB_FEATURE_MASK) != SetValue) 00109 { 00110 error("Feature 0x%s is not enabled in the current library\n", Int64toHexString(SetValue).c_str()); 00111 return false; 00112 } 00113 00114 // Fail if any of the features are locked (unless they are locked enabled!) 00115 if(SetValue & MXFLIB_FEATURE_LOCK) 00116 { 00117 // Check if the locked bits are a problem (the locked value may be "on", which is fine) 00118 UInt64 Locked = SetValue & MXFLIB_FEATURE_LOCK; 00119 if(Locked & (~MXFLIB_FEATURE_DEFAULT)) 00120 { 00121 error("Feature 0x%s is locked off in the current library\n", Int64toHexString(SetValue).c_str()); 00122 return false; 00123 } 00124 } 00125 00126 // Set the feature or features 00127 Features |= SetValue; 00128 00129 // All OK 00130 return true; 00131 } 00132 00133 00135 00144 inline bool ClearFeature(const UInt64 ClearValue) 00145 { 00146 // Fail if any of the features are locked (and they are locked enabled!) 00147 if(ClearValue & MXFLIB_FEATURE_LOCK) 00148 { 00149 // Check if the locked bits are a problem (the locked value may be "off", which is fine) 00150 UInt64 Locked = ClearValue & MXFLIB_FEATURE_LOCK; 00151 if(Locked & MXFLIB_FEATURE_DEFAULT) 00152 { 00153 error("Feature 0x%s is locked on in the current library\n", Int64toHexString(ClearValue).c_str()); 00154 return false; 00155 } 00156 } 00157 00158 // Clear the feature or features 00159 Features &= ~ClearValue; 00160 00161 // All OK 00162 return true; 00163 } 00164 00165 00167 /* DRAGONS: This code is written so that it will fold to: 00168 * - a compile-time result if the value of Value is known at compile-time and it is disabled or locked (on or off) 00169 * - a simple bit-test if the value of SetValue is non known at compile time, but no features are disabled or locked 00170 * - the full function in all other cases 00171 */ 00172 inline bool Feature(const UInt64 Value) 00173 { 00174 // If any of the features are disabled don't bother to read it 00175 if((Value & MXFLIB_FEATURE_MASK) != Value) return false; 00176 00177 // If all of the features are locked simply return the compile-time setting 00178 if(Value & MXFLIB_FEATURE_LOCK) 00179 { 00180 if((Value & MXFLIB_FEATURE_DEFAULT) == Value) return true; else return false; 00181 } 00182 00183 // Run-time test 00184 if((Value & Features) == Value) return true; else return false; 00185 } 00186 } 00187