aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorepar <epar@yandex-team.ru>2022-02-10 16:50:02 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:50:02 +0300
commit904f1af50fdd9aae658a7b5688b5a497044c4584 (patch)
tree5fc4555525a8451ec9e74fde574490f4c72c8fc5
parent9473a88c91129dfe21343af486bebb93a0b33291 (diff)
downloadydb-904f1af50fdd9aae658a7b5688b5a497044c4584.tar.gz
Restoring authorship annotation for <epar@yandex-team.ru>. Commit 1 of 2.
-rw-r--r--library/cpp/scheme/scheme.h18
-rw-r--r--library/cpp/scheme/scheme_cast.h466
-rw-r--r--library/cpp/scheme/scimpl.h6
-rw-r--r--library/cpp/scheme/tests/ut/scheme_cast_ut.cpp224
-rw-r--r--util/generic/adaptor.cpp2
-rw-r--r--util/generic/adaptor.h38
-rw-r--r--util/generic/adaptor_ut.cpp118
7 files changed, 436 insertions, 436 deletions
diff --git a/library/cpp/scheme/scheme.h b/library/cpp/scheme/scheme.h
index 3d7c59f3c9..47cbb354c4 100644
--- a/library/cpp/scheme/scheme.h
+++ b/library/cpp/scheme/scheme.h
@@ -91,14 +91,14 @@ namespace NSc {
inline TValue& operator=(TStringBuf t);
inline TValue& operator=(const char* t);
- inline TValue& operator=(TValue& v) &;
- inline TValue& operator=(const TValue& v) &;
- inline TValue& operator=(TValue&& v) & noexcept;
-
- inline TValue& operator=(TValue& v) && = delete;
- inline TValue& operator=(const TValue& v) && = delete;
- inline TValue& operator=(TValue&& v) && = delete;
-
+ inline TValue& operator=(TValue& v) &;
+ inline TValue& operator=(const TValue& v) &;
+ inline TValue& operator=(TValue&& v) & noexcept;
+
+ inline TValue& operator=(TValue& v) && = delete;
+ inline TValue& operator=(const TValue& v) && = delete;
+ inline TValue& operator=(TValue&& v) && = delete;
+
public:
template <class T> // ui16 or TStringBuf
inline TValue& operator[](const T& idx) {
@@ -531,7 +531,7 @@ namespace NSc {
}
#include "scimpl.h"
-#include "scheme_cast.h"
+#include "scheme_cast.h"
#ifdef _MSC_VER
#pragma warning(default : 4521 4522)
diff --git a/library/cpp/scheme/scheme_cast.h b/library/cpp/scheme/scheme_cast.h
index 00839e8017..083123b38d 100644
--- a/library/cpp/scheme/scheme_cast.h
+++ b/library/cpp/scheme/scheme_cast.h
@@ -1,321 +1,321 @@
-#pragma once
-
-#include <util/generic/set.h>
-#include <util/generic/vector.h>
-#include <util/generic/map.h>
-#include <util/generic/hash.h>
-#include <util/generic/hash_set.h>
-#include <util/string/cast.h>
-#include <util/generic/yexception.h>
-
+#pragma once
+
+#include <util/generic/set.h>
+#include <util/generic/vector.h>
+#include <util/generic/map.h>
+#include <util/generic/hash.h>
+#include <util/generic/hash_set.h>
+#include <util/string/cast.h>
+#include <util/generic/yexception.h>
+
#include "scheme.h"
-
-namespace NJsonConverters {
- class IJsonSerializable {
+
+namespace NJsonConverters {
+ class IJsonSerializable {
public:
virtual NSc::TValue ToTValue() const = 0;
virtual void FromTValue(const NSc::TValue&, const bool validate) = 0;
-
+
const TString ToJson(const bool sort = false) const {
return ToTValue().ToJson(sort);
};
-
+
void FromJson(const TStringBuf& json, const bool validate = false) {
NSc::TValue v = NSc::TValue::FromJson(json);
FromTValue(v, validate);
}
-
+
virtual ~IJsonSerializable(){};
- };
+ };
//////////////////////////////////////////////////////////////////////
// fwd declarations
//////////////////////////////////////////////////////////////////////
-
+
//TVector
- template <typename T, typename A>
+ template <typename T, typename A>
NSc::TValue ToTValue(const TVector<T, A>& x);
- template <typename T, typename A>
+ template <typename T, typename A>
void FromTValue(const NSc::TValue& x, TVector<T, A>& out, const bool validate);
-
+
//THashMap
- template <class Key, class T, class HashFcn, class EqualKey, class Alloc>
+ template <class Key, class T, class HashFcn, class EqualKey, class Alloc>
NSc::TValue ToTValue(const THashMap<Key, T, HashFcn, EqualKey, Alloc>& x);
- template <class Key, class T, class HashFcn, class EqualKey, class Alloc>
+ template <class Key, class T, class HashFcn, class EqualKey, class Alloc>
void FromTValue(const NSc::TValue& x, THashMap<Key, T, HashFcn, EqualKey, Alloc>& out, const bool validate);
-
+
//TMap
- template <class K, class V, class Less, class A>
+ template <class K, class V, class Less, class A>
NSc::TValue ToTValue(const TMap<K, V, Less, A>& x);
- template <class K, class V, class Less, class A>
+ template <class K, class V, class Less, class A>
void FromTValue(const NSc::TValue& x, TMap<K, V, Less, A>& out, const bool validate);
-
+
//THashSet
- template <class V, class H, class E, class A>
+ template <class V, class H, class E, class A>
NSc::TValue ToTValue(const THashSet<V, H, E, A>& x);
- template <class V, class H, class E, class A>
+ template <class V, class H, class E, class A>
void FromTValue(const NSc::TValue& x, THashSet<V, H, E, A>& out, const bool validate);
-
+
//TSet
- template <class K, class L, class A>
+ template <class K, class L, class A>
NSc::TValue ToTValue(const TSet<K, L, A>& x);
- template <class K, class L, class A>
+ template <class K, class L, class A>
void FromTValue(const NSc::TValue& x, TSet<K, L, A>& out, const bool validate);
-
+
//std::pair
- template <class T1, class T2>
+ template <class T1, class T2>
NSc::TValue ToTValue(const std::pair<T1, T2>& x);
- template <class T1, class T2>
+ template <class T1, class T2>
void FromTValue(const NSc::TValue& x, std::pair<T1, T2>& out, const bool validate);
-
+
//////////////////////////////////////////////////////////////////////
// simple From, To helpers
//////////////////////////////////////////////////////////////////////
template <typename T, bool HasSerializer>
- struct TValueAndStrokaConv {};
-
+ struct TValueAndStrokaConv {};
+
template <typename T>
- struct TValueAndStrokaConv<T, 0> {
- static NSc::TValue ToTValue(const T& x) {
- return NSc::TValue(x);
- }
-
- static void FromTValue(const NSc::TValue& x, T& out, const bool) {
- out = x;
- }
-
+ struct TValueAndStrokaConv<T, 0> {
+ static NSc::TValue ToTValue(const T& x) {
+ return NSc::TValue(x);
+ }
+
+ static void FromTValue(const NSc::TValue& x, T& out, const bool) {
+ out = x;
+ }
+
static TString ToString(const T& x) {
- return ::ToString(x);
- }
-
- static void FromString(const TStringBuf& str, T& res, const bool) {
- res = ::FromString<T>(str);
- }
- };
-
+ return ::ToString(x);
+ }
+
+ static void FromString(const TStringBuf& str, T& res, const bool) {
+ res = ::FromString<T>(str);
+ }
+ };
+
template <typename T>
struct TValueAndStrokaConv<T, 1> {
- static NSc::TValue ToTValue(const T& x) {
- return x.ToTValue();
- }
-
- static void FromTValue(const NSc::TValue& x, T& out, const bool validate) {
- out.FromTValue(x, validate);
- }
-
+ static NSc::TValue ToTValue(const T& x) {
+ return x.ToTValue();
+ }
+
+ static void FromTValue(const NSc::TValue& x, T& out, const bool validate) {
+ out.FromTValue(x, validate);
+ }
+
static TString ToString(const T& x) {
- return x.ToJson();
- }
-
- static void FromString(const TStringBuf& str, T& res, const bool validate) {
- res.FromJson(str, validate);
- }
- };
-
- template <typename T>
- NSc::TValue ToTValue(const T& x) {
+ return x.ToJson();
+ }
+
+ static void FromString(const TStringBuf& str, T& res, const bool validate) {
+ res.FromJson(str, validate);
+ }
+ };
+
+ template <typename T>
+ NSc::TValue ToTValue(const T& x) {
return TValueAndStrokaConv<T, std::is_base_of<IJsonSerializable, T>::value>::ToTValue(x);
- }
-
- template <typename T>
- void FromTValue(const NSc::TValue& x, T& out, const bool validate) {
+ }
+
+ template <typename T>
+ void FromTValue(const NSc::TValue& x, T& out, const bool validate) {
return TValueAndStrokaConv<T, std::is_base_of<IJsonSerializable, T>::value>::FromTValue(x, out, validate);
- }
-
- template <typename T>
- T FromTValue(const NSc::TValue& x, const bool validate) {
- T ret;
- FromTValue(x, ret, validate);
- return ret;
- }
-
- template <typename T>
+ }
+
+ template <typename T>
+ T FromTValue(const NSc::TValue& x, const bool validate) {
+ T ret;
+ FromTValue(x, ret, validate);
+ return ret;
+ }
+
+ template <typename T>
TString ToString(const T& x) {
return TValueAndStrokaConv<T, std::is_base_of<IJsonSerializable, T>::value>::ToString(x);
- }
-
- template <typename T>
- void FromString(const TStringBuf& str, T& res, const bool validate) {
+ }
+
+ template <typename T>
+ void FromString(const TStringBuf& str, T& res, const bool validate) {
return TValueAndStrokaConv<T, std::is_base_of<IJsonSerializable, T>::value>::FromString(str, res, validate);
- }
-
- template <typename T>
- T FromString(const TStringBuf& str, bool validate) {
- T ret;
- FromString(str, ret, validate);
- return ret;
- }
-
- namespace NPrivate {
- template <typename T>
- NSc::TValue ToTValueDict(const T& dict) {
- NSc::TValue out;
- out.SetDict();
- for (typename T::const_iterator it = dict.begin(); it != dict.end(); ++it) {
- out[ToString(it->first)] = NJsonConverters::ToTValue(it->second);
- }
- return out;
- }
-
- template <typename T>
- void FromTValueDict(const NSc::TValue& x, T& out, bool validate) {
- typedef typename T::key_type TKey;
- typedef typename T::mapped_type TMapped;
- if (validate)
+ }
+
+ template <typename T>
+ T FromString(const TStringBuf& str, bool validate) {
+ T ret;
+ FromString(str, ret, validate);
+ return ret;
+ }
+
+ namespace NPrivate {
+ template <typename T>
+ NSc::TValue ToTValueDict(const T& dict) {
+ NSc::TValue out;
+ out.SetDict();
+ for (typename T::const_iterator it = dict.begin(); it != dict.end(); ++it) {
+ out[ToString(it->first)] = NJsonConverters::ToTValue(it->second);
+ }
+ return out;
+ }
+
+ template <typename T>
+ void FromTValueDict(const NSc::TValue& x, T& out, bool validate) {
+ typedef typename T::key_type TKey;
+ typedef typename T::mapped_type TMapped;
+ if (validate)
Y_ENSURE(x.IsDict() || x.IsNull(), "not valid input scheme");
- out.clear();
- if (x.IsDict()) {
- const NSc::TDict& dict = x.GetDict();
+ out.clear();
+ if (x.IsDict()) {
+ const NSc::TDict& dict = x.GetDict();
for (const auto& it : dict) {
TKey key = NJsonConverters::FromString<TKey>(it.first, validate);
TMapped val = NJsonConverters::FromTValue<TMapped>(it.second, validate);
out.insert(std::pair<TKey, TMapped>(key, val));
- }
- }
- }
-
- template <typename T>
- NSc::TValue ToTValueSet(const T& set) {
- NSc::TValue out;
- out.SetDict();
- for (typename T::const_iterator it = set.begin(); it != set.end(); ++it) {
- out[ToString(*it)] = NSc::Null();
- }
- return out;
- }
-
- template <typename T>
- void FromTValueSet(const NSc::TValue& x, T& out, const bool validate) {
- typedef typename T::key_type TKey;
- if (validate)
+ }
+ }
+ }
+
+ template <typename T>
+ NSc::TValue ToTValueSet(const T& set) {
+ NSc::TValue out;
+ out.SetDict();
+ for (typename T::const_iterator it = set.begin(); it != set.end(); ++it) {
+ out[ToString(*it)] = NSc::Null();
+ }
+ return out;
+ }
+
+ template <typename T>
+ void FromTValueSet(const NSc::TValue& x, T& out, const bool validate) {
+ typedef typename T::key_type TKey;
+ if (validate)
Y_ENSURE(x.IsDict() || x.IsNull(), "not valid input scheme");
- out.clear();
- if (x.IsDict()) {
- const NSc::TDict& dict = x.GetDict();
+ out.clear();
+ if (x.IsDict()) {
+ const NSc::TDict& dict = x.GetDict();
for (const auto& it : dict) {
- TKey key;
+ TKey key;
NJsonConverters::FromString<TKey>(it.first, key, validate);
- out.insert(key);
- }
- }
- }
- }
-
+ out.insert(key);
+ }
+ }
+ }
+ }
+
//////////////////////////////////////////////////////////////////////
// TVector
//////////////////////////////////////////////////////////////////////
- template <typename T, typename A>
+ template <typename T, typename A>
NSc::TValue ToTValue(const TVector<T, A>& x) {
- NSc::TValue out;
- out.SetArray();
+ NSc::TValue out;
+ out.SetArray();
for (typename TVector<T, A>::const_iterator it = x.begin(); it != x.end(); ++it)
- out.Push(NJsonConverters::ToTValue(*it));
- return out;
- }
-
- template <typename T, typename A>
+ out.Push(NJsonConverters::ToTValue(*it));
+ return out;
+ }
+
+ template <typename T, typename A>
void FromTValue(const NSc::TValue& x, TVector<T, A>& out, const bool validate) {
- if (validate)
+ if (validate)
Y_ENSURE(x.IsArray() || x.IsNull(), "not valid input scheme");
- out.clear();
- if (x.IsArray()) {
- const NSc::TArray& arr = x.GetArray();
- out.reserve(arr.size());
+ out.clear();
+ if (x.IsArray()) {
+ const NSc::TArray& arr = x.GetArray();
+ out.reserve(arr.size());
for (const auto& it : arr) {
- T val;
+ T val;
NJsonConverters::FromTValue(it, val, validate);
- out.push_back(val);
- }
- }
- }
-
+ out.push_back(val);
+ }
+ }
+ }
+
//////////////////////////////////////////////////////////////////////
// THashMap & TMap
//////////////////////////////////////////////////////////////////////
- template <class Key, class T, class HashFcn, class EqualKey, class Alloc>
+ template <class Key, class T, class HashFcn, class EqualKey, class Alloc>
NSc::TValue ToTValue(const THashMap<Key, T, HashFcn, EqualKey, Alloc>& x) {
- return NPrivate::ToTValueDict(x);
- }
-
- template <class Key, class T, class HashFcn, class EqualKey, class Alloc>
+ return NPrivate::ToTValueDict(x);
+ }
+
+ template <class Key, class T, class HashFcn, class EqualKey, class Alloc>
void FromTValue(const NSc::TValue& x, THashMap<Key, T, HashFcn, EqualKey, Alloc>& out, const bool validate) {
- NPrivate::FromTValueDict(x, out, validate);
- }
-
- template <class K, class V, class Less, class A>
+ NPrivate::FromTValueDict(x, out, validate);
+ }
+
+ template <class K, class V, class Less, class A>
NSc::TValue ToTValue(const TMap<K, V, Less, A>& x) {
- return NPrivate::ToTValueDict(x);
- }
-
- template <class K, class V, class Less, class A>
+ return NPrivate::ToTValueDict(x);
+ }
+
+ template <class K, class V, class Less, class A>
void FromTValue(const NSc::TValue& x, TMap<K, V, Less, A>& out, const bool validate) {
- NPrivate::FromTValueDict(x, out, validate);
- }
-
+ NPrivate::FromTValueDict(x, out, validate);
+ }
+
//////////////////////////////////////////////////////////////////////
// THashSet & TSet
//////////////////////////////////////////////////////////////////////
- template <class V, class H, class E, class A>
+ template <class V, class H, class E, class A>
NSc::TValue ToTValue(const THashSet<V, H, E, A>& x) {
- return NPrivate::ToTValueSet(x);
- }
-
- template <class V, class H, class E, class A>
+ return NPrivate::ToTValueSet(x);
+ }
+
+ template <class V, class H, class E, class A>
void FromTValue(const NSc::TValue& x, THashSet<V, H, E, A>& out, const bool validate) {
- NPrivate::FromTValueSet(x, out, validate);
- }
-
- template <class K, class L, class A>
+ NPrivate::FromTValueSet(x, out, validate);
+ }
+
+ template <class K, class L, class A>
NSc::TValue ToTValue(const TSet<K, L, A>& x) {
- return NPrivate::ToTValueSet(x);
- }
-
- template <class K, class L, class A>
+ return NPrivate::ToTValueSet(x);
+ }
+
+ template <class K, class L, class A>
void FromTValue(const NSc::TValue& x, TSet<K, L, A>& out, const bool validate) {
- NPrivate::FromTValueSet(x, out, validate);
- }
-
+ NPrivate::FromTValueSet(x, out, validate);
+ }
+
//////////////////////////////////////////////////////////////////////
// std::pair
//////////////////////////////////////////////////////////////////////
- template <class T1, class T2>
+ template <class T1, class T2>
NSc::TValue ToTValue(const std::pair<T1, T2>& x) {
- NSc::TValue out;
- out.SetArray();
- out.Push(NJsonConverters::ToTValue(x.first));
- out.Push(NJsonConverters::ToTValue(x.second));
- return out;
- }
-
- template <class T1, class T2>
+ NSc::TValue out;
+ out.SetArray();
+ out.Push(NJsonConverters::ToTValue(x.first));
+ out.Push(NJsonConverters::ToTValue(x.second));
+ return out;
+ }
+
+ template <class T1, class T2>
void FromTValue(const NSc::TValue& x, std::pair<T1, T2>& out, const bool validate) {
- if (validate)
+ if (validate)
Y_ENSURE(x.IsArray() || x.IsNull(), "not valid input scheme");
- if (x.IsArray()) {
- const NSc::TArray& arr = x.GetArray();
- if (arr.size() == 2) {
- T1 val0;
- T2 val1;
- NJsonConverters::FromTValue(arr[0], val0, validate);
- NJsonConverters::FromTValue(arr[1], val1, validate);
- out.first = val0;
- out.second = val1;
- }
- }
- }
-
+ if (x.IsArray()) {
+ const NSc::TArray& arr = x.GetArray();
+ if (arr.size() == 2) {
+ T1 val0;
+ T2 val1;
+ NJsonConverters::FromTValue(arr[0], val0, validate);
+ NJsonConverters::FromTValue(arr[1], val1, validate);
+ out.first = val0;
+ out.second = val1;
+ }
+ }
+ }
+
//////////////////////////////////////////////////////////////////////
// global user functions
//////////////////////////////////////////////////////////////////////
- template <typename T>
+ template <typename T>
TString ToJson(const T& val, const bool sort = false) {
- return NJsonConverters::ToTValue(val).ToJson(sort);
- }
-
- template <typename T>
- T FromJson(const TStringBuf& json, bool validate = false) {
- NSc::TValue v = NSc::TValue::FromJson(json);
- T ret;
- NJsonConverters::FromTValue(v, ret, validate);
- return ret;
- }
-}
+ return NJsonConverters::ToTValue(val).ToJson(sort);
+ }
+
+ template <typename T>
+ T FromJson(const TStringBuf& json, bool validate = false) {
+ NSc::TValue v = NSc::TValue::FromJson(json);
+ T ret;
+ NJsonConverters::FromTValue(v, ret, validate);
+ return ret;
+ }
+}
diff --git a/library/cpp/scheme/scimpl.h b/library/cpp/scheme/scimpl.h
index 4f68f16290..089817372d 100644
--- a/library/cpp/scheme/scimpl.h
+++ b/library/cpp/scheme/scimpl.h
@@ -517,7 +517,7 @@ namespace NSc {
return SetString(t);
}
- TValue& TValue::operator=(TValue& v) & {
+ TValue& TValue::operator=(TValue& v) & {
if (!Same(*this, v)) {
//Extend TheCore lifetime not to trigger possible v deletion via parent-child chain
auto tmpCore = TheCore;
@@ -527,7 +527,7 @@ namespace NSc {
return *this;
}
- TValue& TValue::operator=(const TValue& v) & {
+ TValue& TValue::operator=(const TValue& v) & {
if (!Same(*this, v)) {
//Extend TheCore lifetime not to trigger possible v deletion via parent-child chain
auto tmpCore = TheCore;
@@ -537,7 +537,7 @@ namespace NSc {
return *this;
}
- TValue& TValue::operator=(TValue&& v) & noexcept {
+ TValue& TValue::operator=(TValue&& v) & noexcept {
if (!Same(*this, v)) {
//Extend TheCore lifetime not to trigger possible v deletion via parent-child chain
auto tmpCore = TheCore;
diff --git a/library/cpp/scheme/tests/ut/scheme_cast_ut.cpp b/library/cpp/scheme/tests/ut/scheme_cast_ut.cpp
index 4f907157e9..43b2270559 100644
--- a/library/cpp/scheme/tests/ut/scheme_cast_ut.cpp
+++ b/library/cpp/scheme/tests/ut/scheme_cast_ut.cpp
@@ -1,94 +1,94 @@
#include <library/cpp/scheme/scheme.h>
#include <library/cpp/scheme/scheme_cast.h>
-
+
#include <library/cpp/testing/unittest/registar.h>
-
-#include <util/stream/null.h>
-#include <util/string/subst.h>
-#include <util/string/util.h>
-
-using namespace NJsonConverters;
-
+
+#include <util/stream/null.h>
+#include <util/string/subst.h>
+#include <util/string/util.h>
+
+using namespace NJsonConverters;
+
using TVI = TVector<int>;
using THI = THashMap<int, int>;
using TMI = TMap<int, int>;
using THSI = THashSet<int>;
using TSI = TSet<int>;
using TPI = std::pair<int, int>;
-
+
Y_UNIT_TEST_SUITE(TSchemeCastTest) {
Y_UNIT_TEST(TestYVector) {
- TVI v;
- for (int i = 0; i < 3; ++i)
- v.push_back(i);
-
- UNIT_ASSERT_VALUES_EQUAL("[0,1,2]", ToJson(v));
-
- TVI y(FromJson<TVI>(ToJson(v)));
- UNIT_ASSERT_VALUES_EQUAL(v.size(), y.size());
+ TVI v;
+ for (int i = 0; i < 3; ++i)
+ v.push_back(i);
+
+ UNIT_ASSERT_VALUES_EQUAL("[0,1,2]", ToJson(v));
+
+ TVI y(FromJson<TVI>(ToJson(v)));
+ UNIT_ASSERT_VALUES_EQUAL(v.size(), y.size());
UNIT_ASSERT(std::equal(v.begin(), v.end(), y.begin()));
- }
-
+ }
+
Y_UNIT_TEST(TestYHash) {
- THI h;
- for (int i = 0; i < 3; ++i)
+ THI h;
+ for (int i = 0; i < 3; ++i)
h[i] = i * i;
-
+
const TString etalon = "{\"0\":0,\"1\":1,\"2\":4}";
- UNIT_ASSERT_VALUES_EQUAL(etalon, ToJson(h, true));
-
- THI h2(FromJson<THI>(ToJson(h)));
- UNIT_ASSERT_VALUES_EQUAL(ToJson(h2, true), ToJson(h, true));
- }
-
+ UNIT_ASSERT_VALUES_EQUAL(etalon, ToJson(h, true));
+
+ THI h2(FromJson<THI>(ToJson(h)));
+ UNIT_ASSERT_VALUES_EQUAL(ToJson(h2, true), ToJson(h, true));
+ }
+
Y_UNIT_TEST(TestYMap) {
- TMI h;
- for (int i = 0; i < 3; ++i)
+ TMI h;
+ for (int i = 0; i < 3; ++i)
h[i] = i * i;
-
+
const TString etalon = "{\"0\":0,\"1\":1,\"2\":4}";
- UNIT_ASSERT_VALUES_EQUAL(etalon, ToJson(h, true));
-
- TMI h2(FromJson<TMI>(ToJson(h)));
- UNIT_ASSERT_VALUES_EQUAL(ToJson(h2, true), ToJson(h, true));
- }
-
+ UNIT_ASSERT_VALUES_EQUAL(etalon, ToJson(h, true));
+
+ TMI h2(FromJson<TMI>(ToJson(h)));
+ UNIT_ASSERT_VALUES_EQUAL(ToJson(h2, true), ToJson(h, true));
+ }
+
Y_UNIT_TEST(TestYHashSet) {
- THSI h;
- for (int i = 0; i < 3; ++i)
+ THSI h;
+ for (int i = 0; i < 3; ++i)
h.insert(i * i);
-
+
const TString etalon = "{\"0\":null,\"1\":null,\"4\":null}";
- UNIT_ASSERT_VALUES_EQUAL(etalon, ToJson(h, true));
-
- THSI h2(FromJson<THSI>(ToJson(h)));
- UNIT_ASSERT_VALUES_EQUAL(ToJson(h2, true), ToJson(h, true));
- }
-
+ UNIT_ASSERT_VALUES_EQUAL(etalon, ToJson(h, true));
+
+ THSI h2(FromJson<THSI>(ToJson(h)));
+ UNIT_ASSERT_VALUES_EQUAL(ToJson(h2, true), ToJson(h, true));
+ }
+
Y_UNIT_TEST(TestYSet) {
- TSI h;
- for (int i = 0; i < 3; ++i)
+ TSI h;
+ for (int i = 0; i < 3; ++i)
h.insert(i * i);
-
+
const TString etalon = "{\"0\":null,\"1\":null,\"4\":null}";
- UNIT_ASSERT_VALUES_EQUAL(etalon, ToJson(h, true));
-
- TSI h2(FromJson<TSI>(ToJson(h)));
- UNIT_ASSERT_VALUES_EQUAL(ToJson(h2, true), ToJson(h, true));
- }
-
+ UNIT_ASSERT_VALUES_EQUAL(etalon, ToJson(h, true));
+
+ TSI h2(FromJson<TSI>(ToJson(h)));
+ UNIT_ASSERT_VALUES_EQUAL(ToJson(h2, true), ToJson(h, true));
+ }
+
Y_UNIT_TEST(TestTPair) {
TPI p(1, 1);
-
+
const TString etalon = "[1,1]";
- UNIT_ASSERT_VALUES_EQUAL(etalon, ToJson(p, true));
-
- TPI p2(FromJson<TPI>(ToJson(p)));
- UNIT_ASSERT_VALUES_EQUAL(ToJson(p2, true), ToJson(p, true));
- }
-
- struct TCustom: public IJsonSerializable {
- int A, B;
+ UNIT_ASSERT_VALUES_EQUAL(etalon, ToJson(p, true));
+
+ TPI p2(FromJson<TPI>(ToJson(p)));
+ UNIT_ASSERT_VALUES_EQUAL(ToJson(p2, true), ToJson(p, true));
+ }
+
+ struct TCustom: public IJsonSerializable {
+ int A, B;
TCustom()
: A(0)
, B(0){};
@@ -98,65 +98,65 @@ Y_UNIT_TEST_SUITE(TSchemeCastTest) {
{
}
NSc::TValue ToTValue() const override {
- NSc::TValue res;
- res["a"] = A;
- res["b"] = B;
- return res;
- }
+ NSc::TValue res;
+ res["a"] = A;
+ res["b"] = B;
+ return res;
+ }
void FromTValue(const NSc::TValue& v, const bool) override {
- A = v["a"].GetNumber();
- B = v["b"].GetNumber();
- }
-
+ A = v["a"].GetNumber();
+ B = v["b"].GetNumber();
+ }
+
bool operator<(const TCustom& rhs) const {
- return A < rhs.A;
- }
- };
-
+ return A < rhs.A;
+ }
+ };
+
Y_UNIT_TEST(TestTCustom) {
- TCustom x(2, 3);
-
+ TCustom x(2, 3);
+
const TString etalon = "{\"a\":2,\"b\":3}";
- UNIT_ASSERT_VALUES_EQUAL(etalon, ToJson(x, true));
-
- TCustom x2(FromJson<TCustom>(ToJson(x)));
- UNIT_ASSERT_VALUES_EQUAL(ToJson(x2, true), ToJson(x, true));
- }
-
+ UNIT_ASSERT_VALUES_EQUAL(etalon, ToJson(x, true));
+
+ TCustom x2(FromJson<TCustom>(ToJson(x)));
+ UNIT_ASSERT_VALUES_EQUAL(ToJson(x2, true), ToJson(x, true));
+ }
+
Y_UNIT_TEST(TestVectorOfPairs) {
typedef TVector<TPI> TVPI;
- TVPI v;
-
- for (int i = 0; i < 3; ++i)
+ TVPI v;
+
+ for (int i = 0; i < 3; ++i)
v.push_back(TPI(i, i * i));
-
+
const TString etalon = "[[0,0],[1,1],[2,4]]";
- UNIT_ASSERT_VALUES_EQUAL(etalon, ToJson(v, true));
-
- TVPI v2(FromJson<TVPI>(ToJson(v)));
- UNIT_ASSERT_VALUES_EQUAL(ToJson(v2, true), ToJson(v, true));
- }
-
+ UNIT_ASSERT_VALUES_EQUAL(etalon, ToJson(v, true));
+
+ TVPI v2(FromJson<TVPI>(ToJson(v)));
+ UNIT_ASSERT_VALUES_EQUAL(ToJson(v2, true), ToJson(v, true));
+ }
+
Y_UNIT_TEST(TestSetOfCustom) {
typedef TSet<TCustom> TSC;
- TSC s;
+ TSC s;
s.insert(TCustom(2, 3));
-
+
const TString etalon = "{\"{\\\"a\\\":2,\\\"b\\\":3}\":null}";
- UNIT_ASSERT_VALUES_EQUAL(etalon, ToJson(s, true));
-
- TSC s2(FromJson<TSC>(ToJson(s)));
- UNIT_ASSERT_VALUES_EQUAL(ToJson(s2, true), ToJson(s, true));
- }
-
+ UNIT_ASSERT_VALUES_EQUAL(etalon, ToJson(s, true));
+
+ TSC s2(FromJson<TSC>(ToJson(s)));
+ UNIT_ASSERT_VALUES_EQUAL(ToJson(s2, true), ToJson(s, true));
+ }
+
Y_UNIT_TEST(TestExceptions) {
- NSc::TValue v = 1;
+ NSc::TValue v = 1;
const TString json = v.ToJson();
- UNIT_ASSERT_EXCEPTION(FromJson<TVI>(json, true), yexception);
- UNIT_ASSERT_EXCEPTION(FromJson<THI>(json, true), yexception);
- UNIT_ASSERT_EXCEPTION(FromJson<TMI>(json, true), yexception);
- UNIT_ASSERT_EXCEPTION(FromJson<THSI>(json, true), yexception);
- UNIT_ASSERT_EXCEPTION(FromJson<TSI>(json, true), yexception);
- UNIT_ASSERT_EXCEPTION(FromJson<TPI>(json, true), yexception);
- }
-};
+ UNIT_ASSERT_EXCEPTION(FromJson<TVI>(json, true), yexception);
+ UNIT_ASSERT_EXCEPTION(FromJson<THI>(json, true), yexception);
+ UNIT_ASSERT_EXCEPTION(FromJson<TMI>(json, true), yexception);
+ UNIT_ASSERT_EXCEPTION(FromJson<THSI>(json, true), yexception);
+ UNIT_ASSERT_EXCEPTION(FromJson<TSI>(json, true), yexception);
+ UNIT_ASSERT_EXCEPTION(FromJson<TPI>(json, true), yexception);
+ }
+};
diff --git a/util/generic/adaptor.cpp b/util/generic/adaptor.cpp
index 1909857ba5..04bf3d54cb 100644
--- a/util/generic/adaptor.cpp
+++ b/util/generic/adaptor.cpp
@@ -1 +1 @@
-#include "adaptor.h"
+#include "adaptor.h"
diff --git a/util/generic/adaptor.h b/util/generic/adaptor.h
index b88a65fc81..e04f7b12d2 100644
--- a/util/generic/adaptor.h
+++ b/util/generic/adaptor.h
@@ -1,9 +1,9 @@
-#pragma once
-
+#pragma once
+
#include "store_policy.h"
-#include "typetraits.h"
-
-namespace NPrivate {
+#include "typetraits.h"
+
+namespace NPrivate {
template <class Range>
class TReverseRangeStorage {
public:
@@ -11,7 +11,7 @@ namespace NPrivate {
: Base_(std::forward<Range>(range))
{
}
-
+
decltype(auto) Base() const {
return *Base_.Ptr();
}
@@ -44,8 +44,8 @@ namespace NPrivate {
auto begin() const {
return Base().rbegin();
- }
-
+ }
+
auto end() const {
return Base().rend();
}
@@ -70,23 +70,23 @@ namespace NPrivate {
auto begin() const {
using std::end;
return std::make_reverse_iterator(end(Base()));
- }
-
+ }
+
auto end() const {
using std::begin;
return std::make_reverse_iterator(begin(Base()));
- }
-
+ }
+
auto begin() {
using std::end;
return std::make_reverse_iterator(end(Base()));
- }
-
+ }
+
auto end() {
using std::begin;
return std::make_reverse_iterator(begin(Base()));
- }
- };
+ }
+ };
template <class Range>
class TReverseRange: public TReverseRangeBase<Range> {
@@ -119,8 +119,8 @@ namespace NPrivate {
return end(Base());
}
};
-}
-
+}
+
/**
* Provides a reverse view into the provided container.
*
@@ -137,4 +137,4 @@ namespace NPrivate {
template <class Range>
constexpr ::NPrivate::TReverseRange<Range> Reversed(Range&& range) {
return ::NPrivate::TReverseRange<Range>(std::forward<Range>(range));
-}
+}
diff --git a/util/generic/adaptor_ut.cpp b/util/generic/adaptor_ut.cpp
index 721f849f93..793e22c2c7 100644
--- a/util/generic/adaptor_ut.cpp
+++ b/util/generic/adaptor_ut.cpp
@@ -1,80 +1,80 @@
-#include "adaptor.h"
-#include "yexception.h"
-
+#include "adaptor.h"
+#include "yexception.h"
+
#include <library/cpp/testing/unittest/registar.h>
-
+
struct TOnCopy: yexception {
-};
-
+};
+
struct TOnMove: yexception {
-};
-
-struct TState {
- explicit TState() {
- }
-
- TState(const TState&) {
- ythrow TOnCopy();
- }
-
- TState(TState&&) {
- ythrow TOnMove();
- }
-
- void operator=(const TState&) {
- ythrow TOnCopy();
- }
-
- void rbegin() const {
- }
-
- void rend() const {
- }
-};
-
+};
+
+struct TState {
+ explicit TState() {
+ }
+
+ TState(const TState&) {
+ ythrow TOnCopy();
+ }
+
+ TState(TState&&) {
+ ythrow TOnMove();
+ }
+
+ void operator=(const TState&) {
+ ythrow TOnCopy();
+ }
+
+ void rbegin() const {
+ }
+
+ void rend() const {
+ }
+};
+
Y_UNIT_TEST_SUITE(TReverseAdaptor) {
Y_UNIT_TEST(ReadTest) {
TVector<int> cont = {1, 2, 3};
TVector<int> etalon = {3, 2, 1};
- size_t idx = 0;
- for (const auto& x : Reversed(cont)) {
- UNIT_ASSERT_VALUES_EQUAL(etalon[idx++], x);
- }
+ size_t idx = 0;
+ for (const auto& x : Reversed(cont)) {
+ UNIT_ASSERT_VALUES_EQUAL(etalon[idx++], x);
+ }
idx = 0;
for (const auto& x : Reversed(std::move(cont))) {
UNIT_ASSERT_VALUES_EQUAL(etalon[idx++], x);
}
- }
-
+ }
+
Y_UNIT_TEST(WriteTest) {
TVector<int> cont = {1, 2, 3};
TVector<int> etalon = {3, 6, 9};
- size_t idx = 0;
- for (auto& x : Reversed(cont)) {
- x *= x + idx++;
- }
- idx = 0;
- for (auto& x : cont) {
- UNIT_ASSERT_VALUES_EQUAL(etalon[idx++], x);
- }
- }
-
+ size_t idx = 0;
+ for (auto& x : Reversed(cont)) {
+ x *= x + idx++;
+ }
+ idx = 0;
+ for (auto& x : cont) {
+ UNIT_ASSERT_VALUES_EQUAL(etalon[idx++], x);
+ }
+ }
+
Y_UNIT_TEST(InnerTypeTest) {
using TStub = TVector<int>;
- TStub stub;
- const TStub cstub;
-
- using namespace NPrivate;
+ TStub stub;
+ const TStub cstub;
+
+ using namespace NPrivate;
UNIT_ASSERT_TYPES_EQUAL(decltype(Reversed(stub)), TReverseRange<TStub&>);
UNIT_ASSERT_TYPES_EQUAL(decltype(Reversed(cstub)), TReverseRange<const TStub&>);
- }
-
+ }
+
Y_UNIT_TEST(CopyMoveTest) {
- TState lvalue;
- const TState clvalue;
- UNIT_ASSERT_NO_EXCEPTION(Reversed(lvalue));
- UNIT_ASSERT_NO_EXCEPTION(Reversed(clvalue));
- }
+ TState lvalue;
+ const TState clvalue;
+ UNIT_ASSERT_NO_EXCEPTION(Reversed(lvalue));
+ UNIT_ASSERT_NO_EXCEPTION(Reversed(clvalue));
+ }
Y_UNIT_TEST(ReverseX2Test) {
TVector<int> cont = {1, 2, 3};
@@ -121,4 +121,4 @@ Y_UNIT_TEST_SUITE(TReverseAdaptor) {
UNIT_ASSERT_VALUES_EQUAL(etalon2[idx++], x);
}
}
-}
+}