diff options
author | karpik <karpik@yandex-team.ru> | 2022-02-10 16:49:23 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:23 +0300 |
commit | eb4b8b8ee0d18f168ae14f4d88a6efe2498e0f78 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/binsaver/class_factory.h | |
parent | 9cb2cb2fdceae44848ab4504f5e445015b0eca6e (diff) | |
download | ydb-eb4b8b8ee0d18f168ae14f4d88a6efe2498e0f78.tar.gz |
Restoring authorship annotation for <karpik@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/binsaver/class_factory.h')
-rw-r--r-- | library/cpp/binsaver/class_factory.h | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/library/cpp/binsaver/class_factory.h b/library/cpp/binsaver/class_factory.h index 704ae9fb4b..e83512331b 100644 --- a/library/cpp/binsaver/class_factory.h +++ b/library/cpp/binsaver/class_factory.h @@ -1,27 +1,27 @@ -#pragma once +#pragma once -#include <typeinfo> +#include <typeinfo> #include <util/generic/hash.h> #include <util/generic/vector.h> #include <util/ysafeptr.h> - -//////////////////////////////////////////////////////////////////////////////////////////////////// -// factory is using RTTI -// objects should inherit T and T must have at least 1 virtual function -template <class T> + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// factory is using RTTI +// objects should inherit T and T must have at least 1 virtual function +template <class T> class TClassFactory { -public: +public: typedef const std::type_info* VFT; -private: +private: typedef T* (*newFunc)(); typedef THashMap<int, newFunc> CTypeNewHash; // typeID->newFunc() typedef THashMap<VFT, int> CTypeIndexHash; // vftable->typeID - + CTypeIndexHash typeIndex; CTypeNewHash typeInfo; - + void RegisterTypeBase(int nTypeID, newFunc func, VFT vft); static VFT GetObjectType(T* pObject) { return &typeid(*pObject); @@ -39,7 +39,7 @@ private: return -1; } -public: +public: template <class TT> void RegisterType(int nTypeID, newFunc func, TT*) { RegisterTypeBase(nTypeID, func, &typeid(TT)); @@ -72,9 +72,9 @@ public: typeIds.push_back(iter->first); } } -}; -//////////////////////////////////////////////////////////////////////////////////////////////////// -template <class T> +}; +//////////////////////////////////////////////////////////////////////////////////////////////////// +template <class T> void TClassFactory<T>::RegisterTypeBase(int nTypeID, newFunc func, VFT vft) { if (typeInfo.find(nTypeID) != typeInfo.end()) { TObj<IObjectBase> o1 = typeInfo[nTypeID](); @@ -97,9 +97,9 @@ void TClassFactory<T>::RegisterTypeBase(int nTypeID, newFunc func, VFT vft) { } typeIndex[vft] = nTypeID; typeInfo[nTypeID] = func; -} -//////////////////////////////////////////////////////////////////////////////////////////////////// -// macro for registering CFundament derivatives +} +//////////////////////////////////////////////////////////////////////////////////////////////////// +// macro for registering CFundament derivatives #define REGISTER_CLASS(factory, N, name) factory.RegisterType(N, name::New##name, (name*)0); #define REGISTER_TEMPL_CLASS(factory, N, name, className) factory.RegisterType(N, name::New##className, (name*)0); #define REGISTER_CLASS_NM(factory, N, name, nmspace) factory.RegisterType(N, nmspace::name::New##name, (nmspace::name*)0); |