aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/resource/resource.cpp
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/resource/resource.cpp
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/resource/resource.cpp')
-rw-r--r--library/cpp/resource/resource.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/library/cpp/resource/resource.cpp b/library/cpp/resource/resource.cpp
new file mode 100644
index 00000000000..cc20f847a5f
--- /dev/null
+++ b/library/cpp/resource/resource.cpp
@@ -0,0 +1,57 @@
+#include "resource.h"
+#include "resource.h"
+#include "registry.h"
+
+#include <util/generic/yexception.h>
+#include <util/generic/xrange.h>
+
+using namespace NResource;
+
+bool NResource::FindExact(const TStringBuf key, TString* out) {
+ return CommonStore()->FindExact(key, out);
+}
+
+void NResource::FindMatch(const TStringBuf subkey, TResources* out) {
+ 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);
+}
+
+TString NResource::Find(const TStringBuf key) {
+ TString ret;
+
+ 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);
+}
+
+TVector<TStringBuf> NResource::ListAllKeys() {
+ TVector<TStringBuf> res(Reserve(NResource::Count()));
+ for (auto i : xrange(NResource::Count())) {
+ res.push_back(NResource::KeyByIndex(i));
+ }
+ return res;
+}