diff options
author | ermolovd <ermolovd@yandex-team.ru> | 2022-02-10 16:47:53 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:53 +0300 |
commit | b91bcef7c99a119b0846479ef71bfab4beec72ca (patch) | |
tree | be118d54d12a61bc4812ceb0a266a170a2fa3bc9 /library/cpp/yson | |
parent | f421873774cf0b71743afbe5f6677861e66601ea (diff) | |
download | ydb-b91bcef7c99a119b0846479ef71bfab4beec72ca.tar.gz |
Restoring authorship annotation for <ermolovd@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/yson')
39 files changed, 839 insertions, 839 deletions
diff --git a/library/cpp/yson/consumer.cpp b/library/cpp/yson/consumer.cpp index 40ae452978..b1cd000631 100644 --- a/library/cpp/yson/consumer.cpp +++ b/library/cpp/yson/consumer.cpp @@ -2,7 +2,7 @@ #include "string.h" #include "parser.h" -namespace NYson { +namespace NYson { //////////////////////////////////////////////////////////////////////////////// @@ -12,4 +12,4 @@ namespace NYson { //////////////////////////////////////////////////////////////////////////////// -} // namespace NYson +} // namespace NYson diff --git a/library/cpp/yson/consumer.h b/library/cpp/yson/consumer.h index d5a9d66335..ad17a7e2dd 100644 --- a/library/cpp/yson/consumer.h +++ b/library/cpp/yson/consumer.h @@ -5,9 +5,9 @@ #include <util/generic/strbuf.h> #include <util/system/defaults.h> -namespace NYson { +namespace NYson { struct TYsonConsumerBase : public virtual NYT::NYson::IYsonConsumer { void OnRaw(TStringBuf ysonNode, NYT::NYson::EYsonType type) override; }; -} // namespace NYson +} // namespace NYson diff --git a/library/cpp/yson/detail.h b/library/cpp/yson/detail.h index 27f5e8ffff..d2e965373f 100644 --- a/library/cpp/yson/detail.h +++ b/library/cpp/yson/detail.h @@ -10,7 +10,7 @@ #include <util/string/cast.h> #include <util/stream/input.h> -namespace NYson { +namespace NYson { namespace NDetail { //////////////////////////////////////////////////////////////////////////////// @@ -803,4 +803,4 @@ namespace NYson { //////////////////////////////////////////////////////////////////////////////// -} // namespace NYson +} // namespace NYson diff --git a/library/cpp/yson/format.h b/library/cpp/yson/format.h index 2ff6dc9f6e..92053e05ab 100644 --- a/library/cpp/yson/format.h +++ b/library/cpp/yson/format.h @@ -2,7 +2,7 @@ #include "token.h" -namespace NYson { +namespace NYson { //////////////////////////////////////////////////////////////////////////////// const ETokenType BeginListToken = LeftBracket; @@ -22,4 +22,4 @@ namespace NYson { //////////////////////////////////////////////////////////////////////////////// -} // namespace NYson +} // namespace NYson diff --git a/library/cpp/yson/json/json_writer.h b/library/cpp/yson/json/json_writer.h index d84ac0de53..39a3c85ba7 100644 --- a/library/cpp/yson/json/json_writer.h +++ b/library/cpp/yson/json/json_writer.h @@ -1,7 +1,7 @@ #pragma once -#include <library/cpp/yson/public.h> -#include <library/cpp/yson/consumer.h> +#include <library/cpp/yson/public.h> +#include <library/cpp/yson/consumer.h> #include <library/cpp/json/json_writer.h> @@ -27,7 +27,7 @@ namespace NYT { }; class TJsonWriter - : public ::NYson::TYsonConsumerBase { + : public ::NYson::TYsonConsumerBase { public: TJsonWriter( IOutputStream* output, diff --git a/library/cpp/yson/json/ya.make b/library/cpp/yson/json/ya.make index 625a6b231e..0d9314d455 100644 --- a/library/cpp/yson/json/ya.make +++ b/library/cpp/yson/json/ya.make @@ -1,17 +1,17 @@ -LIBRARY() - -OWNER( - ermolovd - g:yt -) - -SRCS( - json_writer.cpp - yson2json_adapter.cpp -) - -PEERDIR( - library/cpp/json -) - -END() +LIBRARY() + +OWNER( + ermolovd + g:yt +) + +SRCS( + json_writer.cpp + yson2json_adapter.cpp +) + +PEERDIR( + library/cpp/json +) + +END() diff --git a/library/cpp/yson/json/yson2json_adapter.h b/library/cpp/yson/json/yson2json_adapter.h index da1bf5ba70..4056be7559 100644 --- a/library/cpp/yson/json/yson2json_adapter.h +++ b/library/cpp/yson/json/yson2json_adapter.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/yson/consumer.h> +#include <library/cpp/yson/consumer.h> #include <library/cpp/json/json_reader.h> @@ -21,7 +21,7 @@ namespace NYT { }; public: - TYson2JsonCallbacksAdapter(::NYson::TYsonConsumerBase* impl, bool throwException = false); + TYson2JsonCallbacksAdapter(::NYson::TYsonConsumerBase* impl, bool throwException = false); bool OnNull() override; bool OnBoolean(bool val) override; @@ -47,7 +47,7 @@ namespace NYT { void WrapIfListItem(); private: - ::NYson::TYsonConsumerBase* Impl_; + ::NYson::TYsonConsumerBase* Impl_; TState State_; }; } diff --git a/library/cpp/yson/lexer.cpp b/library/cpp/yson/lexer.cpp index 5eae94273b..acb7987bdc 100644 --- a/library/cpp/yson/lexer.cpp +++ b/library/cpp/yson/lexer.cpp @@ -4,7 +4,7 @@ #include <util/generic/ptr.h> -namespace NYson { +namespace NYson { //////////////////////////////////////////////////////////////////////////////// class TStatelessLexer::TImpl { @@ -40,4 +40,4 @@ namespace NYson { //////////////////////////////////////////////////////////////////////////////// -} // namespace NYson +} // namespace NYson diff --git a/library/cpp/yson/lexer.h b/library/cpp/yson/lexer.h index d9d701874d..7a1dcf77aa 100644 --- a/library/cpp/yson/lexer.h +++ b/library/cpp/yson/lexer.h @@ -5,7 +5,7 @@ #include <util/generic/ptr.h> -namespace NYson { +namespace NYson { //////////////////////////////////////////////////////////////////////////////// class TStatelessLexer { @@ -23,4 +23,4 @@ namespace NYson { //////////////////////////////////////////////////////////////////////////////// -} // namespace NYson +} // namespace NYson diff --git a/library/cpp/yson/lexer_detail.h b/library/cpp/yson/lexer_detail.h index 0bba30acdd..f6ff4f46a1 100644 --- a/library/cpp/yson/lexer_detail.h +++ b/library/cpp/yson/lexer_detail.h @@ -3,7 +3,7 @@ #include "detail.h" #include "token.h" -namespace NYson { +namespace NYson { //////////////////////////////////////////////////////////////////////////////// namespace NDetail { @@ -293,4 +293,4 @@ namespace NYson { //////////////////////////////////////////////////////////////////////////////// -} // namespace NYson +} // namespace NYson diff --git a/library/cpp/yson/node/node.cpp b/library/cpp/yson/node/node.cpp index b39e070718..14c9aaefea 100644 --- a/library/cpp/yson/node/node.cpp +++ b/library/cpp/yson/node/node.cpp @@ -1,26 +1,26 @@ -#include "node.h" - -#include "node_io.h" - -#include <library/cpp/yson/writer.h> +#include "node.h" +#include "node_io.h" + +#include <library/cpp/yson/writer.h> + #include <util/generic/overloaded.h> -namespace NYT { +namespace NYT { -//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// -bool TNode::TNull::operator==(const TNull&) const { - return true; -} +bool TNode::TNull::operator==(const TNull&) const { + return true; +} //////////////////////////////////////////////////////////////////////////////// -bool TNode::TUndefined::operator==(const TUndefined&) const { - return true; -} +bool TNode::TUndefined::operator==(const TUndefined&) const { + return true; +} -//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// namespace NNodeCmp { @@ -91,17 +91,17 @@ bool operator>=(const TNode& lhs, const TNode& rhs) //////////////////////////////////////////////////////////////////////////////// -TNode::TNode() +TNode::TNode() : Value_(TUndefined{}) -{ } +{ } -TNode::TNode(const char* s) +TNode::TNode(const char* s) : Value_(TString(s)) -{ } +{ } TNode::TNode(TStringBuf s) : Value_(TString(s)) -{ } +{ } TNode::TNode(std::string_view s) : Value_(TString(s)) @@ -113,172 +113,172 @@ TNode::TNode(const std::string& s) TNode::TNode(TString s) : Value_(std::move(s)) -{ } +{ } -TNode::TNode(int i) +TNode::TNode(int i) : Value_(static_cast<i64>(i)) -{ } +{ } -TNode::TNode(unsigned int ui) +TNode::TNode(unsigned int ui) : Value_(static_cast<ui64>(ui)) -{ } +{ } -TNode::TNode(long i) +TNode::TNode(long i) : Value_(static_cast<i64>(i)) -{ } +{ } -TNode::TNode(unsigned long ui) +TNode::TNode(unsigned long ui) : Value_(static_cast<ui64>(ui)) -{ } +{ } -TNode::TNode(long long i) +TNode::TNode(long long i) : Value_(static_cast<i64>(i)) -{ } +{ } -TNode::TNode(unsigned long long ui) +TNode::TNode(unsigned long long ui) : Value_(static_cast<ui64>(ui)) -{ } +{ } -TNode::TNode(double d) +TNode::TNode(double d) : Value_(d) -{ } +{ } -TNode::TNode(bool b) +TNode::TNode(bool b) : Value_(b) -{ } +{ } TNode::TNode(TMapType map) : Value_(std::move(map)) { } -TNode::TNode(const TNode& rhs) - : TNode() -{ - if (rhs.Attributes_) { - CreateAttributes(); - *Attributes_ = *rhs.Attributes_; - } - Value_ = rhs.Value_; -} - -TNode& TNode::operator=(const TNode& rhs) -{ - if (this != &rhs) { - TNode tmp = rhs; - Move(std::move(tmp)); - } - return *this; -} +TNode::TNode(const TNode& rhs) + : TNode() +{ + if (rhs.Attributes_) { + CreateAttributes(); + *Attributes_ = *rhs.Attributes_; + } + 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() +{ + Move(std::move(rhs)); +} TNode& TNode::operator=(TNode&& rhs) noexcept -{ - if (this != &rhs) { - TNode tmp = std::move(rhs); - Move(std::move(tmp)); +{ + if (this != &rhs) { + TNode tmp = std::move(rhs); + Move(std::move(tmp)); } - return *this; -} + return *this; +} -TNode::~TNode() = default; +TNode::~TNode() = default; -void TNode::Clear() -{ - ClearAttributes(); - Value_ = TUndefined(); -} +void TNode::Clear() +{ + ClearAttributes(); + Value_ = TUndefined(); +} -bool TNode::IsString() const -{ +bool TNode::IsString() const +{ return std::holds_alternative<TString>(Value_); -} - -bool TNode::IsInt64() const -{ +} + +bool TNode::IsInt64() const +{ return std::holds_alternative<i64>(Value_); -} +} -bool TNode::IsUint64() const -{ +bool TNode::IsUint64() const +{ return std::holds_alternative<ui64>(Value_); -} +} -bool TNode::IsDouble() const -{ +bool TNode::IsDouble() const +{ return std::holds_alternative<double>(Value_); -} +} -bool TNode::IsBool() const -{ +bool TNode::IsBool() const +{ return std::holds_alternative<bool>(Value_); -} +} -bool TNode::IsList() const -{ +bool TNode::IsList() const +{ return std::holds_alternative<TListType>(Value_); -} +} -bool TNode::IsMap() const -{ +bool TNode::IsMap() const +{ return std::holds_alternative<TMapType>(Value_); -} +} -bool TNode::IsEntity() const -{ - return IsNull(); -} +bool TNode::IsEntity() const +{ + return IsNull(); +} -bool TNode::IsNull() const -{ +bool TNode::IsNull() const +{ return std::holds_alternative<TNull>(Value_); -} - -bool TNode::IsUndefined() const -{ +} + +bool TNode::IsUndefined() const +{ return std::holds_alternative<TUndefined>(Value_); -} - +} + bool TNode::HasValue() const { return !IsNull() && !IsUndefined(); } -bool TNode::Empty() const -{ - switch (GetType()) { - case String: +bool TNode::Empty() const +{ + switch (GetType()) { + case String: return std::get<TString>(Value_).empty(); - case List: + case List: return std::get<TListType>(Value_).empty(); - case Map: + case Map: return std::get<TMapType>(Value_).empty(); - default: + default: ythrow TTypeError() << "Empty() called for type " << GetType(); } -} +} -size_t TNode::Size() const -{ - switch (GetType()) { - case String: +size_t TNode::Size() const +{ + switch (GetType()) { + case String: return std::get<TString>(Value_).size(); - case List: + case List: return std::get<TListType>(Value_).size(); - case Map: + case Map: return std::get<TMapType>(Value_).size(); - default: + default: ythrow TTypeError() << "Size() called for type " << GetType(); } -} +} -TNode::EType TNode::GetType() const -{ +TNode::EType TNode::GetType() const +{ return std::visit(TOverloaded{ [](const TUndefined&) { return Undefined; }, [](const TString&) { return String; }, @@ -290,61 +290,61 @@ TNode::EType TNode::GetType() const [](const TMapType&) { return Map; }, [](const TNull&) { return Null; } }, Value_); -} +} const TString& TNode::AsString() const -{ - CheckType(String); +{ + CheckType(String); return std::get<TString>(Value_); -} +} -i64 TNode::AsInt64() const -{ - CheckType(Int64); +i64 TNode::AsInt64() const +{ + CheckType(Int64); return std::get<i64>(Value_); -} +} -ui64 TNode::AsUint64() const -{ - CheckType(Uint64); +ui64 TNode::AsUint64() const +{ + CheckType(Uint64); return std::get<ui64>(Value_); -} +} -double TNode::AsDouble() const -{ - CheckType(Double); +double TNode::AsDouble() const +{ + CheckType(Double); return std::get<double>(Value_); -} +} -bool TNode::AsBool() const -{ - CheckType(Bool); +bool TNode::AsBool() const +{ + CheckType(Bool); return std::get<bool>(Value_); -} +} const TNode::TListType& TNode::AsList() const -{ - CheckType(List); +{ + CheckType(List); return std::get<TListType>(Value_); -} +} const TNode::TMapType& TNode::AsMap() const -{ - CheckType(Map); +{ + CheckType(Map); return std::get<TMapType>(Value_); -} +} TNode::TListType& TNode::AsList() -{ - CheckType(List); +{ + CheckType(List); return std::get<TListType>(Value_); -} +} TNode::TMapType& TNode::AsMap() -{ - CheckType(Map); +{ + CheckType(Map); return std::get<TMapType>(Value_); -} +} const TString& TNode::UncheckedAsString() const noexcept { @@ -391,52 +391,52 @@ TNode::TMapType& TNode::UncheckedAsMap() noexcept return std::get<TMapType>(Value_); } -TNode TNode::CreateList() -{ - TNode node; +TNode TNode::CreateList() +{ + TNode node; node.Value_ = TListType{}; - return node; -} - -TNode TNode::CreateList(TListType list) -{ - TNode node; - node.Value_ = std::move(list); - return node; -} - -TNode TNode::CreateMap() -{ - TNode node; + return node; +} + +TNode TNode::CreateList(TListType list) +{ + TNode node; + node.Value_ = std::move(list); + return node; +} + +TNode TNode::CreateMap() +{ + TNode node; node.Value_ = TMapType{}; - return node; -} - -TNode TNode::CreateMap(TMapType map) -{ - TNode node; - node.Value_ = std::move(map); - return node; -} - -TNode TNode::CreateEntity() -{ - TNode node; + return node; +} + +TNode TNode::CreateMap(TMapType map) +{ + TNode node; + node.Value_ = std::move(map); + return node; +} + +TNode TNode::CreateEntity() +{ + TNode node; node.Value_ = TNull{}; - return node; -} + return node; +} -const TNode& TNode::operator[](size_t index) const -{ - CheckType(List); +const TNode& TNode::operator[](size_t index) const +{ + CheckType(List); return std::get<TListType>(Value_)[index]; -} +} -TNode& TNode::operator[](size_t index) -{ - CheckType(List); +TNode& TNode::operator[](size_t index) +{ + CheckType(List); return std::get<TListType>(Value_)[index]; -} +} const TNode& TNode::At(size_t index) const { CheckType(List); @@ -457,88 +457,88 @@ TNode& TNode::At(size_t index) { } TNode& TNode::Add() & -{ - AssureList(); +{ + AssureList(); return std::get<TListType>(Value_).emplace_back(); -} +} TNode TNode::Add() && -{ +{ return std::move(Add()); } TNode& TNode::Add(const TNode& node) & { - AssureList(); + AssureList(); std::get<TListType>(Value_).emplace_back(node); - return *this; -} + return *this; +} TNode TNode::Add(const TNode& node) && -{ +{ return std::move(Add(node)); } TNode& TNode::Add(TNode&& node) & { - AssureList(); + AssureList(); std::get<TListType>(Value_).emplace_back(std::move(node)); - return *this; -} + return *this; +} TNode TNode::Add(TNode&& node) && { return std::move(Add(std::move(node))); } -bool TNode::HasKey(const TStringBuf key) const -{ - CheckType(Map); +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(); +{ + AssureMap(); std::get<TMapType>(Value_)[key] = value; - return *this; -} + return *this; +} TNode TNode::operator()(const TString& key, const TNode& value) && -{ +{ return std::move(operator()(key, value)); } TNode& TNode::operator()(const TString& key, TNode&& value) & { - AssureMap(); + AssureMap(); std::get<TMapType>(Value_)[key] = std::move(value); - return *this; -} + return *this; +} TNode TNode::operator()(const TString& key, TNode&& value) && { return std::move(operator()(key, std::move(value))); } -const TNode& TNode::operator[](const TStringBuf key) const -{ - CheckType(Map); - static TNode notFound; +const TNode& TNode::operator[](const TStringBuf key) const +{ + CheckType(Map); + static TNode notFound; const auto& map = std::get<TMapType>(Value_); TMapType::const_iterator i = map.find(key); - if (i == map.end()) { - return notFound; - } else { - return i->second; + if (i == map.end()) { + return notFound; + } else { + return i->second; } -} +} -TNode& TNode::operator[](const TStringBuf key) -{ - AssureMap(); +TNode& TNode::operator[](const TStringBuf key) +{ + AssureMap(); return std::get<TMapType>(Value_)[key]; -} +} const TNode& TNode::At(const TStringBuf key) const { CheckType(Map); @@ -778,101 +778,101 @@ TNode::TMapType& TNode::ChildAsMap(size_t index) { } } -bool TNode::HasAttributes() const -{ - return Attributes_ && !Attributes_->Empty(); -} +bool TNode::HasAttributes() const +{ + return Attributes_ && !Attributes_->Empty(); +} -void TNode::ClearAttributes() -{ - if (Attributes_) { - Attributes_.Destroy(); +void TNode::ClearAttributes() +{ + if (Attributes_) { + Attributes_.Destroy(); } -} +} -const TNode& TNode::GetAttributes() const -{ - static TNode notFound = TNode::CreateMap(); - if (!Attributes_) { - return notFound; +const TNode& TNode::GetAttributes() const +{ + static TNode notFound = TNode::CreateMap(); + if (!Attributes_) { + return notFound; } - return *Attributes_; -} + return *Attributes_; +} -TNode& TNode::Attributes() -{ - if (!Attributes_) { - CreateAttributes(); +TNode& TNode::Attributes() +{ + if (!Attributes_) { + CreateAttributes(); } - return *Attributes_; -} + return *Attributes_; +} -void TNode::MoveWithoutAttributes(TNode&& rhs) -{ - Value_ = std::move(rhs.Value_); - rhs.Clear(); -} +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::Move(TNode&& rhs) +{ + Value_ = std::move(rhs.Value_); + Attributes_ = std::move(rhs.Attributes_); +} -void TNode::CheckType(EType type) const -{ - Y_ENSURE_EX(GetType() == type, +void TNode::CheckType(EType type) const +{ + Y_ENSURE_EX(GetType() == type, TTypeError() << "TNode type " << type << " expected, actual type " << GetType(); - ); -} + ); +} -void TNode::AssureMap() -{ +void TNode::AssureMap() +{ if (std::holds_alternative<TUndefined>(Value_)) { Value_ = TMapType(); - } else { - CheckType(Map); + } else { + CheckType(Map); } -} +} -void TNode::AssureList() -{ +void TNode::AssureList() +{ if (std::holds_alternative<TUndefined>(Value_)) { Value_ = TListType(); - } else { - CheckType(List); + } else { + CheckType(List); } -} +} -void TNode::CreateAttributes() -{ +void TNode::CreateAttributes() +{ Attributes_ = MakeHolder<TNode>(); Attributes_->Value_ = TMapType(); -} +} void TNode::Save(IOutputStream* out) const -{ +{ NodeToYsonStream(*this, out, NYson::EYsonFormat::Binary); -} - +} + void TNode::Load(IInputStream* in) -{ - Clear(); +{ + Clear(); *this = NodeFromYsonStream(in, ::NYson::EYsonType::Node); -} +} + +//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// - -bool operator==(const TNode& lhs, const TNode& rhs) -{ +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; + // TODO: should try to remove this behaviour if nobody uses it. + return false; } - if (lhs.GetType() != rhs.GetType()) { + if (lhs.GetType() != rhs.GetType()) { return false; } @@ -890,15 +890,15 @@ bool operator==(const TNode& lhs, const TNode& rhs) } } - return rhs.Value_ == lhs.Value_; + return rhs.Value_ == lhs.Value_; } -bool operator!=(const TNode& lhs, const TNode& rhs) +bool operator!=(const TNode& lhs, const TNode& rhs) { return !(lhs == rhs); } -bool GetBool(const TNode& node) +bool GetBool(const TNode& node) { if (node.IsBool()) { return node.AsBool(); diff --git a/library/cpp/yson/node/node.h b/library/cpp/yson/node/node.h index 5f90f95df0..2fc3cb4213 100644 --- a/library/cpp/yson/node/node.h +++ b/library/cpp/yson/node/node.h @@ -1,9 +1,9 @@ #pragma once -#include <util/generic/bt_exception.h> +#include <util/generic/bt_exception.h> #include <util/generic/cast.h> #include <util/generic/hash.h> -#include <util/generic/variant.h> +#include <util/generic/variant.h> #include <util/generic/vector.h> #include <util/generic/yexception.h> #include <util/generic/ylimits.h> @@ -31,57 +31,57 @@ public: { }; enum EType { - Undefined = 0 /*"undefined"*/, - - // NOTE: string representation of all node types - // are compatible with server node type (except `Undefined' which is missing on server). - String = 1 /*"string_node"*/, - Int64 = 2 /*"int64_node"*/, - Uint64 = 3 /*"uint64_node"*/, - Double = 4 /*"double_node"*/, - Bool = 5 /*"boolean_node"*/, - List = 6 /*"list_node"*/, - Map = 7 /*"map_node"*/, - Null = 8 /*"null"*/, + Undefined = 0 /*"undefined"*/, + + // NOTE: string representation of all node types + // are compatible with server node type (except `Undefined' which is missing on server). + String = 1 /*"string_node"*/, + Int64 = 2 /*"int64_node"*/, + Uint64 = 3 /*"uint64_node"*/, + Double = 4 /*"double_node"*/, + Bool = 5 /*"boolean_node"*/, + List = 6 /*"list_node"*/, + Map = 7 /*"map_node"*/, + Null = 8 /*"null"*/, }; using TListType = TVector<TNode>; using TMapType = THashMap<TString, TNode>; -private: - struct TNull { - bool operator==(const TNull&) const; - }; +private: + struct TNull { + bool operator==(const TNull&) const; + }; - struct TUndefined { - bool operator==(const TUndefined&) const; - }; + struct TUndefined { + bool operator==(const TUndefined&) const; + }; using TValue = std::variant< - bool, - i64, - ui64, - double, + bool, + i64, + ui64, + double, TString, TListType, TMapType, - TNull, - TUndefined - >; + TNull, + TUndefined + >; -public: +public: - TNode(); - TNode(const char* s); + TNode(); + TNode(const char* s); TNode(TStringBuf s); explicit TNode(std::string_view s); explicit TNode(const std::string& s); TNode(TString s); - TNode(int i); + TNode(int i); //this case made speccially for prevent mess cast of EType into TNode through TNode(int) constructor - //usual case of error SomeNode == TNode::Undefined <-- SomeNode indeed will be compared with TNode(0) without this method - //correct way is SomeNode.GetType() == TNode::Undefined + //usual case of error SomeNode == TNode::Undefined <-- SomeNode indeed will be compared with TNode(0) without this method + //correct way is SomeNode.GetType() == TNode::Undefined template<class T = EType> Y_FORCE_INLINE TNode(EType) { @@ -94,37 +94,37 @@ public: static_assert(!std::is_same<T,T>::value, "looks like a mistake, and pointer have converted to bool"); } - TNode(unsigned int ui); - TNode(long i); - TNode(unsigned long ui); - TNode(long long i); - TNode(unsigned long long ui); - TNode(double d); - TNode(bool b); + TNode(unsigned int ui); + TNode(long i); + TNode(unsigned long ui); + TNode(long long i); + TNode(unsigned long long ui); + TNode(double d); + TNode(bool b); TNode(TMapType map); - TNode(const TNode& rhs); - TNode& operator=(const TNode& rhs); + TNode(const TNode& rhs); + TNode& operator=(const TNode& rhs); TNode(TNode&& rhs) noexcept; TNode& operator=(TNode&& rhs) noexcept; - ~TNode(); - - void Clear(); - - bool IsString() const; - bool IsInt64() const; - bool IsUint64() const; - bool IsDouble() const; - bool IsBool() const; - bool IsList() const; - bool IsMap() const; - - // `IsEntity' is deprecated use `IsNull' instead. - bool IsEntity() const; - bool IsNull() const; - bool IsUndefined() const; + ~TNode(); + + void Clear(); + + bool IsString() const; + bool IsInt64() const; + bool IsUint64() const; + bool IsDouble() const; + bool IsBool() const; + bool IsList() const; + bool IsMap() const; + + // `IsEntity' is deprecated use `IsNull' instead. + bool IsEntity() const; + bool IsNull() const; + bool IsUndefined() const; // Returns true if TNode is neither Null, nor Undefined bool HasValue() const; @@ -134,16 +134,16 @@ public: // Int64, Uint64, Double, or Bool bool IsArithmetic() const; - bool Empty() const; - size_t Size() const; + bool Empty() const; + size_t Size() const; - EType GetType() const; + EType GetType() const; const TString& AsString() const; - i64 AsInt64() const; - ui64 AsUint64() const; - double AsDouble() const; - bool AsBool() const; + i64 AsInt64() const; + ui64 AsUint64() const; + double AsDouble() const; + bool AsBool() const; const TListType& AsList() const; const TMapType& AsMap() const; TListType& AsList(); @@ -175,14 +175,14 @@ public: template<typename T> const T& As() const; - static TNode CreateList(); - static TNode CreateList(TListType list); - static TNode CreateMap(); - static TNode CreateMap(TMapType map); - static TNode CreateEntity(); + static TNode CreateList(); + static TNode CreateList(TListType list); + static TNode CreateMap(); + static TNode CreateMap(TMapType map); + static TNode CreateEntity(); - const TNode& operator[](size_t index) const; - TNode& operator[](size_t index); + const TNode& operator[](size_t index) const; + TNode& operator[](size_t index); const TNode& At(size_t index) const; TNode& At(size_t index); @@ -193,15 +193,15 @@ public: TNode& Add(TNode&& node) &; TNode Add(TNode&& node) &&; - bool HasKey(const TStringBuf key) const; - + bool HasKey(const TStringBuf key) const; + TNode& operator()(const TString& key, const TNode& value) &; TNode operator()(const TString& key, const TNode& value) &&; TNode& operator()(const TString& key, TNode&& value) &; TNode operator()(const TString& key, TNode&& value) &&; - const TNode& operator[](const TStringBuf key) const; - TNode& operator[](const TStringBuf key); + const TNode& operator[](const TStringBuf key) const; + TNode& operator[](const TStringBuf key); const TNode& At(const TStringBuf key) const; TNode& At(const TStringBuf key); @@ -255,40 +255,40 @@ public: // attributes - bool HasAttributes() const; - void ClearAttributes(); - const TNode& GetAttributes() const; - TNode& Attributes(); + bool HasAttributes() const; + void ClearAttributes(); + const TNode& GetAttributes() const; + TNode& Attributes(); - void MoveWithoutAttributes(TNode&& rhs); + void MoveWithoutAttributes(TNode&& rhs); - // Serialize TNode using binary yson format. - // Methods for ysaveload. + // Serialize TNode using binary yson format. + // Methods for ysaveload. void Save(IOutputStream* output) const; void Load(IInputStream* input); - + private: - void Move(TNode&& rhs); + void Move(TNode&& rhs); - void CheckType(EType type) const; + void CheckType(EType type) const; - void AssureMap(); - void AssureList(); + void AssureMap(); + void AssureList(); - void CreateAttributes(); + void CreateAttributes(); private: - TValue Value_; - THolder<TNode> Attributes_; + TValue Value_; + THolder<TNode> Attributes_; friend bool operator==(const TNode& lhs, const TNode& rhs); friend bool operator!=(const TNode& lhs, const TNode& rhs); }; -bool operator==(const TNode& lhs, const TNode& rhs); -bool operator!=(const TNode& lhs, const TNode& rhs); +bool operator==(const TNode& lhs, const TNode& rhs); +bool operator!=(const TNode& lhs, const TNode& rhs); -bool GetBool(const TNode& node); +bool GetBool(const TNode& node); inline bool TNode::IsArithmetic() const { return IsInt64() || IsUint64() || IsDouble() || IsBool(); @@ -344,20 +344,20 @@ inline T TNode::ConvertTo() const { template<> inline TString TNode::ConvertTo<TString>() const { switch (GetType()) { - case NYT::TNode::String: + case NYT::TNode::String: return AsString(); - case NYT::TNode::Int64: + case NYT::TNode::Int64: return ::ToString(AsInt64()); - case NYT::TNode::Uint64: + case NYT::TNode::Uint64: return ::ToString(AsUint64()); - case NYT::TNode::Double: + case NYT::TNode::Double: return ::ToString(AsDouble()); - case NYT::TNode::Bool: + case NYT::TNode::Bool: return ::ToString(AsBool()); - case NYT::TNode::List: - case NYT::TNode::Map: - case NYT::TNode::Null: - case NYT::TNode::Undefined: + case NYT::TNode::List: + case NYT::TNode::Map: + case NYT::TNode::Null: + case NYT::TNode::Undefined: ythrow TTypeError() << "ConvertTo<TString>() called for type " << GetType(); } Y_UNREACHABLE(); @@ -366,20 +366,20 @@ inline TString TNode::ConvertTo<TString>() const { template<> inline double TNode::ConvertTo<double>() const { switch (GetType()) { - case NYT::TNode::String: + case NYT::TNode::String: return ::FromString(AsString()); - case NYT::TNode::Int64: + case NYT::TNode::Int64: return AsInt64(); - case NYT::TNode::Uint64: + case NYT::TNode::Uint64: return AsUint64(); - case NYT::TNode::Double: + case NYT::TNode::Double: return AsDouble(); - case NYT::TNode::Bool: + case NYT::TNode::Bool: return AsBool(); - case NYT::TNode::List: - case NYT::TNode::Map: - case NYT::TNode::Null: - case NYT::TNode::Undefined: + case NYT::TNode::List: + case NYT::TNode::Map: + case NYT::TNode::Null: + case NYT::TNode::Undefined: ythrow TTypeError() << "ConvertTo<double>() called for type " << GetType(); } } @@ -387,20 +387,20 @@ inline double TNode::ConvertTo<double>() const { template<> inline bool TNode::ConvertTo<bool>() const { switch (GetType()) { - case NYT::TNode::String: + case NYT::TNode::String: return ::FromString(AsString()); - case NYT::TNode::Int64: + case NYT::TNode::Int64: return AsInt64(); - case NYT::TNode::Uint64: + case NYT::TNode::Uint64: return AsUint64(); - case NYT::TNode::Double: + case NYT::TNode::Double: return AsDouble(); - case NYT::TNode::Bool: + case NYT::TNode::Bool: return AsBool(); - case NYT::TNode::List: - case NYT::TNode::Map: - case NYT::TNode::Null: - case NYT::TNode::Undefined: + case NYT::TNode::List: + case NYT::TNode::Map: + case NYT::TNode::Null: + case NYT::TNode::Undefined: ythrow TTypeError() << "ConvertTo<bool>() called for type " << GetType(); } } diff --git a/library/cpp/yson/node/node_builder.h b/library/cpp/yson/node/node_builder.h index 69800016e0..8e0dd57fc1 100644 --- a/library/cpp/yson/node/node_builder.h +++ b/library/cpp/yson/node/node_builder.h @@ -1,10 +1,10 @@ #pragma once -#include "node.h" +#include "node.h" #include <library/cpp/json/json_reader.h> -#include <library/cpp/yson/consumer.h> +#include <library/cpp/yson/consumer.h> #include <util/generic/stack.h> @@ -13,7 +13,7 @@ namespace NYT { //////////////////////////////////////////////////////////////////////////////// class TNodeBuilder - : public ::NYson::TYsonConsumerBase + : public ::NYson::TYsonConsumerBase { public: TNodeBuilder(TNode* node); diff --git a/library/cpp/yson/node/node_io.cpp b/library/cpp/yson/node/node_io.cpp index 294a7f7217..2d8c4f3c5a 100644 --- a/library/cpp/yson/node/node_io.cpp +++ b/library/cpp/yson/node/node_io.cpp @@ -1,12 +1,12 @@ -#include "node_io.h" +#include "node_io.h" #include "node_builder.h" #include "node_visitor.h" -#include <library/cpp/yson/json/json_writer.h> -#include <library/cpp/yson/parser.h> -#include <library/cpp/yson/writer.h> -#include <library/cpp/yson/json/yson2json_adapter.h> +#include <library/cpp/yson/json/json_writer.h> +#include <library/cpp/yson/parser.h> +#include <library/cpp/yson/writer.h> +#include <library/cpp/yson/json/yson2json_adapter.h> #include <library/cpp/json/json_reader.h> #include <library/cpp/json/json_value.h> @@ -18,56 +18,56 @@ namespace NYT { -static void WalkJsonTree(const NJson::TJsonValue& jsonValue, NJson::TJsonCallbacks* callbacks) -{ - using namespace NJson; - switch (jsonValue.GetType()) { - case JSON_NULL: - callbacks->OnNull(); - return; - case JSON_BOOLEAN: - callbacks->OnBoolean(jsonValue.GetBoolean()); - return; - case JSON_INTEGER: - callbacks->OnInteger(jsonValue.GetInteger()); - return; - case JSON_UINTEGER: - callbacks->OnUInteger(jsonValue.GetUInteger()); - return; - case JSON_DOUBLE: - callbacks->OnDouble(jsonValue.GetDouble()); - return; - case JSON_STRING: - callbacks->OnString(jsonValue.GetString()); - return; - case JSON_MAP: - { - callbacks->OnOpenMap(); - for (const auto& item : jsonValue.GetMap()) { - callbacks->OnMapKey(item.first); - WalkJsonTree(item.second, callbacks); - } - callbacks->OnCloseMap(); - } - return; - case JSON_ARRAY: - { - callbacks->OnOpenArray(); - for (const auto& item : jsonValue.GetArray()) { - WalkJsonTree(item, callbacks); - } - callbacks->OnCloseArray(); - } - return; - case JSON_UNDEFINED: - ythrow yexception() << "cannot consume undefined json value"; - return; - } - Y_UNREACHABLE(); -} - +static void WalkJsonTree(const NJson::TJsonValue& jsonValue, NJson::TJsonCallbacks* callbacks) +{ + using namespace NJson; + switch (jsonValue.GetType()) { + case JSON_NULL: + callbacks->OnNull(); + return; + case JSON_BOOLEAN: + callbacks->OnBoolean(jsonValue.GetBoolean()); + return; + case JSON_INTEGER: + callbacks->OnInteger(jsonValue.GetInteger()); + return; + case JSON_UINTEGER: + callbacks->OnUInteger(jsonValue.GetUInteger()); + return; + case JSON_DOUBLE: + callbacks->OnDouble(jsonValue.GetDouble()); + return; + case JSON_STRING: + callbacks->OnString(jsonValue.GetString()); + return; + case JSON_MAP: + { + callbacks->OnOpenMap(); + for (const auto& item : jsonValue.GetMap()) { + callbacks->OnMapKey(item.first); + WalkJsonTree(item.second, callbacks); + } + callbacks->OnCloseMap(); + } + return; + case JSON_ARRAY: + { + callbacks->OnOpenArray(); + for (const auto& item : jsonValue.GetArray()) { + WalkJsonTree(item, callbacks); + } + callbacks->OnCloseArray(); + } + return; + case JSON_UNDEFINED: + ythrow yexception() << "cannot consume undefined json value"; + return; + } + Y_UNREACHABLE(); +} + static TNode CreateEmptyNodeByType(::NYson::EYsonType type) -{ +{ TNode result; switch (type) { case ::NYson::EYsonType::ListFragment: @@ -85,16 +85,16 @@ static TNode CreateEmptyNodeByType(::NYson::EYsonType type) TNode NodeFromYsonString(const TStringBuf input, ::NYson::EYsonType type) { TMemoryInput stream(input); - return NodeFromYsonStream(&stream, type); -} + return NodeFromYsonStream(&stream, type); +} TString NodeToYsonString(const TNode& node, NYson::EYsonFormat format) -{ - TStringStream stream; - NodeToYsonStream(node, &stream, format); - return stream.Str(); -} - +{ + TStringStream stream; + NodeToYsonStream(node, &stream, format); + return stream.Str(); +} + TString NodeToCanonicalYsonString(const TNode& node, NYson::EYsonFormat format) { TStringStream stream; @@ -103,7 +103,7 @@ TString NodeToCanonicalYsonString(const TNode& node, NYson::EYsonFormat format) } TNode NodeFromYsonStream(IInputStream* input, ::NYson::EYsonType type) -{ +{ TNode result = CreateEmptyNodeByType(type); TNodeBuilder builder(&result); @@ -127,10 +127,10 @@ void NodeToCanonicalYsonStream(const TNode& node, IOutputStream* output, NYson:: } TNode NodeFromJsonString(const TStringBuf input) -{ +{ TMemoryInput stream(input); - TNode result; + TNode result; TNodeBuilder builder(&result); TYson2JsonCallbacksAdapter callbacks(&builder, /*throwException*/ true); @@ -140,15 +140,15 @@ TNode NodeFromJsonString(const TStringBuf input) return result; } -TNode NodeFromJsonValue(const NJson::TJsonValue& input) -{ - TNode result; - TNodeBuilder builder(&result); - TYson2JsonCallbacksAdapter callbacks(&builder, /*throwException*/ true); - WalkJsonTree(input, &callbacks); - return result; -} - +TNode NodeFromJsonValue(const NJson::TJsonValue& input) +{ + TNode result; + TNodeBuilder builder(&result); + TYson2JsonCallbacksAdapter callbacks(&builder, /*throwException*/ true); + WalkJsonTree(input, &callbacks); + return result; +} + //////////////////////////////////////////////////////////////////////////////// } // namespace NYT diff --git a/library/cpp/yson/node/node_io.h b/library/cpp/yson/node/node_io.h index 2ad23b658f..1fb4ead92f 100644 --- a/library/cpp/yson/node/node_io.h +++ b/library/cpp/yson/node/node_io.h @@ -1,12 +1,12 @@ #pragma once -#include "node.h" -#include <library/cpp/yson/public.h> - -namespace NJson { - class TJsonValue; -} // namespace NJson +#include "node.h" +#include <library/cpp/yson/public.h> +namespace NJson { + class TJsonValue; +} // namespace NJson + namespace NYT { //////////////////////////////////////////////////////////////////////////////// @@ -25,7 +25,7 @@ TNode NodeFromYsonStream(IInputStream* input, ::NYson::EYsonType type = ::NYson: // Serialize TNode to stream in one of YSON formats with random order of maps' keys (don't use in tests) void NodeToYsonStream(const TNode& node, IOutputStream* output, ::NYson::EYsonFormat format = ::NYson::EYsonFormat::Text); - + // Same as the latter, but maps' keys are sorted lexicographically (to be used in tests) void NodeToCanonicalYsonStream(const TNode& node, IOutputStream* output, ::NYson::EYsonFormat format = ::NYson::EYsonFormat::Text); @@ -33,7 +33,7 @@ void NodeToCanonicalYsonStream(const TNode& node, IOutputStream* output, ::NYson TNode NodeFromJsonString(const TStringBuf input); // Convert TJsonValue to TNode -TNode NodeFromJsonValue(const NJson::TJsonValue& input); +TNode NodeFromJsonValue(const NJson::TJsonValue& input); //////////////////////////////////////////////////////////////////////////////// diff --git a/library/cpp/yson/node/node_ut.cpp b/library/cpp/yson/node/node_ut.cpp index 448e99f575..4728ce3c35 100644 --- a/library/cpp/yson/node/node_ut.cpp +++ b/library/cpp/yson/node/node_ut.cpp @@ -1,55 +1,55 @@ -#include "node.h" -#include "node_io.h" - +#include "node.h" +#include "node_io.h" + #include <library/cpp/testing/unittest/registar.h> - -#include <util/ysaveload.h> - -using namespace NYT; - -template<> + +#include <util/ysaveload.h> + +using namespace NYT; + +template<> void Out<NYT::TNode>(IOutputStream& s, const NYT::TNode& node) -{ - s << "TNode:" << NodeToYsonString(node); -} - +{ + s << "TNode:" << NodeToYsonString(node); +} + Y_UNIT_TEST_SUITE(YtNodeTest) { Y_UNIT_TEST(TestConstsructors) { - TNode nodeEmpty; - UNIT_ASSERT_EQUAL(nodeEmpty.GetType(), TNode::Undefined); - - TNode nodeString("foobar"); - UNIT_ASSERT_EQUAL(nodeString.GetType(), TNode::String); - UNIT_ASSERT(nodeString.IsString()); - UNIT_ASSERT_VALUES_EQUAL(nodeString.AsString(), "foobar"); - - TNode nodeInt(int(54)); - UNIT_ASSERT_EQUAL(nodeInt.GetType(), TNode::Int64); - UNIT_ASSERT(nodeInt.IsInt64()); - UNIT_ASSERT(!nodeInt.IsUint64()); - UNIT_ASSERT_VALUES_EQUAL(nodeInt.AsInt64(), 54ull); - - TNode nodeUint(ui64(42)); - UNIT_ASSERT_EQUAL(nodeUint.GetType(), TNode::Uint64); - UNIT_ASSERT(nodeUint.IsUint64()); - UNIT_ASSERT(!nodeUint.IsInt64()); - UNIT_ASSERT_VALUES_EQUAL(nodeUint.AsUint64(), 42ull); - - TNode nodeDouble(double(2.3)); - UNIT_ASSERT_EQUAL(nodeDouble.GetType(), TNode::Double); - UNIT_ASSERT(nodeDouble.IsDouble()); - UNIT_ASSERT_VALUES_EQUAL(nodeDouble.AsDouble(), double(2.3)); - - TNode nodeBool(true); - UNIT_ASSERT_EQUAL(nodeBool.GetType(), TNode::Bool); - UNIT_ASSERT(nodeBool.IsBool()); - UNIT_ASSERT_VALUES_EQUAL(nodeBool.AsBool(), true); - - TNode nodeEntity = TNode::CreateEntity(); - UNIT_ASSERT_EQUAL(nodeEntity.GetType(), TNode::Null); - UNIT_ASSERT(nodeEntity.IsEntity()); - } - + TNode nodeEmpty; + UNIT_ASSERT_EQUAL(nodeEmpty.GetType(), TNode::Undefined); + + TNode nodeString("foobar"); + UNIT_ASSERT_EQUAL(nodeString.GetType(), TNode::String); + UNIT_ASSERT(nodeString.IsString()); + UNIT_ASSERT_VALUES_EQUAL(nodeString.AsString(), "foobar"); + + TNode nodeInt(int(54)); + UNIT_ASSERT_EQUAL(nodeInt.GetType(), TNode::Int64); + UNIT_ASSERT(nodeInt.IsInt64()); + UNIT_ASSERT(!nodeInt.IsUint64()); + UNIT_ASSERT_VALUES_EQUAL(nodeInt.AsInt64(), 54ull); + + TNode nodeUint(ui64(42)); + UNIT_ASSERT_EQUAL(nodeUint.GetType(), TNode::Uint64); + UNIT_ASSERT(nodeUint.IsUint64()); + UNIT_ASSERT(!nodeUint.IsInt64()); + UNIT_ASSERT_VALUES_EQUAL(nodeUint.AsUint64(), 42ull); + + TNode nodeDouble(double(2.3)); + UNIT_ASSERT_EQUAL(nodeDouble.GetType(), TNode::Double); + UNIT_ASSERT(nodeDouble.IsDouble()); + UNIT_ASSERT_VALUES_EQUAL(nodeDouble.AsDouble(), double(2.3)); + + TNode nodeBool(true); + UNIT_ASSERT_EQUAL(nodeBool.GetType(), TNode::Bool); + UNIT_ASSERT(nodeBool.IsBool()); + UNIT_ASSERT_VALUES_EQUAL(nodeBool.AsBool(), true); + + TNode nodeEntity = TNode::CreateEntity(); + UNIT_ASSERT_EQUAL(nodeEntity.GetType(), TNode::Null); + UNIT_ASSERT(nodeEntity.IsEntity()); + } + Y_UNIT_TEST(TestPredicates) { const TNode undefinedNode; UNIT_ASSERT(undefinedNode.IsUndefined()); @@ -72,62 +72,62 @@ Y_UNIT_TEST_SUITE(YtNodeTest) { UNIT_ASSERT(stringNode.HasValue()); } - Y_UNIT_TEST(TestComplexConstructors) { - const TNode listNode = TNode::CreateList({"one", 2, "tree"}); - const auto expectedListValue = std::vector<TNode>({"one", 2, "tree"}); - UNIT_ASSERT_VALUES_EQUAL(listNode.AsList(), expectedListValue); - - const TNode mapNode = TNode::CreateMap({{"one", 1}, {"two", 2u}}); - const auto expectedMapValue = THashMap<TString, TNode>({{"one", 1}, {"two", 2u}}); - UNIT_ASSERT_VALUES_EQUAL(mapNode.AsMap(), expectedMapValue); - } - + Y_UNIT_TEST(TestComplexConstructors) { + const TNode listNode = TNode::CreateList({"one", 2, "tree"}); + const auto expectedListValue = std::vector<TNode>({"one", 2, "tree"}); + UNIT_ASSERT_VALUES_EQUAL(listNode.AsList(), expectedListValue); + + const TNode mapNode = TNode::CreateMap({{"one", 1}, {"two", 2u}}); + const auto expectedMapValue = THashMap<TString, TNode>({{"one", 1}, {"two", 2u}}); + UNIT_ASSERT_VALUES_EQUAL(mapNode.AsMap(), expectedMapValue); + } + Y_UNIT_TEST(TestNodeMap) { - TNode nodeMap = TNode()("foo", "bar")("bar", "baz"); - UNIT_ASSERT(nodeMap.IsMap()); - UNIT_ASSERT_EQUAL(nodeMap.GetType(), TNode::Map); - UNIT_ASSERT_VALUES_EQUAL(nodeMap.Size(), 2); - - UNIT_ASSERT(nodeMap.HasKey("foo")); - UNIT_ASSERT(!nodeMap.HasKey("42")); - UNIT_ASSERT_EQUAL(nodeMap["foo"], TNode("bar")); - UNIT_ASSERT_EQUAL(nodeMap["bar"], TNode("baz")); - - // const version of operator[] - UNIT_ASSERT_EQUAL(static_cast<const TNode&>(nodeMap)["42"].GetType(), TNode::Undefined); - UNIT_ASSERT(!nodeMap.HasKey("42")); - - // nonconst version of operator[] - UNIT_ASSERT_EQUAL(nodeMap["42"].GetType(), TNode::Undefined); - UNIT_ASSERT(nodeMap.HasKey("42")); - - nodeMap("rock!!!", TNode() - ("Pink", "Floyd") - ("Purple", "Deep")); - - TNode copyNode; - copyNode = nodeMap; - UNIT_ASSERT_EQUAL(copyNode["foo"], TNode("bar")); - UNIT_ASSERT_EQUAL(copyNode["bar"], TNode("baz")); - UNIT_ASSERT(copyNode["42"].GetType() == TNode::Undefined); - UNIT_ASSERT_EQUAL(copyNode["rock!!!"]["Purple"], TNode("Deep")); - } - + TNode nodeMap = TNode()("foo", "bar")("bar", "baz"); + UNIT_ASSERT(nodeMap.IsMap()); + UNIT_ASSERT_EQUAL(nodeMap.GetType(), TNode::Map); + UNIT_ASSERT_VALUES_EQUAL(nodeMap.Size(), 2); + + UNIT_ASSERT(nodeMap.HasKey("foo")); + UNIT_ASSERT(!nodeMap.HasKey("42")); + UNIT_ASSERT_EQUAL(nodeMap["foo"], TNode("bar")); + UNIT_ASSERT_EQUAL(nodeMap["bar"], TNode("baz")); + + // const version of operator[] + UNIT_ASSERT_EQUAL(static_cast<const TNode&>(nodeMap)["42"].GetType(), TNode::Undefined); + UNIT_ASSERT(!nodeMap.HasKey("42")); + + // nonconst version of operator[] + UNIT_ASSERT_EQUAL(nodeMap["42"].GetType(), TNode::Undefined); + UNIT_ASSERT(nodeMap.HasKey("42")); + + nodeMap("rock!!!", TNode() + ("Pink", "Floyd") + ("Purple", "Deep")); + + TNode copyNode; + copyNode = nodeMap; + UNIT_ASSERT_EQUAL(copyNode["foo"], TNode("bar")); + UNIT_ASSERT_EQUAL(copyNode["bar"], TNode("baz")); + UNIT_ASSERT(copyNode["42"].GetType() == TNode::Undefined); + UNIT_ASSERT_EQUAL(copyNode["rock!!!"]["Purple"], TNode("Deep")); + } + Y_UNIT_TEST(TestNodeList) { - TNode nodeList = TNode().Add("foo").Add(42).Add(3.14); - UNIT_ASSERT(nodeList.IsList()); - UNIT_ASSERT_EQUAL(nodeList.GetType(), TNode::List); - UNIT_ASSERT_VALUES_EQUAL(nodeList.Size(), 3); - - UNIT_ASSERT_EQUAL(nodeList[1], TNode(42)); - nodeList.Add(TNode().Add("ls").Add("pwd")); - - TNode copyNode; - copyNode = nodeList; - UNIT_ASSERT_EQUAL(copyNode[0], TNode("foo")); - UNIT_ASSERT_EQUAL(copyNode[3][1], TNode("pwd")); - } - + TNode nodeList = TNode().Add("foo").Add(42).Add(3.14); + UNIT_ASSERT(nodeList.IsList()); + UNIT_ASSERT_EQUAL(nodeList.GetType(), TNode::List); + UNIT_ASSERT_VALUES_EQUAL(nodeList.Size(), 3); + + UNIT_ASSERT_EQUAL(nodeList[1], TNode(42)); + nodeList.Add(TNode().Add("ls").Add("pwd")); + + TNode copyNode; + copyNode = nodeList; + UNIT_ASSERT_EQUAL(copyNode[0], TNode("foo")); + UNIT_ASSERT_EQUAL(copyNode[3][1], TNode("pwd")); + } + Y_UNIT_TEST(TestInsertingMethodsFromTemporaryObjects) { // check that .Add(...) doesn't return lvalue reference to temporary object { @@ -143,59 +143,59 @@ Y_UNIT_TEST_SUITE(YtNodeTest) { } Y_UNIT_TEST(TestAttributes) { - TNode node = TNode()("lee", 42)("faa", 54); - UNIT_ASSERT(!node.HasAttributes()); - node.Attributes()("foo", true)("bar", false); - UNIT_ASSERT(node.HasAttributes()); - - { - TNode copyNode; - UNIT_ASSERT(!copyNode.HasAttributes()); - copyNode = node; - UNIT_ASSERT(copyNode.HasAttributes()); - UNIT_ASSERT_EQUAL(copyNode.GetAttributes()["foo"], TNode(true)); - } - - { - TNode movedWithoutAttributes(42); - movedWithoutAttributes.Attributes()("one", 1)("two", 2); - movedWithoutAttributes.MoveWithoutAttributes(TNode(node)); - UNIT_ASSERT(movedWithoutAttributes.IsMap()); - UNIT_ASSERT_EQUAL(movedWithoutAttributes["lee"], TNode(42)); - UNIT_ASSERT_EQUAL(movedWithoutAttributes.GetAttributes()["one"], TNode(1)); - UNIT_ASSERT(!movedWithoutAttributes.GetAttributes().HasKey("foo")); - } - - { - TNode copyNode = node; - UNIT_ASSERT(copyNode.HasAttributes()); - UNIT_ASSERT(copyNode.GetAttributes().HasKey("foo")); - copyNode.ClearAttributes(); - UNIT_ASSERT(!copyNode.HasAttributes()); - UNIT_ASSERT(!copyNode.GetAttributes().HasKey("foo")); - } - - { - TNode copyNode = node; - UNIT_ASSERT(copyNode.HasAttributes()); - UNIT_ASSERT(copyNode.GetAttributes().HasKey("foo")); - copyNode.Clear(); - UNIT_ASSERT(!copyNode.HasAttributes()); - UNIT_ASSERT(!copyNode.GetAttributes().HasKey("foo")); - } - } - + TNode node = TNode()("lee", 42)("faa", 54); + UNIT_ASSERT(!node.HasAttributes()); + node.Attributes()("foo", true)("bar", false); + UNIT_ASSERT(node.HasAttributes()); + + { + TNode copyNode; + UNIT_ASSERT(!copyNode.HasAttributes()); + copyNode = node; + UNIT_ASSERT(copyNode.HasAttributes()); + UNIT_ASSERT_EQUAL(copyNode.GetAttributes()["foo"], TNode(true)); + } + + { + TNode movedWithoutAttributes(42); + movedWithoutAttributes.Attributes()("one", 1)("two", 2); + movedWithoutAttributes.MoveWithoutAttributes(TNode(node)); + UNIT_ASSERT(movedWithoutAttributes.IsMap()); + UNIT_ASSERT_EQUAL(movedWithoutAttributes["lee"], TNode(42)); + UNIT_ASSERT_EQUAL(movedWithoutAttributes.GetAttributes()["one"], TNode(1)); + UNIT_ASSERT(!movedWithoutAttributes.GetAttributes().HasKey("foo")); + } + + { + TNode copyNode = node; + UNIT_ASSERT(copyNode.HasAttributes()); + UNIT_ASSERT(copyNode.GetAttributes().HasKey("foo")); + copyNode.ClearAttributes(); + UNIT_ASSERT(!copyNode.HasAttributes()); + UNIT_ASSERT(!copyNode.GetAttributes().HasKey("foo")); + } + + { + TNode copyNode = node; + UNIT_ASSERT(copyNode.HasAttributes()); + UNIT_ASSERT(copyNode.GetAttributes().HasKey("foo")); + copyNode.Clear(); + UNIT_ASSERT(!copyNode.HasAttributes()); + UNIT_ASSERT(!copyNode.GetAttributes().HasKey("foo")); + } + } + Y_UNIT_TEST(TestEq) { - TNode nodeNoAttributes = TNode()("lee", 42)("faa", 54); - TNode node = nodeNoAttributes; - node.Attributes()("foo", true)("bar", false); - UNIT_ASSERT(node != nodeNoAttributes); - UNIT_ASSERT(nodeNoAttributes != node); - TNode copyNode = node; - UNIT_ASSERT(copyNode == node); - UNIT_ASSERT(node == copyNode); - } - + TNode nodeNoAttributes = TNode()("lee", 42)("faa", 54); + TNode node = nodeNoAttributes; + node.Attributes()("foo", true)("bar", false); + UNIT_ASSERT(node != nodeNoAttributes); + UNIT_ASSERT(nodeNoAttributes != node); + TNode copyNode = node; + UNIT_ASSERT(copyNode == node); + UNIT_ASSERT(node == copyNode); + } + Y_UNIT_TEST(TestComparison) { using namespace NYT::NNodeCmp; { @@ -261,23 +261,23 @@ Y_UNIT_TEST_SUITE(YtNodeTest) { } Y_UNIT_TEST(TestSaveLoad) { - TNode node = TNode()("foo", "bar")("baz", 42); - node.Attributes()["attr_name"] = "attr_value"; - - TString bytes; - { - TStringOutput s(bytes); - ::Save(&s, node); - } - - TNode nodeCopy; - { - TStringInput s(bytes); - ::Load(&s, nodeCopy); - } - - UNIT_ASSERT_VALUES_EQUAL(node, nodeCopy); - } + TNode node = TNode()("foo", "bar")("baz", 42); + node.Attributes()["attr_name"] = "attr_value"; + + TString bytes; + { + TStringOutput s(bytes); + ::Save(&s, node); + } + + TNode nodeCopy; + { + TStringInput s(bytes); + ::Load(&s, nodeCopy); + } + + UNIT_ASSERT_VALUES_EQUAL(node, nodeCopy); + } Y_UNIT_TEST(TestIntCast) { TNode node = 1ull << 31; @@ -381,7 +381,7 @@ Y_UNIT_TEST_SUITE(YtNodeTest) { UNIT_ASSERT_VALUES_EQUAL(TNode(0).ConvertTo<bool>(), false); UNIT_ASSERT_EXCEPTION(TNode("random").ConvertTo<bool>(), TFromStringException); UNIT_ASSERT_EXCEPTION(TNode("").ConvertTo<bool>(), TFromStringException); - } + } Y_UNIT_TEST(TestCanonicalSerialization) { auto node = TNode() @@ -396,16 +396,16 @@ Y_UNIT_TEST_SUITE(YtNodeTest) { "\"c\"=\"c\";\"ca\"=\"ca\"}"); } - Y_UNIT_TEST(OperatorEqualSubnode) { - TNode node; - node["a"]["b"] = "c"; - - node = node["a"]; - node = node["b"]; - - UNIT_ASSERT_VALUES_EQUAL(node.AsString(), "c"); - } - + Y_UNIT_TEST(OperatorEqualSubnode) { + TNode node; + node["a"]["b"] = "c"; + + node = node["a"]; + node = node["b"]; + + UNIT_ASSERT_VALUES_EQUAL(node.AsString(), "c"); + } + Y_UNIT_TEST(TestMapGetters) { auto node = TNode::CreateMap() ("string", "7") @@ -481,4 +481,4 @@ Y_UNIT_TEST_SUITE(YtNodeTest) { childString = "yaddayadda"; UNIT_ASSERT_VALUES_EQUAL(node.ChildAs<TString>(0), "yaddayadda"); } -} +} diff --git a/library/cpp/yson/node/node_visitor.cpp b/library/cpp/yson/node/node_visitor.cpp index 899fbfa02a..c56c4829cb 100644 --- a/library/cpp/yson/node/node_visitor.cpp +++ b/library/cpp/yson/node/node_visitor.cpp @@ -1,8 +1,8 @@ #include "node_visitor.h" #include <util/generic/algorithm.h> -#include <util/string/printf.h> - +#include <util/string/printf.h> + namespace NYT { //////////////////////////////////////////////////////////////////////////////// @@ -30,7 +30,7 @@ void Iterate(const TNode::TMapType& nodeMap, bool sortByKey, Fun action) //////////////////////////////////////////////////////////////////////////////// -TNodeVisitor::TNodeVisitor(NYson::IYsonConsumer* consumer, bool sortMapKeys) +TNodeVisitor::TNodeVisitor(NYson::IYsonConsumer* consumer, bool sortMapKeys) : Consumer_(consumer) , SortMapKeys_(sortMapKeys) { } @@ -46,44 +46,44 @@ void TNodeVisitor::VisitAny(const TNode& node) Consumer_->OnBeginAttributes(); Iterate(node.GetAttributes().AsMap(), SortMapKeys_, [&](const std::pair<TString, TNode>& item) { Consumer_->OnKeyedItem(item.first); - if (item.second.IsUndefined()) { + if (item.second.IsUndefined()) { ythrow TNode::TTypeError() << "unable to visit attribute value of type " << TNode::EType::Undefined << "; attribute name: `" << item.first << '\'' ; - } + } VisitAny(item.second); }); Consumer_->OnEndAttributes(); } switch (node.GetType()) { - case TNode::String: + case TNode::String: VisitString(node); break; - case TNode::Int64: + case TNode::Int64: VisitInt64(node); break; - case TNode::Uint64: + case TNode::Uint64: VisitUint64(node); break; - case TNode::Double: + case TNode::Double: VisitDouble(node); break; - case TNode::Bool: + case TNode::Bool: VisitBool(node); break; - case TNode::List: - VisitList(node.AsList()); + case TNode::List: + VisitList(node.AsList()); break; - case TNode::Map: - VisitMap(node.AsMap()); + case TNode::Map: + VisitMap(node.AsMap()); break; - case TNode::Null: + case TNode::Null: VisitEntity(); break; - case TNode::Undefined: + case TNode::Undefined: ythrow TNode::TTypeError() << "unable to visit TNode of type " << node.GetType(); - default: - Y_FAIL("Unexpected type: %d", node.GetType()); + default: + Y_FAIL("Unexpected type: %d", node.GetType()); } } @@ -115,15 +115,15 @@ void TNodeVisitor::VisitBool(const TNode& node) void TNodeVisitor::VisitList(const TNode::TListType& nodeList) { Consumer_->OnBeginList(); - size_t index = 0; - for (const auto& item : nodeList) { + size_t index = 0; + for (const auto& item : nodeList) { Consumer_->OnListItem(); - if (item.IsUndefined()) { + if (item.IsUndefined()) { ythrow TNode::TTypeError() << "unable to visit list node child of type " << TNode::EType::Undefined << "; list index: " << index; - } + } VisitAny(item); - ++index; + ++index; } Consumer_->OnEndList(); } @@ -133,10 +133,10 @@ void TNodeVisitor::VisitMap(const TNode::TMapType& nodeMap) Consumer_->OnBeginMap(); Iterate(nodeMap, SortMapKeys_, [&](const std::pair<TString, TNode>& item) { Consumer_->OnKeyedItem(item.first); - if (item.second.IsUndefined()) { + if (item.second.IsUndefined()) { ythrow TNode::TTypeError() << "unable to visit map node child of type " << TNode::EType::Undefined << "; map key: `" << item.first << '\'' ; - } + } VisitAny(item.second); }); Consumer_->OnEndMap(); diff --git a/library/cpp/yson/node/node_visitor.h b/library/cpp/yson/node/node_visitor.h index db25832309..4c0d6347a7 100644 --- a/library/cpp/yson/node/node_visitor.h +++ b/library/cpp/yson/node/node_visitor.h @@ -1,8 +1,8 @@ #pragma once -#include "node.h" - -#include <library/cpp/yson/consumer.h> +#include "node.h" + +#include <library/cpp/yson/consumer.h> namespace NYT { diff --git a/library/cpp/yson/node/pybind/node.cpp b/library/cpp/yson/node/pybind/node.cpp index 79beba3647..70731409dd 100644 --- a/library/cpp/yson/node/pybind/node.cpp +++ b/library/cpp/yson/node/pybind/node.cpp @@ -1,6 +1,6 @@ #include "node.h" -#include <library/cpp/yson/node/node.h> +#include <library/cpp/yson/node/node.h> #include <library/cpp/pybind/cast.h> diff --git a/library/cpp/yson/node/pybind/node.h b/library/cpp/yson/node/pybind/node.h index 65f7236de6..25bf736ff0 100644 --- a/library/cpp/yson/node/pybind/node.h +++ b/library/cpp/yson/node/pybind/node.h @@ -2,7 +2,7 @@ #include <Python.h> -#include <library/cpp/yson/node/node.h> +#include <library/cpp/yson/node/node.h> namespace NYT { PyObject* BuildPyObject(const TNode& val); diff --git a/library/cpp/yson/node/pybind/ya.make b/library/cpp/yson/node/pybind/ya.make index 97b7583e96..938472dcf7 100644 --- a/library/cpp/yson/node/pybind/ya.make +++ b/library/cpp/yson/node/pybind/ya.make @@ -7,7 +7,7 @@ OWNER( PEERDIR( library/cpp/pybind - library/cpp/yson/node + library/cpp/yson/node ) SRCS( node.cpp diff --git a/library/cpp/yson/node/serialize.cpp b/library/cpp/yson/node/serialize.cpp index aeb467622b..d204e03e0e 100644 --- a/library/cpp/yson/node/serialize.cpp +++ b/library/cpp/yson/node/serialize.cpp @@ -2,7 +2,7 @@ #include "node_visitor.h" -#include <library/cpp/yson/consumer.h> +#include <library/cpp/yson/consumer.h> namespace NYT { diff --git a/library/cpp/yson/node/serialize.h b/library/cpp/yson/node/serialize.h index 99b598a44c..00090d0df6 100644 --- a/library/cpp/yson/node/serialize.h +++ b/library/cpp/yson/node/serialize.h @@ -4,10 +4,10 @@ namespace NYT { -namespace NYson { -struct IYsonConsumer; -} // namespace NYson - +namespace NYson { +struct IYsonConsumer; +} // namespace NYson + //////////////////////////////////////////////////////////////////////////////// void Serialize(const TString& value, NYson::IYsonConsumer* consumer); @@ -39,7 +39,7 @@ void Serialize(const TNode& node, NYson::IYsonConsumer* consumer); void Deserialize(TNode& value, const TNode& node); void Serialize(const THashMap<TString, TString>& renameColumns, NYson::IYsonConsumer* consumer); - + //////////////////////////////////////////////////////////////////////////////// } // namespace NYT diff --git a/library/cpp/yson/node/ut/ya.make b/library/cpp/yson/node/ut/ya.make index f49a0bf7df..601c45d8a9 100644 --- a/library/cpp/yson/node/ut/ya.make +++ b/library/cpp/yson/node/ut/ya.make @@ -1,12 +1,12 @@ -UNITTEST_FOR(library/cpp/yson/node) - -OWNER( - ermolovd +UNITTEST_FOR(library/cpp/yson/node) + +OWNER( + ermolovd g:yt -) - -SRCS( - node_ut.cpp -) - -END() +) + +SRCS( + node_ut.cpp +) + +END() diff --git a/library/cpp/yson/node/ya.make b/library/cpp/yson/node/ya.make index a082b293c4..827f3fbab3 100644 --- a/library/cpp/yson/node/ya.make +++ b/library/cpp/yson/node/ya.make @@ -1,25 +1,25 @@ -LIBRARY() - -GENERATE_ENUM_SERIALIZATION(node.h) - -PEERDIR( - library/cpp/yson - library/cpp/yson/json -) - -OWNER( - ermolovd +LIBRARY() + +GENERATE_ENUM_SERIALIZATION(node.h) + +PEERDIR( + library/cpp/yson + library/cpp/yson/json +) + +OWNER( + ermolovd g:yt -) - -SRCS( - node.cpp - node_io.cpp - node_builder.cpp - node_visitor.cpp +) + +SRCS( + node.cpp + node_io.cpp + node_builder.cpp + node_visitor.cpp serialize.cpp -) - -END() - -RECURSE_FOR_TESTS(ut) +) + +END() + +RECURSE_FOR_TESTS(ut) diff --git a/library/cpp/yson/parser.cpp b/library/cpp/yson/parser.cpp index 783f9b9047..a8f47edf86 100644 --- a/library/cpp/yson/parser.cpp +++ b/library/cpp/yson/parser.cpp @@ -6,7 +6,7 @@ #include <util/stream/input.h> #include <util/generic/buffer.h> -namespace NYson { +namespace NYson { //////////////////////////////////////////////////////////////////////////////// class TYsonParser::TImpl { @@ -176,4 +176,4 @@ namespace NYson { //////////////////////////////////////////////////////////////////////////////// -} // namespace NYson +} // namespace NYson diff --git a/library/cpp/yson/parser.h b/library/cpp/yson/parser.h index dce35a8cd4..248d569efc 100644 --- a/library/cpp/yson/parser.h +++ b/library/cpp/yson/parser.h @@ -11,7 +11,7 @@ namespace NYT::NYson { struct IYsonConsumer; } // namespace NYT::NYson -namespace NYson { +namespace NYson { //////////////////////////////////////////////////////////////////////////////// class TYsonParser { @@ -80,4 +80,4 @@ namespace NYson { //////////////////////////////////////////////////////////////////////////////// -} // namespace NYson +} // namespace NYson diff --git a/library/cpp/yson/parser_detail.h b/library/cpp/yson/parser_detail.h index 44223caf12..5ec425b7d9 100644 --- a/library/cpp/yson/parser_detail.h +++ b/library/cpp/yson/parser_detail.h @@ -2,7 +2,7 @@ #include "detail.h" -namespace NYson { +namespace NYson { namespace NDetail { //////////////////////////////////////////////////////////////////////////////// @@ -378,4 +378,4 @@ namespace NYson { //////////////////////////////////////////////////////////////////////////////// -} // namespace NYson +} // namespace NYson diff --git a/library/cpp/yson/public.h b/library/cpp/yson/public.h index 1ed793592b..b343a63722 100644 --- a/library/cpp/yson/public.h +++ b/library/cpp/yson/public.h @@ -6,7 +6,7 @@ #include <library/cpp/yt/yson_string/public.h> #include <library/cpp/yt/yson/public.h> -namespace NYson { +namespace NYson { //////////////////////////////////////////////////////////////////////////////// @@ -15,16 +15,16 @@ namespace NYson { class TYsonStringBuf; - struct TYsonConsumerBase; - - class TYsonWriter; - class TYsonParser; - class TStatelessYsonParser; - class TYsonListParser; + struct TYsonConsumerBase; + class TYsonWriter; + class TYsonParser; + class TStatelessYsonParser; + class TYsonListParser; + class TYsonException : public yexception {}; //////////////////////////////////////////////////////////////////////////////// -} // namespace NYson +} // namespace NYson diff --git a/library/cpp/yson/token.cpp b/library/cpp/yson/token.cpp index c8584c8c2e..f614656bbe 100644 --- a/library/cpp/yson/token.cpp +++ b/library/cpp/yson/token.cpp @@ -3,7 +3,7 @@ #include <util/string/vector.h> #include <util/string/printf.h> -namespace NYson { +namespace NYson { //////////////////////////////////////////////////////////////////////////////// ETokenType CharToTokenType(char ch) { @@ -233,4 +233,4 @@ namespace NYson { //////////////////////////////////////////////////////////////////////////////// -} // namespace NYson +} // namespace NYson diff --git a/library/cpp/yson/token.h b/library/cpp/yson/token.h index 7283e56950..abe6978243 100644 --- a/library/cpp/yson/token.h +++ b/library/cpp/yson/token.h @@ -4,7 +4,7 @@ #include <util/generic/strbuf.h> -namespace NYson { +namespace NYson { //////////////////////////////////////////////////////////////////////////////// enum ETokenType { @@ -90,4 +90,4 @@ namespace NYson { //////////////////////////////////////////////////////////////////////////////// -} // namespace NYson +} // namespace NYson diff --git a/library/cpp/yson/tokenizer.cpp b/library/cpp/yson/tokenizer.cpp index 06760170d4..59c6575f6e 100644 --- a/library/cpp/yson/tokenizer.cpp +++ b/library/cpp/yson/tokenizer.cpp @@ -1,6 +1,6 @@ #include "tokenizer.h" -namespace NYson { +namespace NYson { //////////////////////////////////////////////////////////////////////////////// TTokenizer::TTokenizer(const TStringBuf& input) @@ -34,4 +34,4 @@ namespace NYson { //////////////////////////////////////////////////////////////////////////////// -} // namespace NYson +} // namespace NYson diff --git a/library/cpp/yson/tokenizer.h b/library/cpp/yson/tokenizer.h index 0576aace95..b25ae01c7e 100644 --- a/library/cpp/yson/tokenizer.h +++ b/library/cpp/yson/tokenizer.h @@ -3,7 +3,7 @@ #include "public.h" #include "lexer.h" -namespace NYson { +namespace NYson { //////////////////////////////////////////////////////////////////////////////// class TTokenizer { @@ -25,4 +25,4 @@ namespace NYson { //////////////////////////////////////////////////////////////////////////////// -} // namespace NYson +} // namespace NYson diff --git a/library/cpp/yson/varint.cpp b/library/cpp/yson/varint.cpp index d538ee3cff..c917161665 100644 --- a/library/cpp/yson/varint.cpp +++ b/library/cpp/yson/varint.cpp @@ -1,10 +1,10 @@ -#include "varint.h" - +#include "varint.h" + #include "zigzag.h" -#include <util/generic/yexception.h> +#include <util/generic/yexception.h> -namespace NYson { +namespace NYson { //////////////////////////////////////////////////////////////////////////////// int WriteVarUInt64(IOutputStream* output, ui64 value) { @@ -55,7 +55,7 @@ namespace NYson { ui64 varInt; int bytesRead = ReadVarUInt64(input, &varInt); if (varInt > Max<ui32>()) { - ythrow yexception() << "The data is too long to read ui64"; + ythrow yexception() << "The data is too long to read ui64"; } *value = ZigZagDecode32(static_cast<ui32>(varInt)); return bytesRead; @@ -68,4 +68,4 @@ namespace NYson { return bytesRead; } -} // namespace NYson +} // namespace NYson diff --git a/library/cpp/yson/varint.h b/library/cpp/yson/varint.h index 80b1184e57..8031ca1094 100644 --- a/library/cpp/yson/varint.h +++ b/library/cpp/yson/varint.h @@ -4,7 +4,7 @@ #include <util/stream/output.h> #include <util/system/defaults.h> -namespace NYson { +namespace NYson { //////////////////////////////////////////////////////////////////////////////// // Various functions that read/write varints from/to a stream. @@ -21,4 +21,4 @@ namespace NYson { //////////////////////////////////////////////////////////////////////////////// -} // namespace NYson +} // namespace NYson diff --git a/library/cpp/yson/writer.cpp b/library/cpp/yson/writer.cpp index 054459f9f5..8d130a6500 100644 --- a/library/cpp/yson/writer.cpp +++ b/library/cpp/yson/writer.cpp @@ -1,16 +1,16 @@ #include "writer.h" - -#include "detail.h" + +#include "detail.h" #include "format.h" -#include "parser.h" -#include "varint.h" +#include "parser.h" +#include "varint.h" #include "zigzag.h" #include <util/string/cast.h> #include <cmath> -namespace NYson { +namespace NYson { //////////////////////////////////////////////////////////////////////////////// // Copied from <util/string/escape.cpp> @@ -352,4 +352,4 @@ namespace NYson { //////////////////////////////////////////////////////////////////////////////// -} // namespace NYson +} // namespace NYson diff --git a/library/cpp/yson/writer.h b/library/cpp/yson/writer.h index 40f5d7d501..278fd08624 100644 --- a/library/cpp/yson/writer.h +++ b/library/cpp/yson/writer.h @@ -9,7 +9,7 @@ class IOutputStream; class IZeroCopyInput; -namespace NYson { +namespace NYson { //////////////////////////////////////////////////////////////////////////////// class TYsonWriter @@ -86,4 +86,4 @@ namespace NYson { //////////////////////////////////////////////////////////////////////////////// -} // namespace NYson +} // namespace NYson diff --git a/library/cpp/yson/ya.make b/library/cpp/yson/ya.make index c55a189b10..23896d164c 100644 --- a/library/cpp/yson/ya.make +++ b/library/cpp/yson/ya.make @@ -1,9 +1,9 @@ LIBRARY() -OWNER( - ermolovd +OWNER( + ermolovd g:yt -) +) PEERDIR( library/cpp/yt/misc @@ -11,12 +11,12 @@ PEERDIR( ) SRCS( - consumer.cpp + consumer.cpp lexer.cpp - parser.cpp + parser.cpp token.cpp tokenizer.cpp - varint.cpp + varint.cpp writer.cpp ) diff --git a/library/cpp/yson/zigzag.h b/library/cpp/yson/zigzag.h index 2f1190508f..4b39db202b 100644 --- a/library/cpp/yson/zigzag.h +++ b/library/cpp/yson/zigzag.h @@ -2,7 +2,7 @@ #include <util/system/defaults.h> -namespace NYson { +namespace NYson { //////////////////////////////////////////////////////////////////////////////// //! Functions that provide coding of integers with property: 0 <= f(x) <= 2 * |x| @@ -28,4 +28,4 @@ namespace NYson { //////////////////////////////////////////////////////////////////////////////// -} // namespace NYson +} // namespace NYson |