diff options
author | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-02-10 21:59:03 +0300 |
---|---|---|
committer | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-02-10 21:59:03 +0300 |
commit | 364350511fa304a5ba5c362849dc160fddf67a27 (patch) | |
tree | 01a83b98f97bececf0b7a077e7e9d6e9ad5186e1 | |
parent | 4b285c9638a11b796314e7f10a77a6def9580f11 (diff) | |
download | ydb-364350511fa304a5ba5c362849dc160fddf67a27.tar.gz |
intermediate changes
ref:1bf51835ea7425767532e1b783b23a0d09a0a88e
-rw-r--r-- | contrib/libs/ya.make | 1 | ||||
-rw-r--r-- | library/cpp/object_factory/object_factory.h | 102 | ||||
-rw-r--r-- | library/cpp/yson/node/node_io.h | 2 |
3 files changed, 20 insertions, 85 deletions
diff --git a/contrib/libs/ya.make b/contrib/libs/ya.make index f49afe35b4..62088154b3 100644 --- a/contrib/libs/ya.make +++ b/contrib/libs/ya.make @@ -206,7 +206,6 @@ RECURSE( linux-headers linuxvdso liquidfun - llvm11 llvm12 llvm8 lmdbxx diff --git a/library/cpp/object_factory/object_factory.h b/library/cpp/object_factory/object_factory.h index 96cc11bcfd..c961cbbd56 100644 --- a/library/cpp/object_factory/object_factory.h +++ b/library/cpp/object_factory/object_factory.h @@ -95,39 +95,33 @@ namespace NObjectFactory { TRWMutex CreatorsLock; }; - template <class TProduct, class TKey> - class TObjectFactory: public IObjectFactory<TProduct, TKey, void> { + template <class TProduct, class TKey, class... TArgs> + class TParametrizedObjectFactory: public IObjectFactory<TProduct, TKey, TArgs...> { public: - TProduct* Create(const TKey& key) const { - IFactoryObjectCreator<TProduct, void>* creator = IObjectFactory<TProduct, TKey, void>::GetCreator(key); - return creator == nullptr ? nullptr : creator->Create(); + TProduct* Create(const TKey& key, TArgs... args) const { + IFactoryObjectCreator<TProduct, TArgs...>* creator = IObjectFactory<TProduct, TKey, TArgs...>::GetCreator(key); + return creator == nullptr ? nullptr : creator->Create(std::forward<TArgs>(args)...); } - static TString KeysDebugString() { - TSet<TString> keys; - Singleton<TObjectFactory<TProduct, TKey>>()->GetKeys(keys); - TString keysStr; - for (auto&& k : keys) { - keysStr += k + " "; - } - return keysStr; + static bool Has(const TKey& key) { + return Singleton<TParametrizedObjectFactory<TProduct, TKey, TArgs...>>()->HasImpl(key); } - static TProduct* Construct(const TKey& key, const TKey& defKey) { - TProduct* result = Singleton<TObjectFactory<TProduct, TKey>>()->Create(key); + static TProduct* Construct(const TKey& key, const TKey& defKey, TArgs... args) { + TProduct* result = Singleton<TParametrizedObjectFactory<TProduct, TKey, TArgs...>>()->Create(key, std::forward<TArgs>(args)...); if (!result && !!defKey) { - result = Singleton<TObjectFactory<TProduct, TKey>>()->Create(defKey); + result = Singleton<TParametrizedObjectFactory<TProduct, TKey, TArgs...>>()->Create(defKey, std::forward<TArgs>(args)...); } return result; } - static TProduct* Construct(const TKey& key) { - TProduct* result = Singleton<TObjectFactory<TProduct, TKey>>()->Create(key); - return result; + static TProduct* Construct(const TKey& key, TArgs... args) { + return Singleton<TParametrizedObjectFactory<TProduct, TKey, TArgs...>>()->Create(key, std::forward<TArgs>(args)...); } - static THolder<TProduct> VerifiedConstruct(const TKey& key) { - auto result = MakeHolder(key); + template <class... Args> + static THolder<TProduct> VerifiedConstruct(Args&&... args) { + auto result = MakeHolder(std::forward<Args>(args)...); Y_VERIFY(result, "Construct by factory failed"); return result; } @@ -137,17 +131,13 @@ namespace NObjectFactory { return THolder<TProduct>(Construct(std::forward<Args>(args)...)); } - static bool Has(const TKey& key) { - return Singleton<TObjectFactory<TProduct, TKey>>()->HasImpl(key); - } - static void GetRegisteredKeys(TSet<TKey>& keys) { - return Singleton<TObjectFactory<TProduct, TKey>>()->GetKeys(keys); + return Singleton<TParametrizedObjectFactory<TProduct, TKey, TArgs...>>()->GetKeys(keys); } static TSet<TKey> GetRegisteredKeys() { TSet<TKey> keys; - Singleton<TObjectFactory<TProduct, TKey>>()->GetKeys(keys); + Singleton<TParametrizedObjectFactory<TProduct, TKey, TArgs...>>()->GetKeys(keys); return keys; } @@ -165,62 +155,6 @@ namespace NObjectFactory { template <class Product> class TRegistrator { public: - 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() - : TRegistrator(Product::GetTypeName()) - { - } - }; - }; - - template <class TProduct, class TKey, class... TArgs> - class TParametrizedObjectFactory: public IObjectFactory<TProduct, TKey, TArgs...> { - public: - TProduct* Create(const TKey& key, TArgs... args) const { - IFactoryObjectCreator<TProduct, TArgs...>* creator = IObjectFactory<TProduct, TKey, TArgs...>::GetCreator(key); - return creator == nullptr ? nullptr : creator->Create(std::forward<TArgs>(args)...); - } - - static bool Has(const TKey& key) { - return Singleton<TParametrizedObjectFactory<TProduct, TKey, TArgs...>>()->HasImpl(key); - } - - static TProduct* Construct(const TKey& key, TArgs... args) { - return Singleton<TParametrizedObjectFactory<TProduct, TKey, TArgs...>>()->Create(key, std::forward<TArgs>(args)...); - } - - template <class... Args> - static THolder<TProduct> VerifiedConstruct(Args&&... args) { - auto result = MakeHolder(std::forward<Args>(args)...); - Y_VERIFY(result, "Construct by factory failed"); - return result; - } - - template<class... Args> - static THolder<TProduct> MakeHolder(Args&&... args) { - return THolder<TProduct>(Construct(std::forward<Args>(args)...)); - } - - static void GetRegisteredKeys(TSet<TKey>& keys) { - return Singleton<TParametrizedObjectFactory<TProduct, TKey, TArgs...>>()->GetKeys(keys); - } - - static TSet<TKey> GetRegisteredKeys() { - TSet<TKey> keys; - Singleton<TParametrizedObjectFactory<TProduct, TKey, TArgs...>>()->GetKeys(keys); - return keys; - } - - template <class Product> - class TRegistrator { - public: TRegistrator(const TKey& key, IFactoryObjectCreator<TProduct, TArgs...>* creator) { Singleton<TParametrizedObjectFactory<TProduct, TKey, TArgs...>>()->template Register<Product>(key, creator); } @@ -240,4 +174,6 @@ namespace NObjectFactory { }; }; + template <class TProduct, class TKey, class... TArgs> + using TObjectFactory = TParametrizedObjectFactory<TProduct, TKey, TArgs...>; } diff --git a/library/cpp/yson/node/node_io.h b/library/cpp/yson/node/node_io.h index 2ad23b658f..454e2b14e7 100644 --- a/library/cpp/yson/node/node_io.h +++ b/library/cpp/yson/node/node_io.h @@ -33,7 +33,7 @@ void NodeToCanonicalYsonStream(const TNode& node, IOutputStream* output, ::NYson TNode NodeFromJsonString(const TStringBuf input); // Convert TJsonValue to TNode -TNode NodeFromJsonValue(const NJson::TJsonValue& input); +TNode NodeFromJsonValue(const ::NJson::TJsonValue& input); //////////////////////////////////////////////////////////////////////////////// |