scalar.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "scalar.h"
  2. #include <library/cpp/yson_pull/detail/cescape.h>
  3. #include <util/stream/output.h>
  4. using namespace NYsonPull;
  5. template <>
  6. void Out<TScalar>(IOutputStream& out, const TScalar& value) {
  7. out << '(' << value.Type();
  8. if (value.Type() != EScalarType::Entity) {
  9. out << ' ';
  10. }
  11. switch (value.Type()) {
  12. case EScalarType::Boolean:
  13. out << (value.AsBoolean() ? "true" : "false");
  14. break;
  15. case EScalarType::String:
  16. out << NYsonPull::NDetail::NCEscape::quote(value.AsString());
  17. break;
  18. case EScalarType::Int64:
  19. out << value.AsInt64();
  20. break;
  21. case EScalarType::UInt64:
  22. out << value.AsUInt64();
  23. break;
  24. case EScalarType::Float64:
  25. out << value.AsFloat64();
  26. break;
  27. default:
  28. break;
  29. }
  30. out << ')';
  31. }
  32. bool NYsonPull::operator==(const TScalar& left, const TScalar& right) noexcept {
  33. if (left.Type() != right.Type()) {
  34. return false;
  35. }
  36. switch (left.Type()) {
  37. case EScalarType::Boolean:
  38. return left.AsBoolean() == right.AsBoolean();
  39. case EScalarType::String:
  40. return left.AsString() == right.AsString();
  41. case EScalarType::Int64:
  42. return left.AsInt64() == right.AsInt64();
  43. case EScalarType::UInt64:
  44. return left.AsUInt64() == right.AsUInt64();
  45. case EScalarType::Float64:
  46. return left.AsFloat64() == right.AsFloat64();
  47. case EScalarType::Entity:
  48. return true;
  49. default:
  50. Y_UNREACHABLE();
  51. }
  52. }