/** * @file factory.hpp * @author Julian Iseringhausen * @date Tue Apr 5 20:40:41 2011 * * @brief Factory class that holds commands and arbitrary objects. * * */ #ifndef COMMAND_FACTORY_HPP_ #define COMMAND_FACTORY_HPP_ #include #include #include #include "base/object.hpp" #include "base/proxy.hpp" namespace VMG { class Object; class Factory { public: typedef std::map::iterator command_iterator; typedef std::map::iterator instance_iterator; typedef std::map::iterator object_iterator; Factory(); virtual ~Factory(); void Destroy(); void RegisterCommand(CommandProxyBase* command); ///< Register a command void RegisterObject(Object* object); ///< Register an object /** * Register an arbitrary object that is not derived from Object. * Similar functionality can be achieved by calling * "new ObjectStorage(id, data);" */ template void RegisterObjectStorage(std::string id, const T& data); template T& GetObjectStorageVal(std::string id); void DeleteCommand(std::string id); ///< Delete a command void DeleteObject(std::string id); ///< Delete an object Command* GetCommand(std::string id); ///< Returns a command. Object* GetObject(std::string id); ///< Returns an object. /** * Checks for the correct number of arguments. This check is * automatically performed, whenever a command is executed from * a command list (if the library has not been compiled with NDEBUG). */ bool CheckNumberOfArguments(std::string id, const int& num_arguments); void PrintAvailableCommands(); ///< Prints the name of all commands that have been registered to the factory. void PrintAvailableObjects(); ///< Prints the name of all objects that have been registered to the factory. private: std::map command_map; std::map command_instance_map; std::map object_map; }; template void Factory::RegisterObjectStorage(std::string id, const T& data) { new ObjectStorage(id, data); } template T& Factory::GetObjectStorageVal(std::string id) { return GetObject(id)->Cast< ObjectStorage >()->Val(); } } #endif /* COMMAND_FACTORY_HPP_ */