| 1 | #pragma once | 
|---|---|
| 2 | |
| 3 | #ifdef __clang__ | 
| 4 | #pragma clang diagnostic push | 
| 5 | #pragma clang diagnostic ignored "-Wdouble-promotion" | 
| 6 | #endif | 
| 7 | |
| 8 | #include <double-conversion/double-conversion.h> | 
| 9 | #include <boost/noncopyable.hpp> | 
| 10 | |
| 11 | #ifdef __clang__ | 
| 12 | #pragma clang diagnostic pop | 
| 13 | #endif | 
| 14 | |
| 15 | |
| 16 | namespace DB | 
| 17 | { | 
| 18 | |
| 19 | template <bool emit_decimal_point> struct DoubleToStringConverterFlags | 
| 20 | { | 
| 21 | static constexpr auto flags = double_conversion::DoubleToStringConverter::NO_FLAGS; | 
| 22 | }; | 
| 23 | |
| 24 | template <> struct DoubleToStringConverterFlags<true> | 
| 25 | { | 
| 26 | static constexpr auto flags = double_conversion::DoubleToStringConverter::EMIT_TRAILING_DECIMAL_POINT; | 
| 27 | }; | 
| 28 | |
| 29 | template <bool emit_decimal_point> | 
| 30 | class DoubleConverter : private boost::noncopyable | 
| 31 | { | 
| 32 | DoubleConverter(const DoubleConverter &) = delete; | 
| 33 | DoubleConverter & operator=(const DoubleConverter &) = delete; | 
| 34 | |
| 35 | DoubleConverter() = default; | 
| 36 | |
| 37 | public: | 
| 38 | /// Sign (1 byte) + DigitsBeforePoint + point (1 byte) + DigitsAfterPoint + zero byte. | 
| 39 | /// See comment to DoubleToStringConverter::ToFixed method for explanation. | 
| 40 | static constexpr auto MAX_REPRESENTATION_LENGTH = | 
| 41 | 1 + double_conversion::DoubleToStringConverter::kMaxFixedDigitsBeforePoint + | 
| 42 | 1 + double_conversion::DoubleToStringConverter::kMaxFixedDigitsAfterPoint + 1; | 
| 43 | using BufferType = char[MAX_REPRESENTATION_LENGTH]; | 
| 44 | |
| 45 | static const double_conversion::DoubleToStringConverter & instance(); | 
| 46 | }; | 
| 47 | |
| 48 | } | 
| 49 | 
