convert.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #pragma once
  2. #include "string.h"
  3. #include <library/cpp/yt/misc/guid.h>
  4. #include <library/cpp/yt/exception/exception.h>
  5. #include <util/generic/string.h>
  6. #include <util/datetime/base.h>
  7. namespace NYT::NYson {
  8. ////////////////////////////////////////////////////////////////////////////////
  9. // Generic forward declarations.
  10. template <class T>
  11. TYsonString ConvertToYsonString(const T& value);
  12. template <class T>
  13. TYsonString ConvertToYsonString(const T& value, EYsonFormat format);
  14. template <class T>
  15. T ConvertFromYsonString(const TYsonStringBuf& str);
  16. ////////////////////////////////////////////////////////////////////////////////
  17. // Basic specializations for ConvertToYsonString.
  18. template <>
  19. TYsonString ConvertToYsonString<i8>(const i8& value);
  20. template <>
  21. TYsonString ConvertToYsonString<i32>(const i32& value);
  22. template <>
  23. TYsonString ConvertToYsonString<i64>(const i64& value);
  24. template <>
  25. TYsonString ConvertToYsonString<ui8>(const ui8& value);
  26. template <>
  27. TYsonString ConvertToYsonString<ui32>(const ui32& value);
  28. template <>
  29. TYsonString ConvertToYsonString<ui64>(const ui64& value);
  30. template <>
  31. TYsonString ConvertToYsonString<TString>(const TString& value);
  32. template <>
  33. TYsonString ConvertToYsonString<TStringBuf>(const TStringBuf& value);
  34. TYsonString ConvertToYsonString(const char* value);
  35. template <>
  36. TYsonString ConvertToYsonString<float>(const float& value);
  37. template <>
  38. TYsonString ConvertToYsonString<double>(const double& value);
  39. template <>
  40. TYsonString ConvertToYsonString<bool>(const bool& value);
  41. template <>
  42. TYsonString ConvertToYsonString<TInstant>(const TInstant& value);
  43. template <>
  44. TYsonString ConvertToYsonString<TDuration>(const TDuration& value);
  45. template <>
  46. TYsonString ConvertToYsonString<TGuid>(const TGuid& value);
  47. ////////////////////////////////////////////////////////////////////////////////
  48. // Basic specializations for ConvertFromYsonString.
  49. // Note: these currently support a subset of NYT::NYTree::Convert features.
  50. class TYsonLiteralParseException
  51. : public TCompositeException
  52. {
  53. public:
  54. using TCompositeException::TCompositeException;
  55. };
  56. template <>
  57. i8 ConvertFromYsonString<i8>(const TYsonStringBuf& str);
  58. template <>
  59. i32 ConvertFromYsonString<i32>(const TYsonStringBuf& str);
  60. template <>
  61. i64 ConvertFromYsonString<i64>(const TYsonStringBuf& str);
  62. template <>
  63. ui8 ConvertFromYsonString<ui8>(const TYsonStringBuf& str);
  64. template <>
  65. ui32 ConvertFromYsonString<ui32>(const TYsonStringBuf& str);
  66. template <>
  67. ui64 ConvertFromYsonString<ui64>(const TYsonStringBuf& str);
  68. template <>
  69. TString ConvertFromYsonString<TString>(const TYsonStringBuf& str);
  70. template <>
  71. float ConvertFromYsonString<float>(const TYsonStringBuf& str);
  72. template <>
  73. double ConvertFromYsonString<double>(const TYsonStringBuf& str);
  74. template <>
  75. bool ConvertFromYsonString<bool>(const TYsonStringBuf& str);
  76. template <>
  77. TInstant ConvertFromYsonString<TInstant>(const TYsonStringBuf& str);
  78. template <>
  79. TDuration ConvertFromYsonString<TDuration>(const TYsonStringBuf& str);
  80. template <>
  81. TGuid ConvertFromYsonString<TGuid>(const TYsonStringBuf& str);
  82. ////////////////////////////////////////////////////////////////////////////////
  83. } // namespace NYT::NYson