diff options
author | evelkin <evelkin@yandex-team.ru> | 2022-02-10 16:49:25 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:25 +0300 |
commit | 7510cec1516d17cbc8d7749974e36aa45f547a26 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/object_factory | |
parent | f9f914a9d510572fa0d68959aaea41be5839ff3d (diff) | |
download | ydb-7510cec1516d17cbc8d7749974e36aa45f547a26.tar.gz |
Restoring authorship annotation for <evelkin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/object_factory')
-rw-r--r-- | library/cpp/object_factory/object_factory.h | 34 | ||||
-rw-r--r-- | library/cpp/object_factory/object_factory_ut.cpp | 56 |
2 files changed, 45 insertions, 45 deletions
diff --git a/library/cpp/object_factory/object_factory.h b/library/cpp/object_factory/object_factory.h index e77d0c28fc..96cc11bcfd 100644 --- a/library/cpp/object_factory/object_factory.h +++ b/library/cpp/object_factory/object_factory.h @@ -54,20 +54,20 @@ namespace NObjectFactory { public: template <class TDerivedProduct> - void Register(const TKey& key, IFactoryObjectCreator<TProduct, TArgs...>* creator) { + void Register(const TKey& key, IFactoryObjectCreator<TProduct, TArgs...>* creator) { if (!creator) - ythrow yexception() << "Please specify non-null creator for " << key; + ythrow yexception() << "Please specify non-null creator for " << key; TWriteGuard guard(CreatorsLock); if (!Creators.insert(typename ICreators::value_type(key, creator)).second) ythrow yexception() << "Product with key " << key << " already registered"; } - template <class TDerivedProduct> - void Register(const TKey& key) { - Register<TDerivedProduct>(key, new TFactoryObjectCreator<TProduct, TDerivedProduct, TArgs...>); - } - + template <class TDerivedProduct> + void Register(const TKey& key) { + Register<TDerivedProduct>(key, new TFactoryObjectCreator<TProduct, TDerivedProduct, TArgs...>); + } + void GetKeys(TSet<TKey>& keys) const { TReadGuard guard(CreatorsLock); keys.clear(); @@ -165,14 +165,14 @@ namespace NObjectFactory { template <class Product> class TRegistrator { public: - TRegistrator(const TKey& key, IFactoryObjectCreator<TProduct, void>* creator) { + TRegistrator(const TKey& key, IFactoryObjectCreator<TProduct, void>* creator) { Singleton<TObjectFactory<TProduct, TKey>>()->template Register<Product>(key, creator); } - TRegistrator(const TKey& key) { - Singleton<TObjectFactory<TProduct, TKey>>()->template Register<Product>(key); - } - + TRegistrator(const TKey& key) { + Singleton<TObjectFactory<TProduct, TKey>>()->template Register<Product>(key); + } + TRegistrator() : TRegistrator(Product::GetTypeName()) { @@ -221,14 +221,14 @@ namespace NObjectFactory { template <class Product> class TRegistrator { public: - TRegistrator(const TKey& key, IFactoryObjectCreator<TProduct, TArgs...>* creator) { + TRegistrator(const TKey& key, IFactoryObjectCreator<TProduct, TArgs...>* creator) { Singleton<TParametrizedObjectFactory<TProduct, TKey, TArgs...>>()->template Register<Product>(key, creator); } - TRegistrator(const TKey& key) { - Singleton<TParametrizedObjectFactory<TProduct, TKey, TArgs...>>()->template Register<Product>(key); - } - + TRegistrator(const TKey& key) { + Singleton<TParametrizedObjectFactory<TProduct, TKey, TArgs...>>()->template Register<Product>(key); + } + TRegistrator() : TRegistrator(Product::GetTypeName()) { diff --git a/library/cpp/object_factory/object_factory_ut.cpp b/library/cpp/object_factory/object_factory_ut.cpp index 5bb2b75bf2..06fb0739ff 100644 --- a/library/cpp/object_factory/object_factory_ut.cpp +++ b/library/cpp/object_factory/object_factory_ut.cpp @@ -123,25 +123,25 @@ using TMoveableOnly2Factory = TParametrizedObjectFactory<IMoveableOnlyInterface, static TMoveableOnly2Factory::TRegistrator<TMoveableOnly2> MoveableOnly2Reg("move2"); -class TDirectOrderDifferentSignature : public TDirectOrder { -public: - TDirectOrderDifferentSignature(const TString& provider, TArgument& argument) : - TDirectOrder(provider, 0.01f, argument) - { - } - -}; - -struct TDirectOrderDSCreator: public IFactoryObjectCreator<ICommonInterface, const TString&, float, TArgument&> { - ICommonInterface* Create(const TString& provider, float factor, TArgument& argument) const override { - Y_UNUSED(factor); - return new TDirectOrderDifferentSignature(provider, argument); - } -}; - - -static TTestFactory::TRegistrator<TDirectOrderDifferentSignature> DirectDs("direct_ds", new TDirectOrderDSCreator); - +class TDirectOrderDifferentSignature : public TDirectOrder { +public: + TDirectOrderDifferentSignature(const TString& provider, TArgument& argument) : + TDirectOrder(provider, 0.01f, argument) + { + } + +}; + +struct TDirectOrderDSCreator: public IFactoryObjectCreator<ICommonInterface, const TString&, float, TArgument&> { + ICommonInterface* Create(const TString& provider, float factor, TArgument& argument) const override { + Y_UNUSED(factor); + return new TDirectOrderDifferentSignature(provider, argument); + } +}; + + +static TTestFactory::TRegistrator<TDirectOrderDifferentSignature> DirectDs("direct_ds", new TDirectOrderDSCreator); + Y_UNIT_TEST_SUITE(TestObjectFactory) { Y_UNIT_TEST(TestParametrized) { TArgument directArg{"Name", nullptr}; @@ -177,13 +177,13 @@ Y_UNIT_TEST_SUITE(TestObjectFactory) { UNIT_ASSERT(moveableOnly2->GetValue() == "value2"); } - - Y_UNIT_TEST(TestDifferentSignature) { - TArgument directArg{"Name", nullptr}; - THolder<ICommonInterface> directDs(TTestFactory::Construct("direct_ds", "prov", 0.42, directArg)); - - UNIT_ASSERT(!!directDs); - - UNIT_ASSERT_EQUAL(directDs->GetValue(), "prov0.01Name"); - } + + Y_UNIT_TEST(TestDifferentSignature) { + TArgument directArg{"Name", nullptr}; + THolder<ICommonInterface> directDs(TTestFactory::Construct("direct_ds", "prov", 0.42, directArg)); + + UNIT_ASSERT(!!directDs); + + UNIT_ASSERT_EQUAL(directDs->GetValue(), "prov0.01Name"); + } } |