PixelLightAPI  .
Attribute.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: Attribute.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_ATTRIBUTE_H__
00024 #define __PLCORE_ATTRIBUTE_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLCore/Base/Var/Var.h"
00032 #include "PLCore/Base/Var/VarDesc.h"
00033 
00034 
00035 //[-------------------------------------------------------]
00036 //[ Namespace                                             ]
00037 //[-------------------------------------------------------]
00038 namespace PLCore {
00039 
00040 
00041 //[-------------------------------------------------------]
00042 //[ Classes                                               ]
00043 //[-------------------------------------------------------]
00044 /**
00045 *  @brief
00046 *    Attribute of a class
00047 *
00048 *  @remarks
00049 *    This class template represents attributes (variables that belong to objects).
00050 */
00051 template <typename T, typename ACCESS, typename STORAGE, typename DESC>
00052 class Attribute : public Var<T, ACCESS, STORAGE> {
00053 
00054 
00055     //[-------------------------------------------------------]
00056     //[ Public data types                                     ]
00057     //[-------------------------------------------------------]
00058     public:
00059         // Storage type
00060         typedef typename Type<T>::_Type _Type;
00061 
00062 
00063     //[-------------------------------------------------------]
00064     //[ Public static data                                    ]
00065     //[-------------------------------------------------------]
00066     public:
00067         static DESC Desc;   /**< Attribute descriptor */
00068 
00069 
00070     //[-------------------------------------------------------]
00071     //[ Public functions                                      ]
00072     //[-------------------------------------------------------]
00073     public:
00074         /**
00075         *  @brief
00076         *    Constructor
00077         *
00078         *  @param[in] DefaultValue
00079         *    Default value for the attribute
00080         *  @param[in] pObject
00081         *    Pointer to object to which the attribute belongs
00082         */
00083         Attribute(_Type DefaultValue, Object *pObject) : Var<T, ACCESS, STORAGE>(DefaultValue, pObject)
00084         {
00085             // Ensure that the compiler will actually create static instances
00086             Desc.Dummy();
00087         }
00088 
00089         /**
00090         *  @brief
00091         *    Destructor
00092         */
00093         virtual ~Attribute()
00094         {
00095         }
00096 
00097         /**
00098         *  @brief
00099         *    Assignment operator
00100         *
00101         *  @param[in] Value
00102         *    New value
00103         *
00104         *  @remarks
00105         *    Unfortunately, it is necessary to define assignment operators in the 'leaf'-classes,
00106         *    as they are not inherited from base classes. So we have to define it here and then
00107         *    call the implementation in the base class, which makes everything a bit more complicated
00108         */
00109         Attribute &operator =(const _Type &Value)
00110         {
00111             // Call base implementation
00112             return static_cast<Attribute&>(Var<T, ACCESS, STORAGE>::operator =(Value));
00113         }
00114 
00115 
00116     //[-------------------------------------------------------]
00117     //[ Public virtual DynVar functions                       ]
00118     //[-------------------------------------------------------]
00119     public:
00120         /**
00121         *  @brief
00122         *    Get var descriptor
00123         *
00124         *  @return
00125         *    Var descriptor
00126         */
00127         virtual const VarDesc *GetDesc() const override
00128         {
00129             // Return descriptor
00130             return &Desc;
00131         }
00132 
00133 
00134 };
00135 
00136 
00137 // Static data instances
00138 template<typename T, typename ACCESS, typename STORAGE, typename DESC>
00139 DESC Attribute<T, ACCESS, STORAGE, DESC>::Desc;
00140 
00141 
00142 //[-------------------------------------------------------]
00143 //[ Namespace                                             ]
00144 //[-------------------------------------------------------]
00145 } // PLCore
00146 
00147 
00148 #endif // __PLCORE_ATTRIBUTE_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:08:52
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported