PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: VarAccess.h * 00003 * 00004 * Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/) 00005 * 00006 * This file is part of PixelLight. 00007 * 00008 * PixelLight is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published by 00010 * the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * PixelLight is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with PixelLight. If not, see <http://www.gnu.org/licenses/>. 00020 \*********************************************************/ 00021 00022 00023 #ifndef __PLCORE_VAR_ACCESS_H__ 00024 #define __PLCORE_VAR_ACCESS_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include "PLCore/Base/Var/VarStorage.h" 00032 00033 00034 //[-------------------------------------------------------] 00035 //[ Namespace ] 00036 //[-------------------------------------------------------] 00037 namespace PLCore { 00038 00039 00040 //[-------------------------------------------------------] 00041 //[ Forward declarations ] 00042 //[-------------------------------------------------------] 00043 class Object; 00044 00045 00046 //[-------------------------------------------------------] 00047 //[ Helper classes ] 00048 //[-------------------------------------------------------] 00049 // Access types 00050 class AccessReadWrite{}; // Allow read and write access to var 00051 class AccessReadOnly {}; // Allow only read access to var 00052 00053 00054 //[-------------------------------------------------------] 00055 //[ Classes ] 00056 //[-------------------------------------------------------] 00057 /** 00058 * @brief 00059 * Access mode for a variable 00060 * 00061 * @remarks 00062 * This class template is used to control the access mode of a variable. 00063 * If AccessReadWrite is specified, a variable can be read and written to. 00064 * If AccessReadOnly is specified, a variable can only be read. 00065 */ 00066 template <typename T, typename ACCESS, typename STORAGE> 00067 class VarAccess : public VarStorage<T, STORAGE, typename STORAGE::StorageType> { 00068 }; 00069 00070 00071 /** 00072 * @brief 00073 * Access mode for a variable 00074 * 00075 * @remarks 00076 * Implementation for read/write access 00077 */ 00078 template <typename T, typename STORAGE> 00079 class VarAccess<T, AccessReadWrite, STORAGE> : public VarStorage<T, STORAGE, typename STORAGE::StorageType> { 00080 00081 00082 //[-------------------------------------------------------] 00083 //[ Public data types ] 00084 //[-------------------------------------------------------] 00085 public: 00086 // Storage type 00087 typedef typename Type<T>::_Type _Type; 00088 00089 00090 //[-------------------------------------------------------] 00091 //[ Public functions ] 00092 //[-------------------------------------------------------] 00093 public: 00094 /** 00095 * @brief 00096 * Constructor 00097 * 00098 * @param[in] DefaultValue 00099 * Default value of var 00100 */ 00101 VarAccess(const _Type &DefaultValue) : VarStorage<T, STORAGE, typename STORAGE::StorageType>(DefaultValue) 00102 { 00103 } 00104 00105 /** 00106 * @brief 00107 * Constructor 00108 * 00109 * @param[in] DefaultValue 00110 * Default value of var 00111 * @param[in] pObject 00112 * Pointer to object holding the attribute 00113 */ 00114 VarAccess(const _Type &DefaultValue, Object *pObject) : VarStorage<T, STORAGE, typename STORAGE::StorageType>(DefaultValue, pObject) 00115 { 00116 } 00117 00118 /** 00119 * @brief 00120 * Get value 00121 * 00122 * @return 00123 * Value 00124 */ 00125 inline _Type Get() const 00126 { 00127 return VarStorage<T, STORAGE, typename STORAGE::StorageType>::StorageGet(); 00128 } 00129 00130 /** 00131 * @brief 00132 * Set value 00133 * 00134 * @param[in] Value 00135 * Value 00136 */ 00137 inline void Set(const _Type &Value) 00138 { 00139 VarStorage<T, STORAGE, typename STORAGE::StorageType>::StorageSet(Value); 00140 } 00141 00142 00143 }; 00144 00145 00146 /** 00147 * @brief 00148 * Access mode for a variable 00149 * 00150 * @remarks 00151 * Implementation for read-only access 00152 */ 00153 template <typename T, typename STORAGE> 00154 class VarAccess<T, AccessReadOnly, STORAGE> : public VarStorage<T, STORAGE, typename STORAGE::StorageType> { 00155 00156 00157 //[-------------------------------------------------------] 00158 //[ Public data types ] 00159 //[-------------------------------------------------------] 00160 public: 00161 // Storage type 00162 typedef typename Type<T>::_Type _Type; 00163 00164 00165 //[-------------------------------------------------------] 00166 //[ Public functions ] 00167 //[-------------------------------------------------------] 00168 public: 00169 /** 00170 * @brief 00171 * Constructor 00172 * 00173 * @param[in] DefaultValue 00174 * Default value of var 00175 */ 00176 VarAccess(const _Type &DefaultValue) : VarStorage<T, STORAGE, typename STORAGE::StorageType>(DefaultValue) 00177 { 00178 } 00179 00180 /** 00181 * @brief 00182 * Constructor 00183 * 00184 * @param[in] DefaultValue 00185 * Default value of var 00186 * @param[in] pObject 00187 * Pointer to object holding the attribute 00188 */ 00189 VarAccess(const _Type &DefaultValue, Object *pObject) : VarStorage<T, STORAGE, typename STORAGE::StorageType>(DefaultValue, pObject) 00190 { 00191 } 00192 00193 /** 00194 * @brief 00195 * Get value 00196 * 00197 * @return 00198 * Value 00199 */ 00200 inline _Type Get() const 00201 { 00202 return VarStorage<T, STORAGE, typename STORAGE::StorageType>::StorageGet(); 00203 } 00204 00205 /** 00206 * @brief 00207 * Set value 00208 * 00209 * @param[in] Value 00210 * Value 00211 */ 00212 inline void Set(const _Type &Value) 00213 { 00214 } 00215 00216 00217 }; 00218 00219 00220 //[-------------------------------------------------------] 00221 //[ Namespace ] 00222 //[-------------------------------------------------------] 00223 } // PLCore 00224 00225 00226 #endif // __PLCORE_VAR_ACCESS_H__
|