Browse Source

Filter searcher props by black list. Add NResource::Has()

m-milkin 1 year ago
parent
commit
387c914d75

+ 4 - 0
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

+ 1 - 0
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;

+ 4 - 0
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;
 

+ 2 - 1
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);

+ 5 - 0
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);
+    }
 }