|
|
|||
File indexing completed on 2026-06-02 08:51:49
0001 #ifndef BASE_OBJECT_FACTORY_H 0002 #define BASE_OBJECT_FACTORY_H 0003 0004 /** 0005 * @file BaseObjectFactory.h 0006 * @author Bryan BERTHOU (SPhN / CEA Saclay) 0007 * @date June 26, 2015 0008 * @version 1.0 0009 */ 0010 0011 #include <SFML/System/Mutex.hpp> 0012 #include <map> 0013 #include <string> 0014 0015 #include "BaseObject.h" 0016 0017 namespace PARTONS { 0018 0019 class BaseObjectRegistry; 0020 0021 /** 0022 * @class BaseObjectFactory 0023 * 0024 * @brief Provides a clone (returned as a BaseObject pointer) of an object identified by its class name and previously stored in the BaseObjectRegistry. 0025 * Furthermore, a pointer to each clone is registered in order to destroy it later on if it becomes orphan.\n 0026 * This class is only instantiable by the class Partons to avoid any error at the initialization of the program. 0027 */ 0028 class BaseObjectFactory { 0029 public: 0030 /** 0031 * Default destructor. 0032 */ 0033 virtual ~BaseObjectFactory(); 0034 0035 /** 0036 * Provides a clone of the desired object class stored in the registry identified by its integer identifier. 0037 * 0038 * @param classId 0039 * @return 0040 */ 0041 BaseObject* newBaseObject(unsigned int classId); 0042 0043 /** 0044 * Provides a clone of the desired object class stored in the registry identified by its string class name. 0045 * 0046 * @param classId 0047 * @return 0048 */ 0049 BaseObject* newBaseObject(const std::string &className); 0050 0051 /** 0052 * Remove an object from the factory. 0053 * 0054 * @param baseObjectUniqueId Unique id identifying each object. 0055 */ 0056 void removeFromStore(unsigned int baseObjectUniqueId); 0057 0058 private: 0059 // To allow only Partons class to create a unique of this class. 0060 // Used to avoid multiple singleton class and to avoid multithreading problem especially when getInstance() is called. 0061 // There is a bad behaviour with first instance initialization and mutex. 0062 friend class Partons; 0063 0064 sf::Mutex m_mutex; ///< Mutex to secure concurrent access to the map of instanciated obejcts. 0065 0066 BaseObjectRegistry* m_pBaseObjectRegistry; ///< Pointer to ask BaseObjectRegistry pointer associated to a specific object class. 0067 0068 std::map<unsigned int, BaseObject*> m_pInstantiatedObject; ///< Store BaseObject pointer created by the factory; used at the end of the program to delete orphan pointer. 0069 0070 /** 0071 * Private default constructor to ensure the creation of a single instance of the class, managed by Parton's class. 0072 * 0073 * @param pBaseObjectRegistry 0074 */ 0075 BaseObjectFactory(BaseObjectRegistry* pBaseObjectRegistry); 0076 0077 /** 0078 * Store cloned object pointer to its instantiated object map. 0079 * 0080 * @param pBaseObject 0081 */ 0082 void store(BaseObject* pBaseObject); 0083 }; 0084 0085 } /* namespace PARTONS */ 0086 0087 #endif /* BASE_OBJECT_FACTORY_H */
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|