Browse Source

Restoring authorship annotation for <inngonch@yandex-team.ru>. Commit 2 of 2.

inngonch 3 years ago
parent
commit
7622df751a

+ 39 - 39
library/cpp/yson/node/node.h

@@ -1,7 +1,7 @@
 #pragma once
 
 #include <util/generic/bt_exception.h>
-#include <util/generic/cast.h> 
+#include <util/generic/cast.h>
 #include <util/generic/hash.h>
 #include <util/generic/variant.h>
 #include <util/generic/vector.h>
@@ -159,12 +159,12 @@ public:
     TListType& UncheckedAsList() noexcept;
     TMapType& UncheckedAsMap() noexcept;
 
-    // integer types cast 
+    // integer types cast
     // makes overflow checks
     template<typename T>
     T IntCast() const;
 
-    // integers <-> double <-> string 
+    // integers <-> double <-> string
     // makes overflow checks
     template<typename T>
     T ConvertTo() const;
@@ -296,49 +296,49 @@ inline bool TNode::IsArithmetic() const {
 
 template<typename T>
 inline T TNode::IntCast() const {
-    if constexpr (std::is_integral<T>::value) { 
-        try { 
-            switch (GetType()) { 
-                case TNode::Uint64: 
-                    return SafeIntegerCast<T>(AsUint64()); 
-                case TNode::Int64: 
-                    return SafeIntegerCast<T>(AsInt64()); 
-                default: 
-                    ythrow TTypeError() << "IntCast() called for type " << GetType(); 
+    if constexpr (std::is_integral<T>::value) {
+        try {
+            switch (GetType()) {
+                case TNode::Uint64:
+                    return SafeIntegerCast<T>(AsUint64());
+                case TNode::Int64:
+                    return SafeIntegerCast<T>(AsInt64());
+                default:
+                    ythrow TTypeError() << "IntCast() called for type " << GetType();
             }
-        } catch(TBadCastException& exc) { 
-            ythrow TTypeError() << "TBadCastException during IntCast(): " << exc.what(); 
-        } 
-    } else { 
-        static_assert(sizeof(T) != sizeof(T), "implemented only for std::is_integral types"); 
+        } catch(TBadCastException& exc) {
+            ythrow TTypeError() << "TBadCastException during IntCast(): " << exc.what();
+        }
+    } else {
+        static_assert(sizeof(T) != sizeof(T), "implemented only for std::is_integral types");
     }
 }
 
 template<typename T>
 inline T TNode::ConvertTo() const {
-    if constexpr (std::is_integral<T>::value) { 
-        switch (GetType()) { 
-            case NYT::TNode::String: 
-                return ::FromString(AsString()); 
-            case NYT::TNode::Int64: 
-            case NYT::TNode::Uint64: 
-                return IntCast<T>(); 
-            case NYT::TNode::Double: 
+    if constexpr (std::is_integral<T>::value) {
+        switch (GetType()) {
+            case NYT::TNode::String:
+                return ::FromString(AsString());
+            case NYT::TNode::Int64:
+            case NYT::TNode::Uint64:
+                return IntCast<T>();
+            case NYT::TNode::Double:
                 if (AsDouble() < Min<T>() || AsDouble() > MaxFloor<T>() || !std::isfinite(AsDouble())) {
-                    ythrow TTypeError() << AsDouble() << " can't be converted to " << TypeName<T>(); 
-                } 
-                return AsDouble(); 
-            case NYT::TNode::Bool: 
-                return AsBool(); 
-            case NYT::TNode::List: 
-            case NYT::TNode::Map: 
-            case NYT::TNode::Null: 
-            case NYT::TNode::Undefined: 
-                ythrow TTypeError() << "ConvertTo<" << TypeName<T>() << ">() called for type " << GetType(); 
-        }; 
-    } else { 
-        static_assert(sizeof(T) != sizeof(T), "should have template specialization"); 
-    } 
+                    ythrow TTypeError() << AsDouble() << " can't be converted to " << TypeName<T>();
+                }
+                return AsDouble();
+            case NYT::TNode::Bool:
+                return AsBool();
+            case NYT::TNode::List:
+            case NYT::TNode::Map:
+            case NYT::TNode::Null:
+            case NYT::TNode::Undefined:
+                ythrow TTypeError() << "ConvertTo<" << TypeName<T>() << ">() called for type " << GetType();
+        };
+    } else {
+        static_assert(sizeof(T) != sizeof(T), "should have template specialization");
+    }
 }
 
 template<>

+ 25 - 25
library/cpp/yson/node/node_ut.cpp

@@ -282,11 +282,11 @@ Y_UNIT_TEST_SUITE(YtNodeTest) {
     Y_UNIT_TEST(TestIntCast) {
         TNode node = 1ull << 31;
         UNIT_ASSERT(node.IsUint64());
-        UNIT_ASSERT_EXCEPTION(node.IntCast<i32>(), TNode::TTypeError); 
-        UNIT_ASSERT(node.IntCast<ui32>() == static_cast<ui32>(node.AsUint64())); 
-        UNIT_ASSERT(node.IntCast<i64>() == static_cast<i64>(node.AsUint64())); 
+        UNIT_ASSERT_EXCEPTION(node.IntCast<i32>(), TNode::TTypeError);
+        UNIT_ASSERT(node.IntCast<ui32>() == static_cast<ui32>(node.AsUint64()));
+        UNIT_ASSERT(node.IntCast<i64>() == static_cast<i64>(node.AsUint64()));
         UNIT_ASSERT(node.IntCast<ui64>() == node.AsUint64());
- 
+
         node = 1ull << 63;
         UNIT_ASSERT(node.IsUint64());
         UNIT_ASSERT_EXCEPTION(node.IntCast<i64>(), TNode::TTypeError);
@@ -294,24 +294,24 @@ Y_UNIT_TEST_SUITE(YtNodeTest) {
 
         node = 12345;
         UNIT_ASSERT(node.IsInt64());
-        UNIT_ASSERT_EXCEPTION(node.IntCast<i8>(), TNode::TTypeError); 
-        UNIT_ASSERT_EXCEPTION(node.IntCast<ui8>(), TNode::TTypeError); 
-        UNIT_ASSERT(node.IntCast<i16>() == static_cast<i16>(node.AsInt64())); 
-        UNIT_ASSERT(node.IntCast<ui16>() == static_cast<ui16>(node.AsInt64())); 
-        UNIT_ASSERT(node.IntCast<i32>() == static_cast<i32>(node.AsInt64())); 
-        UNIT_ASSERT(node.IntCast<ui32>() == static_cast<ui32>(node.AsInt64())); 
+        UNIT_ASSERT_EXCEPTION(node.IntCast<i8>(), TNode::TTypeError);
+        UNIT_ASSERT_EXCEPTION(node.IntCast<ui8>(), TNode::TTypeError);
+        UNIT_ASSERT(node.IntCast<i16>() == static_cast<i16>(node.AsInt64()));
+        UNIT_ASSERT(node.IntCast<ui16>() == static_cast<ui16>(node.AsInt64()));
+        UNIT_ASSERT(node.IntCast<i32>() == static_cast<i32>(node.AsInt64()));
+        UNIT_ASSERT(node.IntCast<ui32>() == static_cast<ui32>(node.AsInt64()));
         UNIT_ASSERT(node.IntCast<i64>() == node.AsInt64());
         UNIT_ASSERT(node.IntCast<ui64>() == static_cast<ui64>(node.AsInt64()));
- 
+
         node = -5;
         UNIT_ASSERT(node.IsInt64());
-        UNIT_ASSERT(node.IntCast<i8>() == static_cast<i8>(node.AsInt64())); 
-        UNIT_ASSERT(node.IntCast<i16>() == static_cast<i16>(node.AsInt64())); 
-        UNIT_ASSERT(node.IntCast<i32>() == static_cast<i32>(node.AsInt64())); 
+        UNIT_ASSERT(node.IntCast<i8>() == static_cast<i8>(node.AsInt64()));
+        UNIT_ASSERT(node.IntCast<i16>() == static_cast<i16>(node.AsInt64()));
+        UNIT_ASSERT(node.IntCast<i32>() == static_cast<i32>(node.AsInt64()));
         UNIT_ASSERT(node.IntCast<i64>() == node.AsInt64());
-        UNIT_ASSERT_EXCEPTION(node.IntCast<ui8>(), TNode::TTypeError); 
-        UNIT_ASSERT_EXCEPTION(node.IntCast<ui16>(), TNode::TTypeError); 
-        UNIT_ASSERT_EXCEPTION(node.IntCast<ui32>(), TNode::TTypeError); 
+        UNIT_ASSERT_EXCEPTION(node.IntCast<ui8>(), TNode::TTypeError);
+        UNIT_ASSERT_EXCEPTION(node.IntCast<ui16>(), TNode::TTypeError);
+        UNIT_ASSERT_EXCEPTION(node.IntCast<ui32>(), TNode::TTypeError);
         UNIT_ASSERT_EXCEPTION(node.IntCast<ui64>(), TNode::TTypeError);
     }
 
@@ -335,20 +335,20 @@ Y_UNIT_TEST_SUITE(YtNodeTest) {
     }
 
     Y_UNIT_TEST(TestConvertDoubleInt) {
-        UNIT_ASSERT_VALUES_EQUAL(TNode(5.3).ConvertTo<i8>(), 5); 
-        UNIT_ASSERT_VALUES_EQUAL(TNode(5.3).ConvertTo<ui8>(), 5); 
-        UNIT_ASSERT_VALUES_EQUAL(TNode(5.3).ConvertTo<i64>(), 5); 
+        UNIT_ASSERT_VALUES_EQUAL(TNode(5.3).ConvertTo<i8>(), 5);
+        UNIT_ASSERT_VALUES_EQUAL(TNode(5.3).ConvertTo<ui8>(), 5);
+        UNIT_ASSERT_VALUES_EQUAL(TNode(5.3).ConvertTo<i64>(), 5);
         UNIT_ASSERT_VALUES_EQUAL(TNode(5.3).ConvertTo<ui64>(), 5);
- 
-        UNIT_ASSERT_VALUES_EQUAL(TNode(-5.3).ConvertTo<i8>(), -5); 
+
+        UNIT_ASSERT_VALUES_EQUAL(TNode(-5.3).ConvertTo<i8>(), -5);
         UNIT_ASSERT_VALUES_EQUAL(TNode(-5.3).ConvertTo<i64>(), -5);
-        UNIT_ASSERT_EXCEPTION(TNode(-5.3).ConvertTo<ui8>(), TNode::TTypeError); 
+        UNIT_ASSERT_EXCEPTION(TNode(-5.3).ConvertTo<ui8>(), TNode::TTypeError);
         UNIT_ASSERT_EXCEPTION(TNode(-5.3).ConvertTo<ui64>(), TNode::TTypeError);
- 
+
         UNIT_ASSERT_VALUES_EQUAL(TNode(127.0).ConvertTo<i8>(), 127);
         UNIT_ASSERT_EXCEPTION(TNode(128.0).ConvertTo<i8>(), TNode::TTypeError);
         UNIT_ASSERT_VALUES_EQUAL(TNode(255.0).ConvertTo<ui8>(), 255);
-        UNIT_ASSERT_EXCEPTION(TNode(256.0).ConvertTo<ui8>(), TNode::TTypeError); 
+        UNIT_ASSERT_EXCEPTION(TNode(256.0).ConvertTo<ui8>(), TNode::TTypeError);
         UNIT_ASSERT_EXCEPTION(TNode(1e100).ConvertTo<i64>(), TNode::TTypeError);
         UNIT_ASSERT_EXCEPTION(TNode(1e100).ConvertTo<ui64>(), TNode::TTypeError);
         {

+ 90 - 90
library/cpp/yson/node/pybind/node.cpp

@@ -1,59 +1,59 @@
-#include "node.h" 
- 
+#include "node.h"
+
 #include <library/cpp/yson/node/node.h>
- 
+
 #include <library/cpp/pybind/cast.h>
- 
-#include <Python.h> 
- 
-namespace NYT { 
- 
-    PyObject* BuildPyObject(const TNode& node) { 
-        switch (node.GetType()) { 
-            case TNode::Bool: 
-                return NPyBind::BuildPyObject(node.AsBool()); 
-            case TNode::Int64: 
-                return NPyBind::BuildPyObject(node.AsInt64()); 
-            case TNode::Uint64: 
-                return NPyBind::BuildPyObject(node.AsUint64()); 
-            case TNode::Double: 
-                return NPyBind::BuildPyObject(node.AsDouble()); 
-            case TNode::String: 
-                return NPyBind::BuildPyObject(node.AsString()); 
-            case TNode::List: 
-                return NPyBind::BuildPyObject(node.AsList()); 
-            case TNode::Map: 
-                return NPyBind::BuildPyObject(node.AsMap()); 
-            case TNode::Null: 
-                Py_RETURN_NONE; 
-            case TNode::Undefined: 
-                ythrow TNode::TTypeError() << "BuildPyObject called for undefined TNode"; 
-        } 
-    } 
- 
-} // namespace NYT 
- 
-namespace NPyBind { 
- 
-    template <> 
-    bool FromPyObject(PyObject* obj, NYT::TNode& res) { 
-        if (obj == Py_None) { 
-            res = NYT::TNode::CreateEntity(); 
-            return true; 
-        } 
-        if (PyBool_Check(obj)) { 
-            res = false; 
-            return FromPyObject(obj, res.As<bool>()); 
-        } 
-        if (PyFloat_Check(obj)) { 
-            res = 0.0; 
-            return FromPyObject(obj, res.As<double>()); 
-        } 
+
+#include <Python.h>
+
+namespace NYT {
+
+    PyObject* BuildPyObject(const TNode& node) {
+        switch (node.GetType()) {
+            case TNode::Bool:
+                return NPyBind::BuildPyObject(node.AsBool());
+            case TNode::Int64:
+                return NPyBind::BuildPyObject(node.AsInt64());
+            case TNode::Uint64:
+                return NPyBind::BuildPyObject(node.AsUint64());
+            case TNode::Double:
+                return NPyBind::BuildPyObject(node.AsDouble());
+            case TNode::String:
+                return NPyBind::BuildPyObject(node.AsString());
+            case TNode::List:
+                return NPyBind::BuildPyObject(node.AsList());
+            case TNode::Map:
+                return NPyBind::BuildPyObject(node.AsMap());
+            case TNode::Null:
+                Py_RETURN_NONE;
+            case TNode::Undefined:
+                ythrow TNode::TTypeError() << "BuildPyObject called for undefined TNode";
+        }
+    }
+
+} // namespace NYT
+
+namespace NPyBind {
+
+    template <>
+    bool FromPyObject(PyObject* obj, NYT::TNode& res) {
+        if (obj == Py_None) {
+            res = NYT::TNode::CreateEntity();
+            return true;
+        }
+        if (PyBool_Check(obj)) {
+            res = false;
+            return FromPyObject(obj, res.As<bool>());
+        }
+        if (PyFloat_Check(obj)) {
+            res = 0.0;
+            return FromPyObject(obj, res.As<double>());
+        }
 #if PY_MAJOR_VERSION < 3
-        if (PyString_Check(obj)) { 
-            res = TString(); 
-            return FromPyObject(obj, res.As<TString>()); 
-        } 
+        if (PyString_Check(obj)) {
+            res = TString();
+            return FromPyObject(obj, res.As<TString>());
+        }
 #else
         if (PyUnicode_Check(obj)) {
             res = TString();
@@ -64,42 +64,42 @@ namespace NPyBind {
             return FromPyObject(obj, res.As<TString>());
         }
 #endif
-        if (PyList_Check(obj)) { 
-            res = NYT::TNode::CreateList(); 
-            return FromPyObject(obj, res.AsList()); 
-        } 
-        if (PyDict_Check(obj)) { 
-            res = NYT::TNode::CreateMap(); 
-            return FromPyObject(obj, res.AsMap()); 
-        } 
+        if (PyList_Check(obj)) {
+            res = NYT::TNode::CreateList();
+            return FromPyObject(obj, res.AsList());
+        }
+        if (PyDict_Check(obj)) {
+            res = NYT::TNode::CreateMap();
+            return FromPyObject(obj, res.AsMap());
+        }
 #if PY_MAJOR_VERSION < 3
-        if (PyInt_Check(obj)) { 
-            auto valAsLong = PyInt_AsLong(obj); 
-            if (valAsLong == -1 && PyErr_Occurred()) { 
-                return false; 
-            } 
-            res = valAsLong; 
-            return true; 
-        } 
+        if (PyInt_Check(obj)) {
+            auto valAsLong = PyInt_AsLong(obj);
+            if (valAsLong == -1 && PyErr_Occurred()) {
+                return false;
+            }
+            res = valAsLong;
+            return true;
+        }
 #endif
-        if (PyLong_Check(obj)) { 
-            int overflow = 0; 
-            auto valAsLong = PyLong_AsLongAndOverflow(obj, &overflow); 
-            if (!overflow) { 
-                if (valAsLong == -1 && PyErr_Occurred()) { 
-                    return false; 
-                } 
-                res = valAsLong; 
-                return true; 
-            } 
-            auto valAsULong = PyLong_AsUnsignedLong(obj); 
-            if (valAsULong == static_cast<decltype(valAsULong)>(-1) && PyErr_Occurred()) { 
-                return false; 
-            } 
-            res = valAsULong; 
-            return true; 
-        } 
-        return false; 
-    } 
- 
-} // namespace NPyBind 
+        if (PyLong_Check(obj)) {
+            int overflow = 0;
+            auto valAsLong = PyLong_AsLongAndOverflow(obj, &overflow);
+            if (!overflow) {
+                if (valAsLong == -1 && PyErr_Occurred()) {
+                    return false;
+                }
+                res = valAsLong;
+                return true;
+            }
+            auto valAsULong = PyLong_AsUnsignedLong(obj);
+            if (valAsULong == static_cast<decltype(valAsULong)>(-1) && PyErr_Occurred()) {
+                return false;
+            }
+            res = valAsULong;
+            return true;
+        }
+        return false;
+    }
+
+} // namespace NPyBind

+ 6 - 6
library/cpp/yson/node/pybind/node.h

@@ -1,9 +1,9 @@
-#pragma once 
- 
+#pragma once
+
 #include <Python.h>
 
 #include <library/cpp/yson/node/node.h>
- 
-namespace NYT { 
-    PyObject* BuildPyObject(const TNode& val); 
-} 
+
+namespace NYT {
+    PyObject* BuildPyObject(const TNode& val);
+}

+ 13 - 13
library/cpp/yson/node/pybind/ya.make

@@ -1,16 +1,16 @@
 PY23_NATIVE_LIBRARY()
- 
-OWNER( 
-    inngonch 
-    g:yt 
-) 
- 
-PEERDIR( 
+
+OWNER(
+    inngonch
+    g:yt
+)
+
+PEERDIR(
     library/cpp/pybind
     library/cpp/yson/node
-) 
-SRCS( 
-    node.cpp 
-) 
- 
-END() 
+)
+SRCS(
+    node.cpp
+)
+
+END()

+ 12 - 12
util/datetime/base.cpp

@@ -214,18 +214,18 @@ TString TInstant::ToStringLocalUpToSeconds() const {
     return ::ToString(FormatLocalUpToSeconds(*this));
 }
 
-TString TInstant::FormatLocalTime(const char* format) const noexcept { 
-    struct tm theTm; 
-    LocalTime(&theTm); 
-    return Strftime(format, &theTm); 
-} 
- 
-TString TInstant::FormatGmTime(const char* format) const noexcept { 
-    struct tm theTm; 
-    GmTime(&theTm); 
-    return Strftime(format, &theTm); 
-} 
- 
+TString TInstant::FormatLocalTime(const char* format) const noexcept {
+    struct tm theTm;
+    LocalTime(&theTm);
+    return Strftime(format, &theTm);
+}
+
+TString TInstant::FormatGmTime(const char* format) const noexcept {
+    struct tm theTm;
+    GmTime(&theTm);
+    return Strftime(format, &theTm);
+}
+
 ::NPrivate::TPrintableLocalTime<false, true> FormatIsoLocal(TInstant instant) {
     return ::NPrivate::TPrintableLocalTime<false, true>(instant);
 }

+ 3 - 3
util/datetime/base.h

@@ -504,9 +504,9 @@ public:
      */
     TString ToStringLocalUpToSeconds() const;
 
-    TString FormatLocalTime(const char* format) const noexcept; 
-    TString FormatGmTime(const char* format) const noexcept; 
- 
+    TString FormatLocalTime(const char* format) const noexcept;
+    TString FormatGmTime(const char* format) const noexcept;
+
     /// See #TryParseIso8601.
     static TInstant ParseIso8601(TStringBuf);
     /// See #TryParseRfc822.

+ 4 - 4
util/stream/multi.h

@@ -25,8 +25,8 @@ private:
     IInputStream* N_;
 };
 
-/** 
- * See also "util/stream/tee.h" for multi output. 
- */ 
- 
+/**
+ * See also "util/stream/tee.h" for multi output.
+ */
+
 /** @} */