aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yson/node/node.cpp
diff options
context:
space:
mode:
authormonster <monster@yandex-team.ru>2022-02-10 16:47:19 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:47:19 +0300
commitdd76ae1f6213d065375ab296699f764faafbe5bd (patch)
tree075a4553d0011d8f92752c0891794febb15912cf /library/cpp/yson/node/node.cpp
parentf02a874a7290593efbe4b3aeae69a04b46c1cc86 (diff)
downloadydb-dd76ae1f6213d065375ab296699f764faafbe5bd.tar.gz
Restoring authorship annotation for <monster@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/yson/node/node.cpp')
-rw-r--r--library/cpp/yson/node/node.cpp222
1 files changed, 111 insertions, 111 deletions
diff --git a/library/cpp/yson/node/node.cpp b/library/cpp/yson/node/node.cpp
index b39e070718..a533e34fa6 100644
--- a/library/cpp/yson/node/node.cpp
+++ b/library/cpp/yson/node/node.cpp
@@ -1,5 +1,5 @@
#include "node.h"
-
+
#include "node_io.h"
#include <library/cpp/yson/writer.h>
@@ -13,15 +13,15 @@ namespace NYT {
bool TNode::TNull::operator==(const TNull&) const {
return true;
}
-
-////////////////////////////////////////////////////////////////////////////////
-
+
+////////////////////////////////////////////////////////////////////////////////
+
bool TNode::TUndefined::operator==(const TUndefined&) const {
return true;
}
-
+
////////////////////////////////////////////////////////////////////////////////
-
+
namespace NNodeCmp {
bool IsComparableType(const TNode::EType type) {
@@ -94,15 +94,15 @@ bool operator>=(const TNode& lhs, const TNode& rhs)
TNode::TNode()
: Value_(TUndefined{})
{ }
-
+
TNode::TNode(const char* s)
: Value_(TString(s))
{ }
-
+
TNode::TNode(TStringBuf s)
: Value_(TString(s))
{ }
-
+
TNode::TNode(std::string_view s)
: Value_(TString(s))
{ }
@@ -114,12 +114,12 @@ TNode::TNode(const std::string& s)
TNode::TNode(TString s)
: Value_(std::move(s))
{ }
-
+
TNode::TNode(int i)
: Value_(static_cast<i64>(i))
{ }
-
-
+
+
TNode::TNode(unsigned int ui)
: Value_(static_cast<ui64>(ui))
{ }
@@ -127,27 +127,27 @@ TNode::TNode(unsigned int ui)
TNode::TNode(long i)
: Value_(static_cast<i64>(i))
{ }
-
+
TNode::TNode(unsigned long ui)
: Value_(static_cast<ui64>(ui))
{ }
-
+
TNode::TNode(long long i)
: Value_(static_cast<i64>(i))
{ }
-
+
TNode::TNode(unsigned long long ui)
: Value_(static_cast<ui64>(ui))
{ }
-
+
TNode::TNode(double d)
: Value_(d)
{ }
-
+
TNode::TNode(bool b)
: Value_(b)
{ }
-
+
TNode::TNode(TMapType map)
: Value_(std::move(map))
{ }
@@ -161,39 +161,39 @@ TNode::TNode(const TNode& rhs)
}
Value_ = rhs.Value_;
}
-
+
TNode& TNode::operator=(const TNode& rhs)
{
if (this != &rhs) {
TNode tmp = rhs;
Move(std::move(tmp));
- }
+ }
return *this;
}
-
+
TNode::TNode(TNode&& rhs) noexcept
: TNode()
{
Move(std::move(rhs));
}
-
+
TNode& TNode::operator=(TNode&& rhs) noexcept
{
if (this != &rhs) {
TNode tmp = std::move(rhs);
Move(std::move(tmp));
- }
+ }
return *this;
}
-
+
TNode::~TNode() = default;
-
+
void TNode::Clear()
{
ClearAttributes();
Value_ = TUndefined();
}
-
+
bool TNode::IsString() const
{
return std::holds_alternative<TString>(Value_);
@@ -203,37 +203,37 @@ bool TNode::IsInt64() const
{
return std::holds_alternative<i64>(Value_);
}
-
+
bool TNode::IsUint64() const
{
return std::holds_alternative<ui64>(Value_);
}
-
+
bool TNode::IsDouble() const
{
return std::holds_alternative<double>(Value_);
}
-
+
bool TNode::IsBool() const
{
return std::holds_alternative<bool>(Value_);
}
-
+
bool TNode::IsList() const
{
return std::holds_alternative<TListType>(Value_);
}
-
+
bool TNode::IsMap() const
{
return std::holds_alternative<TMapType>(Value_);
}
-
+
bool TNode::IsEntity() const
{
return IsNull();
}
-
+
bool TNode::IsNull() const
{
return std::holds_alternative<TNull>(Value_);
@@ -260,9 +260,9 @@ bool TNode::Empty() const
return std::get<TMapType>(Value_).empty();
default:
ythrow TTypeError() << "Empty() called for type " << GetType();
- }
+ }
}
-
+
size_t TNode::Size() const
{
switch (GetType()) {
@@ -274,9 +274,9 @@ size_t TNode::Size() const
return std::get<TMapType>(Value_).size();
default:
ythrow TTypeError() << "Size() called for type " << GetType();
- }
+ }
}
-
+
TNode::EType TNode::GetType() const
{
return std::visit(TOverloaded{
@@ -291,61 +291,61 @@ TNode::EType TNode::GetType() const
[](const TNull&) { return Null; }
}, Value_);
}
-
+
const TString& TNode::AsString() const
{
CheckType(String);
return std::get<TString>(Value_);
}
-
+
i64 TNode::AsInt64() const
{
CheckType(Int64);
return std::get<i64>(Value_);
}
-
+
ui64 TNode::AsUint64() const
{
CheckType(Uint64);
return std::get<ui64>(Value_);
}
-
+
double TNode::AsDouble() const
{
CheckType(Double);
return std::get<double>(Value_);
}
-
+
bool TNode::AsBool() const
{
CheckType(Bool);
return std::get<bool>(Value_);
}
-
+
const TNode::TListType& TNode::AsList() const
{
CheckType(List);
return std::get<TListType>(Value_);
}
-
+
const TNode::TMapType& TNode::AsMap() const
{
CheckType(Map);
return std::get<TMapType>(Value_);
}
-
+
TNode::TListType& TNode::AsList()
{
CheckType(List);
return std::get<TListType>(Value_);
}
-
+
TNode::TMapType& TNode::AsMap()
{
CheckType(Map);
return std::get<TMapType>(Value_);
}
-
+
const TString& TNode::UncheckedAsString() const noexcept
{
return std::get<TString>(Value_);
@@ -397,7 +397,7 @@ TNode TNode::CreateList()
node.Value_ = TListType{};
return node;
}
-
+
TNode TNode::CreateList(TListType list)
{
TNode node;
@@ -411,7 +411,7 @@ TNode TNode::CreateMap()
node.Value_ = TMapType{};
return node;
}
-
+
TNode TNode::CreateMap(TMapType map)
{
TNode node;
@@ -425,19 +425,19 @@ TNode TNode::CreateEntity()
node.Value_ = TNull{};
return node;
}
-
+
const TNode& TNode::operator[](size_t index) const
{
CheckType(List);
return std::get<TListType>(Value_)[index];
}
-
+
TNode& TNode::operator[](size_t index)
{
CheckType(List);
return std::get<TListType>(Value_)[index];
}
-
+
const TNode& TNode::At(size_t index) const {
CheckType(List);
const auto& list = std::get<TListType>(Value_);
@@ -461,7 +461,7 @@ TNode& TNode::Add() &
AssureList();
return std::get<TListType>(Value_).emplace_back();
}
-
+
TNode TNode::Add() &&
{
return std::move(Add());
@@ -473,7 +473,7 @@ TNode& TNode::Add(const TNode& node) &
std::get<TListType>(Value_).emplace_back(node);
return *this;
}
-
+
TNode TNode::Add(const TNode& node) &&
{
return std::move(Add(node));
@@ -485,7 +485,7 @@ TNode& TNode::Add(TNode&& node) &
std::get<TListType>(Value_).emplace_back(std::move(node));
return *this;
}
-
+
TNode TNode::Add(TNode&& node) &&
{
return std::move(Add(std::move(node)));
@@ -496,14 +496,14 @@ bool TNode::HasKey(const TStringBuf key) const
CheckType(Map);
return std::get<TMapType>(Value_).contains(key);
}
-
+
TNode& TNode::operator()(const TString& key, const TNode& value) &
{
AssureMap();
std::get<TMapType>(Value_)[key] = value;
return *this;
}
-
+
TNode TNode::operator()(const TString& key, const TNode& value) &&
{
return std::move(operator()(key, value));
@@ -515,7 +515,7 @@ TNode& TNode::operator()(const TString& key, TNode&& value) &
std::get<TMapType>(Value_)[key] = std::move(value);
return *this;
}
-
+
TNode TNode::operator()(const TString& key, TNode&& value) &&
{
return std::move(operator()(key, std::move(value)));
@@ -531,15 +531,15 @@ const TNode& TNode::operator[](const TStringBuf key) const
return notFound;
} else {
return i->second;
- }
+ }
}
-
+
TNode& TNode::operator[](const TStringBuf key)
{
AssureMap();
return std::get<TMapType>(Value_)[key];
}
-
+
const TNode& TNode::At(const TStringBuf key) const {
CheckType(Map);
const auto& map = std::get<TMapType>(Value_);
@@ -782,68 +782,68 @@ bool TNode::HasAttributes() const
{
return Attributes_ && !Attributes_->Empty();
}
-
+
void TNode::ClearAttributes()
{
if (Attributes_) {
Attributes_.Destroy();
- }
+ }
}
-
+
const TNode& TNode::GetAttributes() const
{
static TNode notFound = TNode::CreateMap();
if (!Attributes_) {
return notFound;
- }
+ }
return *Attributes_;
}
-
+
TNode& TNode::Attributes()
{
if (!Attributes_) {
CreateAttributes();
- }
+ }
return *Attributes_;
}
-
+
void TNode::MoveWithoutAttributes(TNode&& rhs)
{
Value_ = std::move(rhs.Value_);
rhs.Clear();
}
-
+
void TNode::Move(TNode&& rhs)
{
Value_ = std::move(rhs.Value_);
Attributes_ = std::move(rhs.Attributes_);
}
-
+
void TNode::CheckType(EType type) const
{
Y_ENSURE_EX(GetType() == type,
TTypeError() << "TNode type " << type << " expected, actual type " << GetType();
);
}
-
+
void TNode::AssureMap()
{
if (std::holds_alternative<TUndefined>(Value_)) {
Value_ = TMapType();
} else {
CheckType(Map);
- }
+ }
}
-
+
void TNode::AssureList()
{
if (std::holds_alternative<TUndefined>(Value_)) {
Value_ = TListType();
} else {
CheckType(List);
- }
+ }
}
-
+
void TNode::CreateAttributes()
{
Attributes_ = MakeHolder<TNode>();
@@ -862,54 +862,54 @@ void TNode::Load(IInputStream* in)
}
////////////////////////////////////////////////////////////////////////////////
-
+
bool operator==(const TNode& lhs, const TNode& rhs)
{
if (std::holds_alternative<TNode::TUndefined>(lhs.Value_) ||
std::holds_alternative<TNode::TUndefined>(rhs.Value_))
- {
+ {
// TODO: should try to remove this behaviour if nobody uses it.
return false;
- }
-
+ }
+
if (lhs.GetType() != rhs.GetType()) {
- return false;
- }
-
- if (lhs.Attributes_) {
- if (rhs.Attributes_) {
+ return false;
+ }
+
+ if (lhs.Attributes_) {
+ if (rhs.Attributes_) {
if (*lhs.Attributes_ != *rhs.Attributes_) {
return false;
}
- } else {
- return false;
- }
- } else {
- if (rhs.Attributes_) {
- return false;
- }
- }
-
+ } else {
+ return false;
+ }
+ } else {
+ if (rhs.Attributes_) {
+ return false;
+ }
+ }
+
return rhs.Value_ == lhs.Value_;
-}
-
+}
+
bool operator!=(const TNode& lhs, const TNode& rhs)
-{
- return !(lhs == rhs);
-}
-
+{
+ return !(lhs == rhs);
+}
+
bool GetBool(const TNode& node)
-{
- if (node.IsBool()) {
- return node.AsBool();
- } else if (node.IsString()) {
- return node.AsString() == "true";
- } else {
+{
+ if (node.IsBool()) {
+ return node.AsBool();
+ } else if (node.IsString()) {
+ return node.AsString() == "true";
+ } else {
ythrow TNode::TTypeError()
<< "GetBool(): not a boolean or string type";
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-} // namespace NYT
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+} // namespace NYT