aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/resource
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:17 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:17 +0300
commitd3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch)
treedd4bd3ca0f36b817e96812825ffaf10d645803f2 /library/cpp/resource
parent72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff)
downloadydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/resource')
-rw-r--r--library/cpp/resource/registry.cpp112
-rw-r--r--library/cpp/resource/registry.h50
-rw-r--r--library/cpp/resource/resource.cpp82
-rw-r--r--library/cpp/resource/resource.h28
-rw-r--r--library/cpp/resource/ut/lib/data2
-rw-r--r--library/cpp/resource/ut/lib/ya.make18
-rw-r--r--library/cpp/resource/ut/resource_ut.cpp8
-rw-r--r--library/cpp/resource/ut/ya.make16
-rw-r--r--library/cpp/resource/ya.make26
9 files changed, 171 insertions, 171 deletions
diff --git a/library/cpp/resource/registry.cpp b/library/cpp/resource/registry.cpp
index 9ff8f09bb4..66001c4769 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 a15e000e0a..fe67702cbc 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 a8c2443662..cc20f847a5 100644
--- a/library/cpp/resource/resource.cpp
+++ b/library/cpp/resource/resource.cpp
@@ -1,52 +1,52 @@
-#include "resource.h"
#include "resource.h"
-#include "registry.h"
-
-#include <util/generic/yexception.h>
+#include "resource.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 18aa5bd6b2..42dd0f1891 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 ef4df624f3..50e37d5cac 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 e361cc2c41..48b92b9c8f 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 7a4f622e15..b6fa8e4df3 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 52ea5b4092..d1ac9ed2ed 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 fa85892cc6..9c06df514f 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()