aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authordiver <diver@yandex-team.ru>2022-02-10 16:48:07 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:48:07 +0300
commit7629e1f9ef7f9d2a3c345c97e6a4e5a4b32ee786 (patch)
treec3371bfa47641a52244267b63009d16e4e7054ff /util
parentcc573d2716c99ba22afc98753971cd97fd5283e0 (diff)
downloadydb-7629e1f9ef7f9d2a3c345c97e6a4e5a4b32ee786.tar.gz
Restoring authorship annotation for <diver@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util')
-rw-r--r--util/draft/enum.h22
-rw-r--r--util/folder/path.cpp10
-rw-r--r--util/folder/tempdir.h6
-rw-r--r--util/generic/lazy_value.cpp2
-rw-r--r--util/generic/lazy_value.h86
-rw-r--r--util/generic/lazy_value_ut.cpp66
6 files changed, 96 insertions, 96 deletions
diff --git a/util/draft/enum.h b/util/draft/enum.h
index 18002b7df2..82e4de14fd 100644
--- a/util/draft/enum.h
+++ b/util/draft/enum.h
@@ -119,18 +119,18 @@ inline void SetEnumFlags(const std::pair<const char*, E>* str2Enum, TStringBuf o
}
}
-// for enums generated with GENERATE_ENUM_SERIALIZATION
-template <class E, size_t B>
-inline void SetEnumFlags(TStringBuf optSpec, std::bitset<B>& flags, bool allIfEmpty = true) {
- if (optSpec.empty()) {
+// for enums generated with GENERATE_ENUM_SERIALIZATION
+template <class E, size_t B>
+inline void SetEnumFlags(TStringBuf optSpec, std::bitset<B>& flags, bool allIfEmpty = true) {
+ if (optSpec.empty()) {
SetEnumFlagsForEmptySpec(flags, allIfEmpty);
- } else {
- flags.reset();
+ } else {
+ flags.reset();
for (const auto& it : StringSplitter(optSpec).Split(',')) {
- E e;
+ E e;
if (!TryFromString(it.Token(), e))
ythrow yexception() << "Unknown enum value '" << it.Token() << "'";
- flags.set((size_t)e);
- }
- }
-}
+ flags.set((size_t)e);
+ }
+ }
+}
diff --git a/util/folder/path.cpp b/util/folder/path.cpp
index bfe0c67d68..5227f2df3a 100644
--- a/util/folder/path.cpp
+++ b/util/folder/path.cpp
@@ -333,12 +333,12 @@ bool TFsPath::Exists() const {
return IsDefined() && NFs::Exists(*this);
}
-void TFsPath::CheckExists() const {
- if (!Exists()) {
+void TFsPath::CheckExists() const {
+ if (!Exists()) {
ythrow TIoException() << "path does not exist " << Path_;
- }
-}
-
+ }
+}
+
bool TFsPath::IsDirectory() const {
return IsDefined() && TFileStat(GetPath().data()).IsDir();
}
diff --git a/util/folder/tempdir.h b/util/folder/tempdir.h
index ff458f83b9..9ce01ef655 100644
--- a/util/folder/tempdir.h
+++ b/util/folder/tempdir.h
@@ -18,9 +18,9 @@ public:
static TTempDir NewTempDir(const TString& root);
const TString& operator()() const {
- return Name();
- }
-
+ return Name();
+ }
+
const TString& Name() const {
return TempDir.GetPath();
}
diff --git a/util/generic/lazy_value.cpp b/util/generic/lazy_value.cpp
index e687ec1a59..6b6738404e 100644
--- a/util/generic/lazy_value.cpp
+++ b/util/generic/lazy_value.cpp
@@ -1 +1 @@
-#include "lazy_value.h"
+#include "lazy_value.h"
diff --git a/util/generic/lazy_value.h b/util/generic/lazy_value.h
index 3c720f76b5..033b46eaf2 100644
--- a/util/generic/lazy_value.h
+++ b/util/generic/lazy_value.h
@@ -1,53 +1,53 @@
-#pragma once
-
-#include "maybe.h"
+#pragma once
+
+#include "maybe.h"
#include "function.h"
-
-template <class T>
+
+template <class T>
class TLazyValueBase {
-public:
+public:
using TInitializer = std::function<T()>;
-
+
TLazyValueBase() = default;
TLazyValueBase(TInitializer initializer)
: Initializer(std::move(initializer))
- {
- }
-
- explicit operator bool() const noexcept {
- return Defined();
- }
-
- bool Defined() const noexcept {
- return ValueHolder.Defined();
- }
-
- const T& GetRef() const {
- if (!Defined()) {
- InitDefault();
- }
- return *ValueHolder;
- }
-
- const T& operator*() const {
- return GetRef();
- }
-
- const T* operator->() const {
- return &GetRef();
- }
-
- void InitDefault() const {
+ {
+ }
+
+ explicit operator bool() const noexcept {
+ return Defined();
+ }
+
+ bool Defined() const noexcept {
+ return ValueHolder.Defined();
+ }
+
+ const T& GetRef() const {
+ if (!Defined()) {
+ InitDefault();
+ }
+ return *ValueHolder;
+ }
+
+ const T& operator*() const {
+ return GetRef();
+ }
+
+ const T* operator->() const {
+ return &GetRef();
+ }
+
+ void InitDefault() const {
Y_ASSERT(Initializer);
- ValueHolder = Initializer();
- }
-
-private:
- mutable TMaybe<T> ValueHolder;
- TInitializer Initializer;
-};
-
+ ValueHolder = Initializer();
+ }
+
+private:
+ mutable TMaybe<T> ValueHolder;
+ TInitializer Initializer;
+};
+
// we need this to get implicit construction TLazyValue from lambda
// and save default copy constructor and operator= for type TLazyValue
template <class T>
@@ -63,4 +63,4 @@ public:
template <typename F>
TLazyValue<TFunctionResult<F>> MakeLazy(F&& f) {
return {std::forward<F>(f)};
-}
+}
diff --git a/util/generic/lazy_value_ut.cpp b/util/generic/lazy_value_ut.cpp
index f6135880c3..ba159f19f7 100644
--- a/util/generic/lazy_value_ut.cpp
+++ b/util/generic/lazy_value_ut.cpp
@@ -1,22 +1,22 @@
-#include "lazy_value.h"
-
+#include "lazy_value.h"
+
#include <library/cpp/testing/unittest/registar.h>
-
+
Y_UNIT_TEST_SUITE(TLazyValueTestSuite) {
Y_UNIT_TEST(TestLazyValue) {
TLazyValue<int> value([]() {
- return 5;
- });
- UNIT_ASSERT(!value);
- UNIT_ASSERT_EQUAL(*value, 5);
- UNIT_ASSERT(value);
- }
-
+ return 5;
+ });
+ UNIT_ASSERT(!value);
+ UNIT_ASSERT_EQUAL(*value, 5);
+ UNIT_ASSERT(value);
+ }
+
Y_UNIT_TEST(TestLazyValueInitialization) {
TLazyValue<int> value1([]() { return 5; });
-
+
TLazyValue<int> value2 = []() { return 5; };
-
+
TLazyValue<int> notInitialized{};
TLazyValue<int> copy1(value1);
@@ -90,17 +90,17 @@ Y_UNIT_TEST_SUITE(TLazyValueTestSuite) {
}
class TValueProvider {
- public:
+ public:
static size_t CountParseDataCalled;
- TValueProvider()
+ TValueProvider()
: Data_([&] { return this->ParseData(); })
- {
- }
-
+ {
+ }
+
const TString& GetData() const {
return *Data_;
- }
+ }
private:
TLazyValue<TString> Data_;
@@ -109,16 +109,16 @@ Y_UNIT_TEST_SUITE(TLazyValueTestSuite) {
CountParseDataCalled++;
return "hi";
}
- };
-
+ };
+
size_t TValueProvider::CountParseDataCalled = 0;
Y_UNIT_TEST(TestValueProvider) {
- TValueProvider provider;
-
- UNIT_ASSERT(provider.GetData() == "hi");
- }
-
+ TValueProvider provider;
+
+ UNIT_ASSERT(provider.GetData() == "hi");
+ }
+
Y_UNIT_TEST(TestValueProviderCopy) {
TValueProvider provider;
provider.GetData();
@@ -147,11 +147,11 @@ Y_UNIT_TEST_SUITE(TLazyValueTestSuite) {
}
Y_UNIT_TEST(TestMakeLazy) {
- auto lv = MakeLazy([] {
- return 100500;
- });
- UNIT_ASSERT(!lv);
- UNIT_ASSERT(lv.GetRef() == 100500);
- UNIT_ASSERT(lv);
- }
-}
+ auto lv = MakeLazy([] {
+ return 100500;
+ });
+ UNIT_ASSERT(!lv);
+ UNIT_ASSERT(lv.GetRef() == 100500);
+ UNIT_ASSERT(lv);
+ }
+}