diff options
author | m-milkin <m-milkin@yandex-team.com> | 2023-03-24 15:34:13 +0300 |
---|---|---|
committer | m-milkin <m-milkin@yandex-team.com> | 2023-03-24 15:34:13 +0300 |
commit | 387c914d75e04773da90dcf623982a47909c19d2 (patch) | |
tree | 2aee2c5f92c70eac1e34206307d910c8c360f585 /library/cpp/resource | |
parent | f8d946ba7430c3864f0a97d42fa295d19ed40a3e (diff) | |
download | ydb-387c914d75e04773da90dcf623982a47909c19d2.tar.gz |
Filter searcher props by black list. Add NResource::Has()
Diffstat (limited to 'library/cpp/resource')
-rw-r--r-- | library/cpp/resource/registry.cpp | 4 | ||||
-rw-r--r-- | library/cpp/resource/registry.h | 1 | ||||
-rw-r--r-- | library/cpp/resource/resource.cpp | 4 | ||||
-rw-r--r-- | library/cpp/resource/resource.h | 3 | ||||
-rw-r--r-- | library/cpp/resource/ut/resource_ut.cpp | 5 |
5 files changed, 16 insertions, 1 deletions
diff --git a/library/cpp/resource/registry.cpp b/library/cpp/resource/registry.cpp index e0da3402a5..6f5ff85c63 100644 --- a/library/cpp/resource/registry.cpp +++ b/library/cpp/resource/registry.cpp @@ -49,6 +49,10 @@ namespace { Y_VERIFY(size() == Count(), "size mismatch"); } + bool Has(const TStringBuf key) const override { + return contains(key); + } + bool FindExact(const TStringBuf key, TString* out) const override { if (TDescriptor* const* res = FindPtr(key)) { // temporary diff --git a/library/cpp/resource/registry.h b/library/cpp/resource/registry.h index fe67702cbc..a2d0ef768d 100644 --- a/library/cpp/resource/registry.h +++ b/library/cpp/resource/registry.h @@ -17,6 +17,7 @@ namespace NResource { class IStore { public: virtual void Store(const TStringBuf key, const TStringBuf data) = 0; + virtual bool Has(const TStringBuf key) const = 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; diff --git a/library/cpp/resource/resource.cpp b/library/cpp/resource/resource.cpp index cc20f847a5..f21c629d18 100644 --- a/library/cpp/resource/resource.cpp +++ b/library/cpp/resource/resource.cpp @@ -30,6 +30,10 @@ void NResource::FindMatch(const TStringBuf subkey, TResources* out) { CommonStore()->FindMatch(subkey, m); } +bool NResource::Has(const TStringBuf key) { + return CommonStore()->Has(key); +} + TString NResource::Find(const TStringBuf key) { TString ret; diff --git a/library/cpp/resource/resource.h b/library/cpp/resource/resource.h index 42dd0f1891..335074104a 100644 --- a/library/cpp/resource/resource.h +++ b/library/cpp/resource/resource.h @@ -12,9 +12,10 @@ namespace NResource { typedef TVector<TResource> TResources; + bool Has(const TStringBuf key); TString Find(const TStringBuf key); bool FindExact(const TStringBuf key, TString* out); - //perform full scan for now + /// @note Perform full scan for now. void FindMatch(const TStringBuf subkey, TResources* out); size_t Count() noexcept; TStringBuf KeyByIndex(size_t idx); diff --git a/library/cpp/resource/ut/resource_ut.cpp b/library/cpp/resource/ut/resource_ut.cpp index b6fa8e4df3..67cf77c571 100644 --- a/library/cpp/resource/ut/resource_ut.cpp +++ b/library/cpp/resource/ut/resource_ut.cpp @@ -5,4 +5,9 @@ Y_UNIT_TEST_SUITE(TestResource) { Y_UNIT_TEST(Test1) { UNIT_ASSERT_VALUES_EQUAL(NResource::Find("/x"), "na gorshke sidel korol\n"); } + + Y_UNIT_TEST(TestHasFunc) { + UNIT_ASSERT_VALUES_EQUAL(NResource::Has("/x"), true); + UNIT_ASSERT_VALUES_EQUAL(NResource::Has("/y"), false); + } } |