diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /library/cpp/resource | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/resource')
-rw-r--r-- | library/cpp/resource/registry.cpp | 112 | ||||
-rw-r--r-- | library/cpp/resource/registry.h | 50 | ||||
-rw-r--r-- | library/cpp/resource/resource.cpp | 82 | ||||
-rw-r--r-- | library/cpp/resource/resource.h | 28 | ||||
-rw-r--r-- | library/cpp/resource/ut/lib/data | 2 | ||||
-rw-r--r-- | library/cpp/resource/ut/lib/ya.make | 18 | ||||
-rw-r--r-- | library/cpp/resource/ut/resource_ut.cpp | 8 | ||||
-rw-r--r-- | library/cpp/resource/ut/ya.make | 16 | ||||
-rw-r--r-- | library/cpp/resource/ya.make | 26 |
9 files changed, 171 insertions, 171 deletions
diff --git a/library/cpp/resource/registry.cpp b/library/cpp/resource/registry.cpp index 66001c4769..9ff8f09bb4 100644 --- a/library/cpp/resource/registry.cpp +++ b/library/cpp/resource/registry.cpp @@ -1,25 +1,25 @@ -#include "registry.h" - +#include "registry.h" + #include <library/cpp/blockcodecs/codecs.h> - -#include <util/system/yassert.h> -#include <util/generic/hash.h> -#include <util/generic/deque.h> -#include <util/generic/singleton.h> + +#include <util/system/yassert.h> +#include <util/generic/hash.h> +#include <util/generic/deque.h> +#include <util/generic/singleton.h> #include <util/system/env.h> - -using namespace NResource; -using namespace NBlockCodecs; - -namespace { + +using namespace NResource; +using namespace NBlockCodecs; + +namespace { inline const ICodec* GetCodec() noexcept { - static const ICodec* ret = Codec("zstd08_5"); - - return ret; - } - + static const ICodec* ret = Codec("zstd08_5"); + + return ret; + } + typedef std::pair<TStringBuf, TStringBuf> TDescriptor; - + struct TStore: public IStore, public THashMap<TStringBuf, TDescriptor*> { void Store(const TStringBuf key, const TStringBuf data) override { if (contains(key)) { @@ -41,16 +41,16 @@ namespace { TString{key}.Quote().c_str(), vsize, dsize); } } - } else { - D_.push_back(TDescriptor(key, data)); - (*this)[key] = &D_.back(); - } - + } else { + D_.push_back(TDescriptor(key, data)); + (*this)[key] = &D_.back(); + } + Y_VERIFY(size() == Count(), "size mismatch"); - } - + } + bool FindExact(const TStringBuf key, TString* out) const override { - if (TDescriptor* const* res = FindPtr(key)) { + if (TDescriptor* const* res = FindPtr(key)) { // temporary // https://st.yandex-team.ru/DEVTOOLS-3985 try { @@ -61,13 +61,13 @@ namespace { } throw e; } - - return true; - } - - return false; - } - + + return true; + } + + return false; + } + void FindMatch(const TStringBuf subkey, IMatch& cb) const override { for (const auto& it : *this) { if (it.first.StartsWith(subkey)) { @@ -83,31 +83,31 @@ namespace { } throw e; } - } - } - } - + } + } + } + size_t Count() const noexcept override { - return D_.size(); - } - + return D_.size(); + } + TStringBuf KeyByIndex(size_t idx) const override { - return D_.at(idx).first; - } - + return D_.at(idx).first; + } + typedef TDeque<TDescriptor> TDescriptors; - TDescriptors D_; - }; -} - + TDescriptors D_; + }; +} + TString NResource::Compress(const TStringBuf data) { - return GetCodec()->Encode(data); -} - + return GetCodec()->Encode(data); +} + TString NResource::Decompress(const TStringBuf data) { - return GetCodec()->Decode(data); -} - -IStore* NResource::CommonStore() { - return SingletonWithPriority<TStore, 0>(); -} + return GetCodec()->Decode(data); +} + +IStore* NResource::CommonStore() { + return SingletonWithPriority<TStore, 0>(); +} diff --git a/library/cpp/resource/registry.h b/library/cpp/resource/registry.h index fe67702cbc..a15e000e0a 100644 --- a/library/cpp/resource/registry.h +++ b/library/cpp/resource/registry.h @@ -1,35 +1,35 @@ -#pragma once - +#pragma once + #include <util/generic/string.h> -#include <util/generic/strbuf.h> - -#include "resource.h" - -namespace NResource { +#include <util/generic/strbuf.h> + +#include "resource.h" + +namespace NResource { TString Compress(const TStringBuf data); TString Decompress(const TStringBuf data); - - class IMatch { - public: - virtual void OnMatch(const TResource& res) = 0; - }; - - class IStore { - public: + + class IMatch { + public: + virtual void OnMatch(const TResource& res) = 0; + }; + + class IStore { + public: virtual void Store(const TStringBuf key, const TStringBuf data) = 0; virtual bool FindExact(const TStringBuf key, TString* out) const = 0; virtual void FindMatch(const TStringBuf subkey, IMatch& cb) const = 0; virtual size_t Count() const noexcept = 0; - virtual TStringBuf KeyByIndex(size_t idx) const = 0; + virtual TStringBuf KeyByIndex(size_t idx) const = 0; virtual ~IStore() { } - }; - - IStore* CommonStore(); - - struct TRegHelper { + }; + + IStore* CommonStore(); + + struct TRegHelper { inline TRegHelper(const TStringBuf key, const TStringBuf data) { - CommonStore()->Store(key, data); - } - }; -} + CommonStore()->Store(key, data); + } + }; +} diff --git a/library/cpp/resource/resource.cpp b/library/cpp/resource/resource.cpp index cc20f847a5..a8c2443662 100644 --- a/library/cpp/resource/resource.cpp +++ b/library/cpp/resource/resource.cpp @@ -1,52 +1,52 @@ +#include "resource.h" #include "resource.h" -#include "resource.h" -#include "registry.h" - -#include <util/generic/yexception.h> +#include "registry.h" + +#include <util/generic/yexception.h> #include <util/generic/xrange.h> - -using namespace NResource; - + +using namespace NResource; + bool NResource::FindExact(const TStringBuf key, TString* out) { - return CommonStore()->FindExact(key, out); -} - + return CommonStore()->FindExact(key, out); +} + void NResource::FindMatch(const TStringBuf subkey, TResources* out) { - struct TMatch: public IMatch { - inline TMatch(TResources* r) - : R(r) - { - } - + struct TMatch: public IMatch { + inline TMatch(TResources* r) + : R(r) + { + } + void OnMatch(const TResource& res) override { - R->push_back(res); - } - - TResources* R; - }; - - TMatch m(out); - - CommonStore()->FindMatch(subkey, m); -} - + R->push_back(res); + } + + TResources* R; + }; + + TMatch m(out); + + CommonStore()->FindMatch(subkey, m); +} + TString NResource::Find(const TStringBuf key) { TString ret; - - if (FindExact(key, &ret)) { - return ret; - } - - ythrow yexception() << "can not find resource with path " << key; -} - + + if (FindExact(key, &ret)) { + return ret; + } + + ythrow yexception() << "can not find resource with path " << key; +} + size_t NResource::Count() noexcept { - return CommonStore()->Count(); -} - -TStringBuf NResource::KeyByIndex(size_t idx) { - return CommonStore()->KeyByIndex(idx); -} + return CommonStore()->Count(); +} + +TStringBuf NResource::KeyByIndex(size_t idx) { + return CommonStore()->KeyByIndex(idx); +} TVector<TStringBuf> NResource::ListAllKeys() { TVector<TStringBuf> res(Reserve(NResource::Count())); diff --git a/library/cpp/resource/resource.h b/library/cpp/resource/resource.h index 42dd0f1891..18aa5bd6b2 100644 --- a/library/cpp/resource/resource.h +++ b/library/cpp/resource/resource.h @@ -1,22 +1,22 @@ -#pragma once - +#pragma once + #include <util/generic/string.h> -#include <util/generic/strbuf.h> -#include <util/generic/vector.h> - -namespace NResource { - struct TResource { - TStringBuf Key; +#include <util/generic/strbuf.h> +#include <util/generic/vector.h> + +namespace NResource { + struct TResource { + TStringBuf Key; TString Data; - }; - + }; + typedef TVector<TResource> TResources; - + TString Find(const TStringBuf key); bool FindExact(const TStringBuf key, TString* out); - //perform full scan for now + //perform full scan for now void FindMatch(const TStringBuf subkey, TResources* out); size_t Count() noexcept; - TStringBuf KeyByIndex(size_t idx); + TStringBuf KeyByIndex(size_t idx); TVector<TStringBuf> ListAllKeys(); -} +} diff --git a/library/cpp/resource/ut/lib/data b/library/cpp/resource/ut/lib/data index 50e37d5cac..ef4df624f3 100644 --- a/library/cpp/resource/ut/lib/data +++ b/library/cpp/resource/ut/lib/data @@ -1 +1 @@ -na gorshke sidel korol +na gorshke sidel korol diff --git a/library/cpp/resource/ut/lib/ya.make b/library/cpp/resource/ut/lib/ya.make index 48b92b9c8f..e361cc2c41 100644 --- a/library/cpp/resource/ut/lib/ya.make +++ b/library/cpp/resource/ut/lib/ya.make @@ -1,9 +1,9 @@ -LIBRARY() - -OWNER(pg) - -RESOURCE( - data /x -) - -END() +LIBRARY() + +OWNER(pg) + +RESOURCE( + data /x +) + +END() diff --git a/library/cpp/resource/ut/resource_ut.cpp b/library/cpp/resource/ut/resource_ut.cpp index b6fa8e4df3..7a4f622e15 100644 --- a/library/cpp/resource/ut/resource_ut.cpp +++ b/library/cpp/resource/ut/resource_ut.cpp @@ -1,8 +1,8 @@ #include <library/cpp/resource/resource.h> #include <library/cpp/testing/unittest/registar.h> - + Y_UNIT_TEST_SUITE(TestResource) { Y_UNIT_TEST(Test1) { - UNIT_ASSERT_VALUES_EQUAL(NResource::Find("/x"), "na gorshke sidel korol\n"); - } -} + UNIT_ASSERT_VALUES_EQUAL(NResource::Find("/x"), "na gorshke sidel korol\n"); + } +} diff --git a/library/cpp/resource/ut/ya.make b/library/cpp/resource/ut/ya.make index d1ac9ed2ed..52ea5b4092 100644 --- a/library/cpp/resource/ut/ya.make +++ b/library/cpp/resource/ut/ya.make @@ -1,9 +1,9 @@ UNITTEST_FOR(library/cpp/resource/ut/lib) - -OWNER(pg) - -SRCS( - resource_ut.cpp -) - -END() + +OWNER(pg) + +SRCS( + resource_ut.cpp +) + +END() diff --git a/library/cpp/resource/ya.make b/library/cpp/resource/ya.make index 9c06df514f..fa85892cc6 100644 --- a/library/cpp/resource/ya.make +++ b/library/cpp/resource/ya.make @@ -1,15 +1,15 @@ -LIBRARY() - -OWNER(pg) - -PEERDIR( +LIBRARY() + +OWNER(pg) + +PEERDIR( library/cpp/blockcodecs/core library/cpp/blockcodecs/codecs/zstd -) - -SRCS( - registry.cpp - resource.cpp -) - -END() +) + +SRCS( + registry.cpp + resource.cpp +) + +END() |