aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/scheme/domscheme_traits.h
diff options
context:
space:
mode:
authorIvan Korostelev <ivan.korostelev@gmail.com>2022-02-10 16:46:41 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:41 +0300
commitb5e813096385b2d9e16b572711fec5bf2eb5058d (patch)
tree49e222ea1c5804306084bb3ae065bb702625360f /library/cpp/scheme/domscheme_traits.h
parentf3a52f9d3e18d1159abbc85fa65eeda69d971657 (diff)
downloadydb-b5e813096385b2d9e16b572711fec5bf2eb5058d.tar.gz
Restoring authorship annotation for Ivan Korostelev <ivan.korostelev@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/scheme/domscheme_traits.h')
-rw-r--r--library/cpp/scheme/domscheme_traits.h338
1 files changed, 169 insertions, 169 deletions
diff --git a/library/cpp/scheme/domscheme_traits.h b/library/cpp/scheme/domscheme_traits.h
index 500cadf9c8..a11c4dd444 100644
--- a/library/cpp/scheme/domscheme_traits.h
+++ b/library/cpp/scheme/domscheme_traits.h
@@ -1,14 +1,14 @@
-#pragma once
-
+#pragma once
+
#include "scheme.h"
#include <util/string/cast.h>
-
-struct TSchemeTraits {
+
+struct TSchemeTraits {
using TValue = NSc::TValue;
using TValueRef = TValue*;
using TConstValueRef = const TValue*;
using TStringType = TStringBuf;
-
+
// anyvalue defaults
template <class T>
static inline TValue Value(T&& t) {
@@ -28,113 +28,113 @@ struct TSchemeTraits {
return &v;
}
- // common ops
- static inline bool IsNull(TConstValueRef v) {
- return v->IsNull();
- }
-
- static inline TString ToJson(TConstValueRef v) {
- return v->ToJson();
- }
-
- // struct ops
- static inline TValueRef GetField(TValueRef v, const TStringBuf& name) {
- return &(*v)[name];
- }
-
- static inline TConstValueRef GetField(TConstValueRef v, const TStringBuf& name) {
- return &(*v)[name];
- }
-
- // array ops
- static bool IsArray(TConstValueRef v) {
- return v->IsArray();
- }
-
- static inline void ArrayClear(TValueRef v) {
+ // common ops
+ static inline bool IsNull(TConstValueRef v) {
+ return v->IsNull();
+ }
+
+ static inline TString ToJson(TConstValueRef v) {
+ return v->ToJson();
+ }
+
+ // struct ops
+ static inline TValueRef GetField(TValueRef v, const TStringBuf& name) {
+ return &(*v)[name];
+ }
+
+ static inline TConstValueRef GetField(TConstValueRef v, const TStringBuf& name) {
+ return &(*v)[name];
+ }
+
+ // array ops
+ static bool IsArray(TConstValueRef v) {
+ return v->IsArray();
+ }
+
+ static inline void ArrayClear(TValueRef v) {
v->SetArray();
- v->ClearArray();
- }
-
+ v->ClearArray();
+ }
+
using TArrayIterator = size_t;
static inline TValueRef ArrayElement(TValueRef v, TArrayIterator n) {
- return &(*v)[n];
- }
-
+ return &(*v)[n];
+ }
+
static inline TConstValueRef ArrayElement(TConstValueRef v, TArrayIterator n) {
- return &(*v)[n];
- }
-
- static inline size_t ArraySize(TConstValueRef v) {
- return v->GetArray().size();
- }
-
- static inline TArrayIterator ArrayBegin(TConstValueRef) {
- return 0;
- }
-
- static inline TArrayIterator ArrayEnd(TConstValueRef v) {
- return ArraySize(v);
- }
-
- // dict ops
- static bool IsDict(TConstValueRef v) {
- return v->IsDict();
- }
-
- static inline void DictClear(TValueRef v) {
+ return &(*v)[n];
+ }
+
+ static inline size_t ArraySize(TConstValueRef v) {
+ return v->GetArray().size();
+ }
+
+ static inline TArrayIterator ArrayBegin(TConstValueRef) {
+ return 0;
+ }
+
+ static inline TArrayIterator ArrayEnd(TConstValueRef v) {
+ return ArraySize(v);
+ }
+
+ // dict ops
+ static bool IsDict(TConstValueRef v) {
+ return v->IsDict();
+ }
+
+ static inline void DictClear(TValueRef v) {
v->SetDict();
- v->ClearDict();
- }
-
- static inline TValueRef DictElement(TValueRef v, TStringBuf key) {
- return &(*v)[key];
- }
-
- static inline TConstValueRef DictElement(TConstValueRef v, TStringBuf key) {
- return &(*v)[key];
- }
-
+ v->ClearDict();
+ }
+
+ static inline TValueRef DictElement(TValueRef v, TStringBuf key) {
+ return &(*v)[key];
+ }
+
+ static inline TConstValueRef DictElement(TConstValueRef v, TStringBuf key) {
+ return &(*v)[key];
+ }
+
static inline size_t DictSize(TConstValueRef v) {
return v->GetDict().size();
- }
-
- using TDictIterator = NSc::TDict::const_iterator;
-
- static inline TDictIterator DictBegin(TConstValueRef v) {
- return v->GetDict().begin();
- }
-
- static inline TDictIterator DictEnd(TConstValueRef v) {
- return v->GetDict().end();
- }
-
- static inline TStringBuf DictIteratorKey(TConstValueRef /*dict*/, const TDictIterator& it) {
- return it->first;
- }
-
- static inline TConstValueRef DictIteratorValue(TConstValueRef /*dict*/, const TDictIterator& it) {
- return &it->second;
- }
-
- // boolean ops
- static inline void Get(TConstValueRef v, bool def, bool& b) {
- b = def == true ? !v->IsExplicitFalse() : v->IsTrue();
- }
-
- static inline void Get(TConstValueRef v, bool& b) {
- b = v->IsTrue();
- }
-
- static inline void Set(TValueRef v, bool b) {
- v->SetIntNumber(b ? 1 : 0);
- }
-
- static inline bool IsValidPrimitive(const bool&, TConstValueRef v) {
- return v->IsTrue() || v->IsExplicitFalse();
- }
-
+ }
+
+ using TDictIterator = NSc::TDict::const_iterator;
+
+ static inline TDictIterator DictBegin(TConstValueRef v) {
+ return v->GetDict().begin();
+ }
+
+ static inline TDictIterator DictEnd(TConstValueRef v) {
+ return v->GetDict().end();
+ }
+
+ static inline TStringBuf DictIteratorKey(TConstValueRef /*dict*/, const TDictIterator& it) {
+ return it->first;
+ }
+
+ static inline TConstValueRef DictIteratorValue(TConstValueRef /*dict*/, const TDictIterator& it) {
+ return &it->second;
+ }
+
+ // boolean ops
+ static inline void Get(TConstValueRef v, bool def, bool& b) {
+ b = def == true ? !v->IsExplicitFalse() : v->IsTrue();
+ }
+
+ static inline void Get(TConstValueRef v, bool& b) {
+ b = v->IsTrue();
+ }
+
+ static inline void Set(TValueRef v, bool b) {
+ v->SetIntNumber(b ? 1 : 0);
+ }
+
+ static inline bool IsValidPrimitive(const bool&, TConstValueRef v) {
+ return v->IsTrue() || v->IsExplicitFalse();
+ }
+
#define INTEGER_OPS_EX(type, min, max, isUnsigned) \
static inline void Get(TConstValueRef v, type def, type& i) { \
if (isUnsigned) { \
@@ -157,72 +157,72 @@ struct TSchemeTraits {
} \
static inline void Set(TValueRef v, type i) { \
v->SetIntNumber(i); \
- }
-
-#define INTEGER_OPS(type, isUnsigned) INTEGER_OPS_EX(type, Min<type>(), Max<type>(), isUnsigned)
-
- INTEGER_OPS(i8, false)
- INTEGER_OPS(i16, false)
- INTEGER_OPS(i32, false)
- INTEGER_OPS(i64, false)
- INTEGER_OPS(ui8, true)
- INTEGER_OPS(ui16, true)
- INTEGER_OPS(ui32, true)
+ }
+
+#define INTEGER_OPS(type, isUnsigned) INTEGER_OPS_EX(type, Min<type>(), Max<type>(), isUnsigned)
+
+ INTEGER_OPS(i8, false)
+ INTEGER_OPS(i16, false)
+ INTEGER_OPS(i32, false)
+ INTEGER_OPS(i64, false)
+ INTEGER_OPS(ui8, true)
+ INTEGER_OPS(ui16, true)
+ INTEGER_OPS(ui32, true)
INTEGER_OPS_EX(ui64, 0, (i64)(Max<i64>() >> 1), true)
-
-#undef INTEGER_OPS
-#undef INTEGER_OPS_EX
-
- // double ops
- static inline bool Get(TConstValueRef v, double def, double& d) {
- if (v->IsNumber()) {
- d = v->GetNumber(def);
- return true;
- }
- d = def;
- return false;
- }
-
- static inline void Get(TConstValueRef v, double& d) {
- d = v->GetNumber();
- }
-
- static inline void Set(TValueRef v, double d) {
- v->SetNumber(d);
- }
-
- static inline bool IsValidPrimitive(const double&, TConstValueRef v) {
- return v->IsNumber();
- }
-
- // string ops
- static inline void Get(TConstValueRef v, TStringBuf def, TStringBuf& s) {
- s = v->GetString(def);
- }
-
- static inline void Get(TConstValueRef v, TStringBuf& s) {
- s = v->GetString();
- }
-
- static inline void Set(TValueRef v, TStringBuf s) {
- v->SetString(s);
- }
-
- static inline bool IsValidPrimitive(const TStringBuf&, TConstValueRef v) {
- return v->IsString();
- }
-
- // validation ops
+
+#undef INTEGER_OPS
+#undef INTEGER_OPS_EX
+
+ // double ops
+ static inline bool Get(TConstValueRef v, double def, double& d) {
+ if (v->IsNumber()) {
+ d = v->GetNumber(def);
+ return true;
+ }
+ d = def;
+ return false;
+ }
+
+ static inline void Get(TConstValueRef v, double& d) {
+ d = v->GetNumber();
+ }
+
+ static inline void Set(TValueRef v, double d) {
+ v->SetNumber(d);
+ }
+
+ static inline bool IsValidPrimitive(const double&, TConstValueRef v) {
+ return v->IsNumber();
+ }
+
+ // string ops
+ static inline void Get(TConstValueRef v, TStringBuf def, TStringBuf& s) {
+ s = v->GetString(def);
+ }
+
+ static inline void Get(TConstValueRef v, TStringBuf& s) {
+ s = v->GetString();
+ }
+
+ static inline void Set(TValueRef v, TStringBuf s) {
+ v->SetString(s);
+ }
+
+ static inline bool IsValidPrimitive(const TStringBuf&, TConstValueRef v) {
+ return v->IsString();
+ }
+
+ // validation ops
static inline TVector<TString> GetKeys(TConstValueRef v) {
TVector<TString> res;
- for (const auto& key : v->DictKeys(true)) {
+ for (const auto& key : v->DictKeys(true)) {
res.push_back(ToString(key));
- }
- return res;
- }
-
- template <typename T>
- static inline bool IsValidPrimitive(const T&, TConstValueRef) {
- return false;
- }
-};
+ }
+ return res;
+ }
+
+ template <typename T>
+ static inline bool IsValidPrimitive(const T&, TConstValueRef) {
+ return false;
+ }
+};