MyGUI_FactoryManager.cpp
Go to the documentation of this file.
/*
* This source file is part of MyGUI. For the latest info, see http://mygui.info/
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/
#include "MyGUI_Precompiled.h"
#include "MyGUI_FactoryManager.h"
#include "MyGUI_BackwardCompatibility.h"
namespace MyGUI
{
MYGUI_SINGLETON_DEFINITION(FactoryManager);
FactoryManager::FactoryManager() :
mSingletonHolder(this)
{
}
void FactoryManager::initialise()
{
MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
mIsInitialise = true;
}
void FactoryManager::shutdown()
{
MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
mIsInitialise = false;
}
void FactoryManager::registerFactory(
std::string_view _category,
std::string_view _type,
Delegate::IDelegate* _delegate)
{
//FIXME
auto category = mRegisterFactoryItems.find(_category);
if (category == mRegisterFactoryItems.end())
category = mRegisterFactoryItems.emplace(_category, MapFactoryItem()).first;
auto type = category->second.find(_type);
if (type == category->second.end())
type = category->second.emplace(_type, Delegate()).first;
type->second = _delegate;
}
void FactoryManager::unregisterFactory(std::string_view _category, std::string_view _type)
{
MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category);
if (category == mRegisterFactoryItems.end())
{
return;
}
MapFactoryItem::iterator type = category->second.find(_type);
if (type == category->second.end())
{
return;
}
category->second.erase(type);
}
void FactoryManager::unregisterFactory(std::string_view _category)
{
MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category);
if (category == mRegisterFactoryItems.end())
{
return;
}
mRegisterFactoryItems.erase(category);
}
IObject* FactoryManager::createObject(std::string_view _category, std::string_view _type)
{
MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category);
if (category == mRegisterFactoryItems.end())
{
return nullptr;
}
std::string_view typeName = BackwardCompatibility::getFactoryRename(_category, _type);
MapFactoryItem::iterator type = category->second.find(typeName);
if (type == category->second.end())
{
return nullptr;
}
if (type->second.empty())
{
return nullptr;
}
IObject* result = nullptr;
type->second(result);
return result;
}
void FactoryManager::destroyObject(IObject* _object)
{
delete _object;
/*MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category);
if (category == mRegisterFactoryItems.end())
{
return;
}
MapFactoryItem::iterator type = category->second.find(_type);
if (type == category->second.end())
{
return;
}
if (type->second.empty())
{
return;
}
type->second(_object, nullptr, _version);*/
}
bool FactoryManager::isFactoryExist(std::string_view _category, std::string_view _type)
{
MapRegisterFactoryItem::iterator category = mRegisterFactoryItems.find(_category);
if (category == mRegisterFactoryItems.end())
{
return false;
}
return category->second.find(_type) != category->second.end();
}
} // namespace MyGUI
MyGUI_BackwardCompatibility.h
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition MyGUI_Diagnostic.h:31
MYGUI_LOG
#define MYGUI_LOG(level, text)
Definition MyGUI_Diagnostic.h:17
MyGUI_FactoryManager.h
MyGUI_Precompiled.h
MYGUI_SINGLETON_DEFINITION
#define MYGUI_SINGLETON_DEFINITION(ClassName)
Definition MyGUI_Singleton.h:126
MyGUI::BackwardCompatibility::getFactoryRename
static std::string_view getFactoryRename(std::string_view _categoryName, std::string_view _factoryName)
Definition MyGUI_BackwardCompatibility.cpp:1320
MyGUI::FactoryManager
Definition MyGUI_FactoryManager.h:19
MyGUI::FactoryManager::Delegate
delegates::Delegate< IObject *& > Delegate
Definition MyGUI_FactoryManager.h:28
MyGUI::FactoryManager::registerFactory
void registerFactory(std::string_view _category, std::string_view _type, Delegate::IDelegate *_delegate)
Definition MyGUI_FactoryManager.cpp:39
MyGUI::FactoryManager::isFactoryExist
bool isFactoryExist(std::string_view _category, std::string_view _type)
Definition MyGUI_FactoryManager.cpp:126
MyGUI::FactoryManager::unregisterFactory
void unregisterFactory(std::string_view _category, std::string_view _type)
Definition MyGUI_FactoryManager.cpp:54
MyGUI::FactoryManager::FactoryManager
FactoryManager()
Definition MyGUI_FactoryManager.cpp:16
MyGUI::FactoryManager::shutdown
void shutdown()
Definition MyGUI_FactoryManager.cpp:30
MyGUI::FactoryManager::destroyObject
void destroyObject(IObject *_object)
Definition MyGUI_FactoryManager.cpp:104
MyGUI::FactoryManager::initialise
void initialise()
Definition MyGUI_FactoryManager.cpp:21
MyGUI::FactoryManager::getClassTypeName
static std::string_view getClassTypeName()
MyGUI::FactoryManager::createObject
IObject * createObject(std::string_view _category, std::string_view _type)
Definition MyGUI_FactoryManager.cpp:80
MyGUI::IObject
Definition MyGUI_IObject.h:17
MyGUI::delegates::Delegate< IObject *& >::IDelegate
DelegateFunction< Args... > IDelegate
Definition MyGUI_Delegate.h:160
MyGUI
Definition MyGUI_ActionController.h:15