整理代码
This commit is contained in:
commit
c7b4e178ec
364 changed files with 59691 additions and 0 deletions
63
util/BuilderSet.h
Normal file
63
util/BuilderSet.h
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
#ifndef BE7ED734_3D5C_4600_89C3_4082EB263BE0
|
||||
#define BE7ED734_3D5C_4600_89C3_4082EB263BE0
|
||||
/*
|
||||
*******************************************************************************
|
||||
* INCLUDE
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include <Poco/SharedPtr.h>
|
||||
#include <map>
|
||||
|
||||
namespace Util
|
||||
{
|
||||
/*
|
||||
*******************************************************************************
|
||||
* CLASS DECLARE
|
||||
*******************************************************************************
|
||||
*/
|
||||
template <class T, class TKey, class TSelector, class... TArgs> class BuilderSet
|
||||
{
|
||||
private:
|
||||
class IBuilder
|
||||
{
|
||||
public:
|
||||
using Ptr = Poco::SharedPtr<IBuilder>;
|
||||
virtual ~IBuilder()
|
||||
{
|
||||
}
|
||||
|
||||
virtual T* build(TArgs... args) = 0;
|
||||
};
|
||||
|
||||
template <class C> class Builder: public IBuilder
|
||||
{
|
||||
public:
|
||||
C* build(TArgs... args) override
|
||||
{
|
||||
C* p = new C(args...);
|
||||
return p;
|
||||
}
|
||||
};
|
||||
|
||||
using Builders = std::map<TKey, typename IBuilder::Ptr>;
|
||||
|
||||
public:
|
||||
static T* build(TArgs... args)
|
||||
{
|
||||
TKey key = TSelector::select(args...);
|
||||
return _builders[key]->build(args...);
|
||||
}
|
||||
|
||||
template <class C> static void registerClass(TKey key)
|
||||
{
|
||||
_builders[key] = new Builder<C>();
|
||||
}
|
||||
|
||||
private:
|
||||
static Builders _builders;
|
||||
};
|
||||
|
||||
template <class T, class TKey, class TSelect, class... TArgs>
|
||||
typename BuilderSet<T, TKey, TSelect, TArgs...>::Builders BuilderSet<T, TKey, TSelect, TArgs...>::_builders;
|
||||
}
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue