|
@@ -92,64 +92,64 @@ bool operator>=(const TNode& lhs, const TNode& rhs)
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
TNode::TNode()
|
|
|
- : Value_(TUndefined{})
|
|
|
+ : Value_(TUndefined{})
|
|
|
{ }
|
|
|
|
|
|
TNode::TNode(const char* s)
|
|
|
- : Value_(TString(s))
|
|
|
+ : Value_(TString(s))
|
|
|
{ }
|
|
|
|
|
|
TNode::TNode(TStringBuf s)
|
|
|
- : Value_(TString(s))
|
|
|
+ : Value_(TString(s))
|
|
|
{ }
|
|
|
|
|
|
TNode::TNode(std::string_view s)
|
|
|
- : Value_(TString(s))
|
|
|
+ : Value_(TString(s))
|
|
|
{ }
|
|
|
|
|
|
TNode::TNode(const std::string& s)
|
|
|
- : Value_(TString(s))
|
|
|
+ : Value_(TString(s))
|
|
|
{ }
|
|
|
|
|
|
TNode::TNode(TString s)
|
|
|
- : Value_(std::move(s))
|
|
|
+ : Value_(std::move(s))
|
|
|
{ }
|
|
|
|
|
|
TNode::TNode(int i)
|
|
|
- : Value_(static_cast<i64>(i))
|
|
|
+ : Value_(static_cast<i64>(i))
|
|
|
{ }
|
|
|
|
|
|
|
|
|
TNode::TNode(unsigned int ui)
|
|
|
- : Value_(static_cast<ui64>(ui))
|
|
|
+ : Value_(static_cast<ui64>(ui))
|
|
|
{ }
|
|
|
|
|
|
TNode::TNode(long i)
|
|
|
- : Value_(static_cast<i64>(i))
|
|
|
+ : Value_(static_cast<i64>(i))
|
|
|
{ }
|
|
|
|
|
|
TNode::TNode(unsigned long ui)
|
|
|
- : Value_(static_cast<ui64>(ui))
|
|
|
+ : Value_(static_cast<ui64>(ui))
|
|
|
{ }
|
|
|
|
|
|
TNode::TNode(long long i)
|
|
|
- : Value_(static_cast<i64>(i))
|
|
|
+ : Value_(static_cast<i64>(i))
|
|
|
{ }
|
|
|
|
|
|
TNode::TNode(unsigned long long ui)
|
|
|
- : Value_(static_cast<ui64>(ui))
|
|
|
+ : Value_(static_cast<ui64>(ui))
|
|
|
{ }
|
|
|
|
|
|
TNode::TNode(double d)
|
|
|
- : Value_(d)
|
|
|
+ : Value_(d)
|
|
|
{ }
|
|
|
|
|
|
TNode::TNode(bool b)
|
|
|
- : Value_(b)
|
|
|
+ : Value_(b)
|
|
|
{ }
|
|
|
|
|
|
TNode::TNode(TMapType map)
|
|
|
- : Value_(std::move(map))
|
|
|
+ : Value_(std::move(map))
|
|
|
{ }
|
|
|
|
|
|
TNode::TNode(const TNode& rhs)
|
|
@@ -196,37 +196,37 @@ void TNode::Clear()
|
|
|
|
|
|
bool TNode::IsString() const
|
|
|
{
|
|
|
- return std::holds_alternative<TString>(Value_);
|
|
|
+ return std::holds_alternative<TString>(Value_);
|
|
|
}
|
|
|
|
|
|
bool TNode::IsInt64() const
|
|
|
{
|
|
|
- return std::holds_alternative<i64>(Value_);
|
|
|
+ return std::holds_alternative<i64>(Value_);
|
|
|
}
|
|
|
|
|
|
bool TNode::IsUint64() const
|
|
|
{
|
|
|
- return std::holds_alternative<ui64>(Value_);
|
|
|
+ return std::holds_alternative<ui64>(Value_);
|
|
|
}
|
|
|
|
|
|
bool TNode::IsDouble() const
|
|
|
{
|
|
|
- return std::holds_alternative<double>(Value_);
|
|
|
+ return std::holds_alternative<double>(Value_);
|
|
|
}
|
|
|
|
|
|
bool TNode::IsBool() const
|
|
|
{
|
|
|
- return std::holds_alternative<bool>(Value_);
|
|
|
+ return std::holds_alternative<bool>(Value_);
|
|
|
}
|
|
|
|
|
|
bool TNode::IsList() const
|
|
|
{
|
|
|
- return std::holds_alternative<TListType>(Value_);
|
|
|
+ return std::holds_alternative<TListType>(Value_);
|
|
|
}
|
|
|
|
|
|
bool TNode::IsMap() const
|
|
|
{
|
|
|
- return std::holds_alternative<TMapType>(Value_);
|
|
|
+ return std::holds_alternative<TMapType>(Value_);
|
|
|
}
|
|
|
|
|
|
bool TNode::IsEntity() const
|
|
@@ -236,12 +236,12 @@ bool TNode::IsEntity() const
|
|
|
|
|
|
bool TNode::IsNull() const
|
|
|
{
|
|
|
- return std::holds_alternative<TNull>(Value_);
|
|
|
+ return std::holds_alternative<TNull>(Value_);
|
|
|
}
|
|
|
|
|
|
bool TNode::IsUndefined() const
|
|
|
{
|
|
|
- return std::holds_alternative<TUndefined>(Value_);
|
|
|
+ return std::holds_alternative<TUndefined>(Value_);
|
|
|
}
|
|
|
|
|
|
bool TNode::HasValue() const
|
|
@@ -253,11 +253,11 @@ bool TNode::Empty() const
|
|
|
{
|
|
|
switch (GetType()) {
|
|
|
case String:
|
|
|
- return std::get<TString>(Value_).empty();
|
|
|
+ return std::get<TString>(Value_).empty();
|
|
|
case List:
|
|
|
- return std::get<TListType>(Value_).empty();
|
|
|
+ return std::get<TListType>(Value_).empty();
|
|
|
case Map:
|
|
|
- return std::get<TMapType>(Value_).empty();
|
|
|
+ return std::get<TMapType>(Value_).empty();
|
|
|
default:
|
|
|
ythrow TTypeError() << "Empty() called for type " << GetType();
|
|
|
}
|
|
@@ -267,11 +267,11 @@ size_t TNode::Size() const
|
|
|
{
|
|
|
switch (GetType()) {
|
|
|
case String:
|
|
|
- return std::get<TString>(Value_).size();
|
|
|
+ return std::get<TString>(Value_).size();
|
|
|
case List:
|
|
|
- return std::get<TListType>(Value_).size();
|
|
|
+ return std::get<TListType>(Value_).size();
|
|
|
case Map:
|
|
|
- return std::get<TMapType>(Value_).size();
|
|
|
+ return std::get<TMapType>(Value_).size();
|
|
|
default:
|
|
|
ythrow TTypeError() << "Size() called for type " << GetType();
|
|
|
}
|
|
@@ -295,106 +295,106 @@ TNode::EType TNode::GetType() const
|
|
|
const TString& TNode::AsString() const
|
|
|
{
|
|
|
CheckType(String);
|
|
|
- return std::get<TString>(Value_);
|
|
|
+ return std::get<TString>(Value_);
|
|
|
}
|
|
|
|
|
|
i64 TNode::AsInt64() const
|
|
|
{
|
|
|
CheckType(Int64);
|
|
|
- return std::get<i64>(Value_);
|
|
|
+ return std::get<i64>(Value_);
|
|
|
}
|
|
|
|
|
|
ui64 TNode::AsUint64() const
|
|
|
{
|
|
|
CheckType(Uint64);
|
|
|
- return std::get<ui64>(Value_);
|
|
|
+ return std::get<ui64>(Value_);
|
|
|
}
|
|
|
|
|
|
double TNode::AsDouble() const
|
|
|
{
|
|
|
CheckType(Double);
|
|
|
- return std::get<double>(Value_);
|
|
|
+ return std::get<double>(Value_);
|
|
|
}
|
|
|
|
|
|
bool TNode::AsBool() const
|
|
|
{
|
|
|
CheckType(Bool);
|
|
|
- return std::get<bool>(Value_);
|
|
|
+ return std::get<bool>(Value_);
|
|
|
}
|
|
|
|
|
|
const TNode::TListType& TNode::AsList() const
|
|
|
{
|
|
|
CheckType(List);
|
|
|
- return std::get<TListType>(Value_);
|
|
|
+ return std::get<TListType>(Value_);
|
|
|
}
|
|
|
|
|
|
const TNode::TMapType& TNode::AsMap() const
|
|
|
{
|
|
|
CheckType(Map);
|
|
|
- return std::get<TMapType>(Value_);
|
|
|
+ return std::get<TMapType>(Value_);
|
|
|
}
|
|
|
|
|
|
TNode::TListType& TNode::AsList()
|
|
|
{
|
|
|
CheckType(List);
|
|
|
- return std::get<TListType>(Value_);
|
|
|
+ return std::get<TListType>(Value_);
|
|
|
}
|
|
|
|
|
|
TNode::TMapType& TNode::AsMap()
|
|
|
{
|
|
|
CheckType(Map);
|
|
|
- return std::get<TMapType>(Value_);
|
|
|
+ return std::get<TMapType>(Value_);
|
|
|
}
|
|
|
|
|
|
const TString& TNode::UncheckedAsString() const noexcept
|
|
|
{
|
|
|
- return std::get<TString>(Value_);
|
|
|
+ return std::get<TString>(Value_);
|
|
|
}
|
|
|
|
|
|
i64 TNode::UncheckedAsInt64() const noexcept
|
|
|
{
|
|
|
- return std::get<i64>(Value_);
|
|
|
+ return std::get<i64>(Value_);
|
|
|
}
|
|
|
|
|
|
ui64 TNode::UncheckedAsUint64() const noexcept
|
|
|
{
|
|
|
- return std::get<ui64>(Value_);
|
|
|
+ return std::get<ui64>(Value_);
|
|
|
}
|
|
|
|
|
|
double TNode::UncheckedAsDouble() const noexcept
|
|
|
{
|
|
|
- return std::get<double>(Value_);
|
|
|
+ return std::get<double>(Value_);
|
|
|
}
|
|
|
|
|
|
bool TNode::UncheckedAsBool() const noexcept
|
|
|
{
|
|
|
- return std::get<bool>(Value_);
|
|
|
+ return std::get<bool>(Value_);
|
|
|
}
|
|
|
|
|
|
const TNode::TListType& TNode::UncheckedAsList() const noexcept
|
|
|
{
|
|
|
- return std::get<TListType>(Value_);
|
|
|
+ return std::get<TListType>(Value_);
|
|
|
}
|
|
|
|
|
|
const TNode::TMapType& TNode::UncheckedAsMap() const noexcept
|
|
|
{
|
|
|
- return std::get<TMapType>(Value_);
|
|
|
+ return std::get<TMapType>(Value_);
|
|
|
}
|
|
|
|
|
|
TNode::TListType& TNode::UncheckedAsList() noexcept
|
|
|
{
|
|
|
- return std::get<TListType>(Value_);
|
|
|
+ return std::get<TListType>(Value_);
|
|
|
}
|
|
|
|
|
|
TNode::TMapType& TNode::UncheckedAsMap() noexcept
|
|
|
{
|
|
|
- return std::get<TMapType>(Value_);
|
|
|
+ return std::get<TMapType>(Value_);
|
|
|
}
|
|
|
|
|
|
TNode TNode::CreateList()
|
|
|
{
|
|
|
TNode node;
|
|
|
- node.Value_ = TListType{};
|
|
|
+ node.Value_ = TListType{};
|
|
|
return node;
|
|
|
}
|
|
|
|
|
@@ -408,7 +408,7 @@ TNode TNode::CreateList(TListType list)
|
|
|
TNode TNode::CreateMap()
|
|
|
{
|
|
|
TNode node;
|
|
|
- node.Value_ = TMapType{};
|
|
|
+ node.Value_ = TMapType{};
|
|
|
return node;
|
|
|
}
|
|
|
|
|
@@ -422,25 +422,25 @@ TNode TNode::CreateMap(TMapType map)
|
|
|
TNode TNode::CreateEntity()
|
|
|
{
|
|
|
TNode node;
|
|
|
- node.Value_ = TNull{};
|
|
|
+ node.Value_ = TNull{};
|
|
|
return node;
|
|
|
}
|
|
|
|
|
|
const TNode& TNode::operator[](size_t index) const
|
|
|
{
|
|
|
CheckType(List);
|
|
|
- return std::get<TListType>(Value_)[index];
|
|
|
+ return std::get<TListType>(Value_)[index];
|
|
|
}
|
|
|
|
|
|
TNode& TNode::operator[](size_t index)
|
|
|
{
|
|
|
CheckType(List);
|
|
|
- return std::get<TListType>(Value_)[index];
|
|
|
+ return std::get<TListType>(Value_)[index];
|
|
|
}
|
|
|
|
|
|
const TNode& TNode::At(size_t index) const {
|
|
|
CheckType(List);
|
|
|
- const auto& list = std::get<TListType>(Value_);
|
|
|
+ const auto& list = std::get<TListType>(Value_);
|
|
|
if (index >= list.size()) {
|
|
|
ythrow TLookupError() << "List out-of-range: requested index=" << index << ", but size=" << list.size();
|
|
|
}
|
|
@@ -449,7 +449,7 @@ const TNode& TNode::At(size_t index) const {
|
|
|
|
|
|
TNode& TNode::At(size_t index) {
|
|
|
CheckType(List);
|
|
|
- auto& list = std::get<TListType>(Value_);
|
|
|
+ auto& list = std::get<TListType>(Value_);
|
|
|
if (index >= list.size()) {
|
|
|
ythrow TLookupError() << "List out-of-range: requested index=" << index << ", but size=" << list.size();
|
|
|
}
|
|
@@ -459,7 +459,7 @@ TNode& TNode::At(size_t index) {
|
|
|
TNode& TNode::Add() &
|
|
|
{
|
|
|
AssureList();
|
|
|
- return std::get<TListType>(Value_).emplace_back();
|
|
|
+ return std::get<TListType>(Value_).emplace_back();
|
|
|
}
|
|
|
|
|
|
TNode TNode::Add() &&
|
|
@@ -470,7 +470,7 @@ TNode TNode::Add() &&
|
|
|
TNode& TNode::Add(const TNode& node) &
|
|
|
{
|
|
|
AssureList();
|
|
|
- std::get<TListType>(Value_).emplace_back(node);
|
|
|
+ std::get<TListType>(Value_).emplace_back(node);
|
|
|
return *this;
|
|
|
}
|
|
|
|
|
@@ -482,7 +482,7 @@ TNode TNode::Add(const TNode& node) &&
|
|
|
TNode& TNode::Add(TNode&& node) &
|
|
|
{
|
|
|
AssureList();
|
|
|
- std::get<TListType>(Value_).emplace_back(std::move(node));
|
|
|
+ std::get<TListType>(Value_).emplace_back(std::move(node));
|
|
|
return *this;
|
|
|
}
|
|
|
|
|
@@ -494,13 +494,13 @@ TNode TNode::Add(TNode&& node) &&
|
|
|
bool TNode::HasKey(const TStringBuf key) const
|
|
|
{
|
|
|
CheckType(Map);
|
|
|
- return std::get<TMapType>(Value_).contains(key);
|
|
|
+ return std::get<TMapType>(Value_).contains(key);
|
|
|
}
|
|
|
|
|
|
TNode& TNode::operator()(const TString& key, const TNode& value) &
|
|
|
{
|
|
|
AssureMap();
|
|
|
- std::get<TMapType>(Value_)[key] = value;
|
|
|
+ std::get<TMapType>(Value_)[key] = value;
|
|
|
return *this;
|
|
|
}
|
|
|
|
|
@@ -512,7 +512,7 @@ TNode TNode::operator()(const TString& key, const TNode& value) &&
|
|
|
TNode& TNode::operator()(const TString& key, TNode&& value) &
|
|
|
{
|
|
|
AssureMap();
|
|
|
- std::get<TMapType>(Value_)[key] = std::move(value);
|
|
|
+ std::get<TMapType>(Value_)[key] = std::move(value);
|
|
|
return *this;
|
|
|
}
|
|
|
|
|
@@ -525,7 +525,7 @@ const TNode& TNode::operator[](const TStringBuf key) const
|
|
|
{
|
|
|
CheckType(Map);
|
|
|
static TNode notFound;
|
|
|
- const auto& map = std::get<TMapType>(Value_);
|
|
|
+ const auto& map = std::get<TMapType>(Value_);
|
|
|
TMapType::const_iterator i = map.find(key);
|
|
|
if (i == map.end()) {
|
|
|
return notFound;
|
|
@@ -537,12 +537,12 @@ const TNode& TNode::operator[](const TStringBuf key) const
|
|
|
TNode& TNode::operator[](const TStringBuf key)
|
|
|
{
|
|
|
AssureMap();
|
|
|
- return std::get<TMapType>(Value_)[key];
|
|
|
+ return std::get<TMapType>(Value_)[key];
|
|
|
}
|
|
|
|
|
|
const TNode& TNode::At(const TStringBuf key) const {
|
|
|
CheckType(Map);
|
|
|
- const auto& map = std::get<TMapType>(Value_);
|
|
|
+ const auto& map = std::get<TMapType>(Value_);
|
|
|
TMapType::const_iterator i = map.find(key);
|
|
|
if (i == map.end()) {
|
|
|
ythrow TLookupError() << "Cannot find key " << key;
|
|
@@ -553,7 +553,7 @@ const TNode& TNode::At(const TStringBuf key) const {
|
|
|
|
|
|
TNode& TNode::At(const TStringBuf key) {
|
|
|
CheckType(Map);
|
|
|
- auto& map = std::get<TMapType>(Value_);
|
|
|
+ auto& map = std::get<TMapType>(Value_);
|
|
|
TMapType::iterator i = map.find(key);
|
|
|
if (i == map.end()) {
|
|
|
ythrow TLookupError() << "Cannot find key " << key;
|
|
@@ -828,7 +828,7 @@ void TNode::CheckType(EType type) const
|
|
|
|
|
|
void TNode::AssureMap()
|
|
|
{
|
|
|
- if (std::holds_alternative<TUndefined>(Value_)) {
|
|
|
+ if (std::holds_alternative<TUndefined>(Value_)) {
|
|
|
Value_ = TMapType();
|
|
|
} else {
|
|
|
CheckType(Map);
|
|
@@ -837,7 +837,7 @@ void TNode::AssureMap()
|
|
|
|
|
|
void TNode::AssureList()
|
|
|
{
|
|
|
- if (std::holds_alternative<TUndefined>(Value_)) {
|
|
|
+ if (std::holds_alternative<TUndefined>(Value_)) {
|
|
|
Value_ = TListType();
|
|
|
} else {
|
|
|
CheckType(List);
|
|
@@ -865,8 +865,8 @@ 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_))
|
|
|
+ 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;
|