PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: ClassImpl.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_IMPL_H__ 00024 #define __PLCORE_CLASS_IMPL_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 Class; 00046 class Object; 00047 class Module; 00048 class VarDesc; 00049 class FuncDesc; 00050 class DynParams; 00051 class EventDesc; 00052 class MemberDesc; 00053 class ConstructorDesc; 00054 class EventHandlerDesc; 00055 00056 00057 //[-------------------------------------------------------] 00058 //[ Classes ] 00059 //[-------------------------------------------------------] 00060 /** 00061 * @brief 00062 * Abstract class implementation base class 00063 * 00064 * @note 00065 * - Implementation of the bridge design pattern, this class is the implementor of the 'Class' abstraction 00066 */ 00067 class ClassImpl { 00068 00069 00070 //[-------------------------------------------------------] 00071 //[ Friends ] 00072 //[-------------------------------------------------------] 00073 friend class Class; 00074 friend class ClassReal; 00075 friend class ClassDummy; 00076 friend class ClassManager; 00077 00078 00079 //[-------------------------------------------------------] 00080 //[ Public functions ] 00081 //[-------------------------------------------------------] 00082 public: 00083 /** 00084 * @brief 00085 * Return the pointer to the owner class instance wrapping this class implementation 00086 * 00087 * @return 00088 * Pointer to the owner class instance (should never be a null pointer, unless something is *terribly* wrong ;-) ) 00089 */ 00090 inline Class *GetClass() const; 00091 00092 00093 //[-------------------------------------------------------] 00094 //[ Protected functions ] 00095 //[-------------------------------------------------------] 00096 protected: 00097 /** 00098 * @brief 00099 * Constructor 00100 * 00101 * @param[in] nModuleID 00102 * ID of owner module 00103 * @param[in] sName 00104 * Name 00105 * @param[in] sDescription 00106 * Description 00107 * @param[in] sNamespace 00108 * Namespace 00109 * @param[in] sBaseClass 00110 * Base class 00111 */ 00112 PLCORE_API ClassImpl(uint32 nModuleID, const String &sName, const String &sDescription, const String &sNamespace, const String &sBaseClass); 00113 00114 /** 00115 * @brief 00116 * Destructor 00117 */ 00118 PLCORE_API virtual ~ClassImpl(); 00119 00120 /** 00121 * @brief 00122 * Get module the class belongs to 00123 * 00124 * @return 00125 * Module (always valid) 00126 */ 00127 PLCORE_API const Module *GetModule() const; 00128 00129 /** 00130 * @brief 00131 * Get full class name (with namespace) 00132 * 00133 * @return 00134 * Name of class and namespace 00135 */ 00136 inline String GetClassName() const; 00137 00138 /** 00139 * @brief 00140 * Get full name of base class (with namespace) 00141 * 00142 * @return 00143 * Name of base class and namespace 00144 */ 00145 inline String GetBaseClassName() const; 00146 00147 /** 00148 * @brief 00149 * Get class name (without namespace) 00150 * 00151 * @return 00152 * Name of class 00153 */ 00154 inline String GetName() const; 00155 00156 /** 00157 * @brief 00158 * Get class description 00159 * 00160 * @return 00161 * Description 00162 */ 00163 inline String GetDescription() const; 00164 00165 /** 00166 * @brief 00167 * Get namespace 00168 * 00169 * @return 00170 * Namespace 00171 */ 00172 inline String GetNamespace() const; 00173 00174 /** 00175 * @brief 00176 * Get base class 00177 * 00178 * @return 00179 * Pointer to base class (can be a null pointer) 00180 */ 00181 PLCORE_API const Class *GetBaseClass() const; 00182 00183 /** 00184 * @brief 00185 * Check if class is derived from another class 00186 * 00187 * @param[in] cBaseClass 00188 * Base class 00189 * 00190 * @return 00191 * 'true' if class is derived from given base class, else 'false' 00192 */ 00193 PLCORE_API bool IsDerivedFrom(const Class &cBaseClass) const; 00194 00195 /** 00196 * @brief 00197 * Check if class is derived from another class 00198 * 00199 * @param[in] sBaseClass 00200 * Base class name (with namespace) 00201 * 00202 * @return 00203 * 'true' if class is derived from given base class, else 'false' 00204 */ 00205 PLCORE_API bool IsDerivedFrom(const String &sBaseClass) const; 00206 00207 /** 00208 * @brief 00209 * Get properties 00210 * 00211 * @return 00212 * Hash map of properties (name -> value) 00213 * 00214 * @remarks 00215 * A property is a name/value pair of strings, that can be assigned to a class. Use this to 00216 * transport additional information for your class, e.g. 00217 * "PluginType" -> "Widget" 00218 * "FileFormats" -> "avi mpg mp4" 00219 */ 00220 inline const HashMap<String, String> &GetProperties() const; 00221 00222 //[-------------------------------------------------------] 00223 //[ Class management ] 00224 //[-------------------------------------------------------] 00225 /** 00226 * @brief 00227 * Add property 00228 * 00229 * @param[in] sName 00230 * Property name 00231 * @param[in] sValue 00232 * Property value 00233 */ 00234 PLCORE_API void AddProperty(const String &sName, const String &sValue); 00235 00236 00237 //[-------------------------------------------------------] 00238 //[ Protected virtual ClassImpl functions ] 00239 //[-------------------------------------------------------] 00240 protected: 00241 //[-------------------------------------------------------] 00242 //[ Class management ] 00243 //[-------------------------------------------------------] 00244 /** 00245 * @brief 00246 * Return whether or not the class implementation is a dummy used for delayed shared library loading 00247 * 00248 * @return 00249 * 'true' if the class implementation is a dummy used for delayed shared library loading, else 'false' 00250 */ 00251 virtual bool IsDummy() const = 0; 00252 00253 /** 00254 * @brief 00255 * Initialize class and class members 00256 * 00257 * @remarks 00258 * This function is called automatically when it is necessary, e.g. the first time 00259 * any members are being accessed. It will search for the base class of the class 00260 * and initialize all members. If later a class is changed (e.g. a new member is 00261 * registered at one of the base classes), that class and all derived classes will 00262 * destroy their information and must be initialized again. 00263 */ 00264 virtual void InitClass() const = 0; 00265 00266 /** 00267 * @brief 00268 * De-Initialize class and class members 00269 * 00270 * @remarks 00271 * This function destroys all data about the class and it's members. See 00272 * InitClass() for more information about why this is necessary and when. 00273 */ 00274 virtual void DeInitClass() const = 0; 00275 00276 //[-------------------------------------------------------] 00277 //[ Class interface ] 00278 //[-------------------------------------------------------] 00279 /** 00280 * @brief 00281 * Get attributes 00282 * 00283 * @return 00284 * List of attribute descriptors 00285 */ 00286 virtual const List<VarDesc*> &GetAttributes() const = 0; 00287 00288 /** 00289 * @brief 00290 * Get attribute 00291 * 00292 * @param[in] sName 00293 * Attribute name 00294 * 00295 * @return 00296 * Attribute descriptor (can be a null pointer, if no member with that name could be found) 00297 */ 00298 virtual const VarDesc *GetAttribute(const String &sName) const = 0; 00299 00300 /** 00301 * @brief 00302 * Get methods 00303 * 00304 * @return 00305 * List of method descriptors 00306 */ 00307 virtual const List<FuncDesc*> &GetMethods() const = 0; 00308 00309 /** 00310 * @brief 00311 * Get method 00312 * 00313 * @param[in] sName 00314 * Method name 00315 * 00316 * @return 00317 * Method descriptor (can be a null pointer, if no member with that name could be found) 00318 */ 00319 virtual const FuncDesc *GetMethod(const String &sName) const = 0; 00320 00321 /** 00322 * @brief 00323 * Get signals 00324 * 00325 * @return 00326 * List of signal descriptors 00327 */ 00328 virtual const List<EventDesc*> &GetSignals() const = 0; 00329 00330 /** 00331 * @brief 00332 * Get signal 00333 * 00334 * @param[in] sName 00335 * Signal name 00336 * 00337 * @return 00338 * Signal descriptor (can be a null pointer, if no member with that name could be found) 00339 */ 00340 virtual const EventDesc *GetSignal(const String &sName) const = 0; 00341 00342 /** 00343 * @brief 00344 * Get slot 00345 * 00346 * @return 00347 * List of slot descriptors 00348 */ 00349 virtual const List<EventHandlerDesc*> &GetSlots() const = 0; 00350 00351 /** 00352 * @brief 00353 * Get slot 00354 * 00355 * @param[in] sName 00356 * Slot name 00357 * 00358 * @return 00359 * Slot descriptor (can be a null pointer, if no member with that name could be found) 00360 */ 00361 virtual const EventHandlerDesc *GetSlot(const String &sName) const = 0; 00362 00363 /** 00364 * @brief 00365 * Check if class has any constructors 00366 * 00367 * @return 00368 * 'true' if class has at least one constructor, else 'false' 00369 */ 00370 virtual bool HasConstructor() const = 0; 00371 00372 /** 00373 * @brief 00374 * Check if class has a default constructor 00375 * 00376 * @return 00377 * 'true' if class has a default constructor, else 'false' 00378 */ 00379 virtual bool HasDefaultConstructor() const = 0; 00380 00381 /** 00382 * @brief 00383 * Get constructors 00384 * 00385 * @return 00386 * List of constructor descriptors 00387 */ 00388 virtual const List<ConstructorDesc*> &GetConstructors() const = 0; 00389 00390 /** 00391 * @brief 00392 * Get constructor 00393 * 00394 * @param[in] sName 00395 * Constructor name 00396 * 00397 * @return 00398 * Constructor descriptor (can be a null pointer, if no member with that name could be found) 00399 */ 00400 virtual const ConstructorDesc *GetConstructor(const String &sName) const = 0; 00401 00402 /** 00403 * @brief 00404 * Create object by using the default constructor 00405 * 00406 * @return 00407 * Pointer to created object (can be a null pointer) 00408 * 00409 * @remarks 00410 * This function will call the default constructor of the class. 00411 * If the class has no default constructor, the function will fail and return a null pointer. 00412 */ 00413 virtual Object *Create() const = 0; 00414 00415 /** 00416 * @brief 00417 * Create object by using typed constructor parameters in order to identity the constructor automatically 00418 * 00419 * @param[in] cParams 00420 * Constructor parameters 00421 * 00422 * @return 00423 * Pointer to created object (can be a null pointer) 00424 * 00425 * @remarks 00426 * This function will search for a constructor that matches the signature of the given parameters. 00427 * If no such constructor can be found, the function will fail and return a null pointer. 00428 */ 00429 virtual Object *Create(const DynParams &cParams) const = 0; 00430 00431 /** 00432 * @brief 00433 * Create object by using a given constructor name and typed constructor parameters 00434 * 00435 * @param[in] sName 00436 * Constructor name 00437 * @param[in] cParams 00438 * Constructor parameters 00439 * 00440 * @return 00441 * Pointer to created object (can be a null pointer) 00442 * 00443 * @remarks 00444 * This function will search for a constructor with the specified name. If no such constructor can be found, or 00445 * the given parameters do not match the signature of the constructor, the function will fail and return a null pointer. 00446 */ 00447 virtual Object *Create(const String &sName, const DynParams &cParams) const = 0; 00448 00449 /** 00450 * @brief 00451 * Create object by using a given constructor name and typeless constructor parameters 00452 * 00453 * @param[in] sName 00454 * Constructor name 00455 * @param[in] sParams 00456 * Constructor parameters 00457 * 00458 * @return 00459 * Pointer to created object (can be a null pointer, destroy the returned instance when you no longer need it) 00460 * 00461 * @remarks 00462 * This function will search for a constructor with the specified name. If no such constructor can be found, 00463 * the function will fail and return a null pointer. 00464 */ 00465 virtual Object *Create(const String &sName, const String &sParams) const = 0; 00466 00467 00468 //[-------------------------------------------------------] 00469 //[ Protected data ] 00470 //[-------------------------------------------------------] 00471 protected: 00472 // Class information 00473 Class *m_pClass; /**< Class instance wrapping this class implementation (can be a null pointer, set and managed by the class manager) */ 00474 String m_sName; /**< Name of class */ 00475 String m_sNamespace; /**< Namespace of class */ 00476 String m_sClassName; /**< Name of class (with namespace) */ 00477 String m_sDescription; /**< Description of class */ 00478 String m_sBaseClass; /**< Name of base class (with namespace) */ 00479 00480 // Own data (does not include data from base classes) 00481 HashMap<String, String> m_mapOwnProperties; /**< Hash map of properties (name -> value) */ 00482 00483 // Runtime data 00484 mutable uint32 m_nModuleID; /**< ID of owner module */ 00485 mutable bool m_bInitialized; /**< Is the class initialized? */ 00486 mutable const Class *m_pBaseClass; /**< Pointer to base class */ 00487 00488 // Member lists (also including the members from base classes) 00489 mutable HashMap<String, String> m_mapProperties; /**< Hash map of properties (name -> value) */ 00490 00491 00492 //[-------------------------------------------------------] 00493 //[ Private functions ] 00494 //[-------------------------------------------------------] 00495 private: 00496 /** 00497 * @brief 00498 * Copy constructor 00499 * 00500 * @param[in] cSource 00501 * Source to copy from 00502 */ 00503 ClassImpl(const ClassImpl &cSource); 00504 00505 /** 00506 * @brief 00507 * Copy operator 00508 * 00509 * @param[in] cSource 00510 * Source to copy from 00511 * 00512 * @return 00513 * Reference to this instance 00514 */ 00515 ClassImpl &operator =(const ClassImpl &cSource); 00516 00517 00518 }; 00519 00520 00521 //[-------------------------------------------------------] 00522 //[ Namespace ] 00523 //[-------------------------------------------------------] 00524 } // PLCore 00525 00526 00527 //[-------------------------------------------------------] 00528 //[ Implementation ] 00529 //[-------------------------------------------------------] 00530 #include "PLCore/Base/ClassImpl.inl" 00531 00532 00533 #endif // __PLCORE_CLASS_IMPL_H__
|