PixelLightAPI  .
Class.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: Class.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_CLASS_H__
00024 #define __PLCORE_CLASS_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLCore/String/String.h"
00032 #include "PLCore/Container/List.h"
00033 #include "PLCore/Container/HashMap.h"
00034 
00035 
00036 //[-------------------------------------------------------]
00037 //[ Namespace                                             ]
00038 //[-------------------------------------------------------]
00039 namespace PLCore {
00040 
00041 
00042 //[-------------------------------------------------------]
00043 //[ Forward declarations                                  ]
00044 //[-------------------------------------------------------]
00045 class Module;
00046 class Object;
00047 class VarDesc;
00048 class FuncDesc;
00049 class EventDesc;
00050 class DynParams;
00051 class ClassImpl;
00052 class ConstructorDesc;
00053 class EventHandlerDesc;
00054 
00055 
00056 //[-------------------------------------------------------]
00057 //[ Classes                                               ]
00058 //[-------------------------------------------------------]
00059 /**
00060 *  @brief
00061 *    Description and interface for classes
00062 *
00063 *  @note
00064 *    - Implementation of the bridge design pattern, this class is the abstraction
00065 */
00066 class Class {
00067 
00068 
00069     //[-------------------------------------------------------]
00070     //[ Friends                                               ]
00071     //[-------------------------------------------------------]
00072     friend class ClassImpl;
00073     friend class ClassReal;
00074     friend class ClassDummy;
00075     friend class ClassManager;
00076 
00077 
00078     //[-------------------------------------------------------]
00079     //[ Public functions                                      ]
00080     //[-------------------------------------------------------]
00081     public:
00082         /**
00083         *  @brief
00084         *    Get module the class belongs to
00085         *
00086         *  @return
00087         *    Module (always valid, do not destroy the returned instance!)
00088         */
00089         inline const Module *GetModule() const;
00090 
00091         /**
00092         *  @brief
00093         *    Get full class name (with namespace)
00094         *
00095         *  @return
00096         *    Name of class and namespace
00097         */
00098         inline String GetClassName() const;
00099 
00100         /**
00101         *  @brief
00102         *    Get full name of base class (with namespace)
00103         *
00104         *  @return
00105         *    Name of base class and namespace
00106         */
00107         inline String GetBaseClassName() const;
00108 
00109         /**
00110         *  @brief
00111         *    Get class name (without namespace)
00112         *
00113         *  @return
00114         *    Name of class
00115         */
00116         inline String GetName() const;
00117 
00118         /**
00119         *  @brief
00120         *    Get class description
00121         *
00122         *  @return
00123         *    Description
00124         */
00125         inline String GetDescription() const;
00126 
00127         /**
00128         *  @brief
00129         *    Get namespace
00130         *
00131         *  @return
00132         *    Namespace
00133         */
00134         inline String GetNamespace() const;
00135 
00136         /**
00137         *  @brief
00138         *    Get base class
00139         *
00140         *  @return
00141         *    Pointer to base class (can be a null pointer, do not destroy the returned instance!)
00142         */
00143         inline const Class *GetBaseClass() const;
00144 
00145         /**
00146         *  @brief
00147         *    Check if class is derived from another class
00148         *
00149         *  @param[in] cBaseClass
00150         *    Base class
00151         *
00152         *  @return
00153         *    'true' if class is derived from given base class, else 'false'
00154         */
00155         inline bool IsDerivedFrom(const Class &cBaseClass) const;
00156 
00157         /**
00158         *  @brief
00159         *    Check if class is derived from another class
00160         *
00161         *  @param[in] sBaseClass
00162         *    Base class name (with namespace)
00163         *
00164         *  @return
00165         *    'true' if class is derived from given base class, else 'false'
00166         */
00167         inline bool IsDerivedFrom(const String &sBaseClass) const;
00168 
00169         /**
00170         *  @brief
00171         *    Get derived classes
00172         *
00173         *  @param[out] lstClasses
00174         *    Receives the list of derived classes, given list is not cleared before adding new elements, do not destroy the returned instances!
00175         *
00176         *  @remarks
00177         *    This method always returns all sub-classes of a class.
00178         *    If you want to search for classes with more specific search criteria,
00179         *    have a look at ClassManager::GetClasses().
00180         */
00181         PLCORE_API void GetDerivedClasses(List<const Class*> &lstClasses) const;
00182 
00183         /**
00184         *  @brief
00185         *    Get properties
00186         *
00187         *  @return
00188         *    Hash map of properties (name -> value)
00189         *
00190         *  @remarks
00191         *    A property is a name/value pair of strings, that can be assigned to a class. Use this to
00192         *    transport additional information for your class, e.g.
00193         *      "PluginType"  -> "Widget"
00194         *      "FileFormats" -> "avi mpg mp4"
00195         */
00196         inline const HashMap<String, String> &GetProperties() const;
00197 
00198         /**
00199         *  @brief
00200         *    Get attributes
00201         *
00202         *  @return
00203         *    List of attribute descriptors, do not destroy the returned instances!
00204         */
00205         inline const List<VarDesc*> &GetAttributes() const;
00206 
00207         /**
00208         *  @brief
00209         *    Get attribute
00210         *
00211         *  @param[in] sName
00212         *    Attribute name
00213         *
00214         *  @return
00215         *    Attribute descriptor (can be a null pointer, if no member with that name could be found, do not destroy the returned instance!)
00216         */
00217         inline const VarDesc *GetAttribute(const String &sName) const;
00218 
00219         /**
00220         *  @brief
00221         *    Get methods
00222         *
00223         *  @return
00224         *    List of method descriptors, do not destroy the returned instances!
00225         */
00226         inline const List<FuncDesc*> &GetMethods() const;
00227 
00228         /**
00229         *  @brief
00230         *    Get method
00231         *
00232         *  @param[in] sName
00233         *    Method name
00234         *
00235         *  @return
00236         *    Method descriptor (can be a null pointer, if no member with that name could be found, do not destroy the returned instance!)
00237         */
00238         inline const FuncDesc *GetMethod(const String &sName) const;
00239 
00240         /**
00241         *  @brief
00242         *    Get signals
00243         *
00244         *  @return
00245         *    List of signal descriptors, do not destroy the returned instances!
00246         */
00247         inline const List<EventDesc*> &GetSignals() const;
00248 
00249         /**
00250         *  @brief
00251         *    Get signal
00252         *
00253         *  @param[in] sName
00254         *    Signal name
00255         *
00256         *  @return
00257         *    Signal descriptor (can be a null pointer, if no member with that name could be found, do not destroy the returned instance!)
00258         */
00259         inline const EventDesc *GetSignal(const String &sName) const;
00260 
00261         /**
00262         *  @brief
00263         *    Get slot
00264         *
00265         *  @return
00266         *    List of slot descriptors, do not destroy the returned instances!
00267         */
00268         inline const List<EventHandlerDesc*> &GetSlots() const;
00269 
00270         /**
00271         *  @brief
00272         *    Get slot
00273         *
00274         *  @param[in] sName
00275         *    Slot name
00276         *
00277         *  @return
00278         *    Slot descriptor (can be a null pointer, if no member with that name could be found, do not destroy the returned instance!)
00279         */
00280         inline const EventHandlerDesc *GetSlot(const String &sName) const;
00281 
00282         /**
00283         *  @brief
00284         *    Check if class has any constructors
00285         *
00286         *  @return
00287         *    'true' if class has at least one constructor, else 'false'
00288         */
00289         inline bool HasConstructor() const;
00290 
00291         /**
00292         *  @brief
00293         *    Check if class has a default constructor
00294         *
00295         *  @return
00296         *    'true' if class has a default constructor, else 'false'
00297         */
00298         inline bool HasDefaultConstructor() const;
00299 
00300         /**
00301         *  @brief
00302         *    Get constructors
00303         *
00304         *  @return
00305         *    List of constructor descriptors, do not destroy the returned instances!
00306         */
00307         inline const List<ConstructorDesc*> &GetConstructors() const;
00308 
00309         /**
00310         *  @brief
00311         *    Get constructor
00312         *
00313         *  @param[in] sName
00314         *    Constructor name
00315         *
00316         *  @return
00317         *    Constructor descriptor (can be a null pointer, if no member with that name could be found, do not destroy the returned instance!)
00318         */
00319         inline const ConstructorDesc *GetConstructor(const String &sName) const;
00320 
00321         /**
00322         *  @brief
00323         *    Create object by using the default constructor
00324         *
00325         *  @return
00326         *    Pointer to created object (can be a null pointer, destroy the returned instance when you no longer need it)
00327         *
00328         *  @remarks
00329         *    This function will call the default constructor of the class.
00330         *    If the class has no default constructor, the function will fail and return a null pointer.
00331         */
00332         inline Object *Create() const;
00333 
00334         /**
00335         *  @brief
00336         *    Create object by using typed constructor parameters in order to identity the constructor automatically
00337         *
00338         *  @param[in] cParams
00339         *    Constructor parameters
00340         *
00341         *  @return
00342         *    Pointer to created object (can be a null pointer, destroy the returned instance when you no longer need it)
00343         *
00344         *  @remarks
00345         *    This function will search for a constructor that matches the signature of the given parameters.
00346         *    If no such constructor can be found, the function will fail and return a null pointer.
00347         */
00348         inline Object *Create(const DynParams &cParams) const;
00349 
00350         /**
00351         *  @brief
00352         *    Create object by using a given constructor name and typed constructor parameters
00353         *
00354         *  @param[in] sName
00355         *    Constructor name
00356         *  @param[in] cParams
00357         *    Constructor parameters
00358         *
00359         *  @return
00360         *    Pointer to created object (can be a null pointer, destroy the returned instance when you no longer need it)
00361         *
00362         *  @remarks
00363         *    This function will search for a constructor with the specified name. If no such constructor can be found, or
00364         *    the given parameters do not match the signature of the constructor, the function will fail and return a null pointer.
00365         */
00366         inline Object *Create(const String &sName, const DynParams &cParams) const;
00367 
00368         /**
00369         *  @brief
00370         *    Create object by using a given constructor name and typeless constructor parameters
00371         *
00372         *  @param[in] sName
00373         *    Constructor name
00374         *  @param[in] sParams
00375         *    Constructor parameters
00376         *
00377         *  @return
00378         *    Pointer to created object (can be a null pointer, destroy the returned instance when you no longer need it)
00379         *
00380         *  @remarks
00381         *    This function will search for a constructor with the specified name. If no such constructor can be found,
00382         *    the function will fail and return a null pointer.
00383         */
00384         inline Object *Create(const String &sName, const String &sParams) const;
00385 
00386 
00387     //[-------------------------------------------------------]
00388     //[ Private functions                                     ]
00389     //[-------------------------------------------------------]
00390     private:
00391         /**
00392         *  @brief
00393         *    Constructor
00394         *
00395         *  @param[in] cClassImpl
00396         *    Reference to the class specific implementation (this class just shares the given data and doesn't destroy it)
00397         */
00398         Class(ClassImpl &cClassImpl);
00399 
00400         /**
00401         *  @brief
00402         *    Copy constructor
00403         *
00404         *  @param[in] cSource
00405         *    Source to copy from
00406         */
00407         Class(const Class &cSource);
00408 
00409         /**
00410         *  @brief
00411         *    Destructor
00412         */
00413         ~Class();
00414 
00415         /**
00416         *  @brief
00417         *    Copy operator
00418         *
00419         *  @param[in] cSource
00420         *    Source to copy from
00421         *
00422         *  @return
00423         *    Reference to this instance
00424         */
00425         Class &operator =(const Class &cSource);
00426 
00427 
00428     //[-------------------------------------------------------]
00429     //[ Private data                                          ]
00430     //[-------------------------------------------------------]
00431     private:
00432         mutable ClassImpl *m_pClassImpl;    /**< Pointer to the class specific implementation, just shared pointer (assumed to be never a null pointer!) */
00433 
00434 
00435 };
00436 
00437 
00438 //[-------------------------------------------------------]
00439 //[ Namespace                                             ]
00440 //[-------------------------------------------------------]
00441 } // PLCore
00442 
00443 
00444 //[-------------------------------------------------------]
00445 //[ Implementation                                        ]
00446 //[-------------------------------------------------------]
00447 #include "PLCore/Base/Class.inl"
00448 
00449 
00450 #endif // __PLCORE_CLASS_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