percent_scalar.h 968 B

123456789101112131415161718192021222324252627282930313233343536
  1. #pragma once
  2. #include <util/generic/strbuf.h>
  3. namespace NYsonPull::NDetail {
  4. enum class percent_scalar_type {
  5. boolean,
  6. float64
  7. };
  8. struct percent_scalar {
  9. //! Text boolean literals
  10. static constexpr TStringBuf true_literal = "%true";
  11. static constexpr TStringBuf false_literal = "%false";
  12. //! Text floating-point literals
  13. static constexpr TStringBuf nan_literal = "%nan";
  14. static constexpr TStringBuf positive_inf_literal = "%inf";
  15. static constexpr TStringBuf negative_inf_literal = "%-inf";
  16. percent_scalar_type type;
  17. union {
  18. double as_float64;
  19. bool as_boolean;
  20. } value;
  21. percent_scalar(double v) {
  22. type = percent_scalar_type::float64;
  23. value.as_float64 = v;
  24. }
  25. percent_scalar(bool v) {
  26. type = percent_scalar_type::boolean;
  27. value.as_boolean = v;
  28. }
  29. };
  30. }