aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yson_pull/detail/percent_scalar.h
blob: 4dfb57d36b48d89d301134ea43fb253a9c7ff0c7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#pragma once

#include <util/generic/strbuf.h>

namespace NYsonPull::NDetail {
    enum class percent_scalar_type {
        boolean,
        float64
    };

    struct percent_scalar {
        //! Text boolean literals
        static constexpr TStringBuf true_literal = "%true"; 
        static constexpr TStringBuf false_literal = "%false"; 
        //! Text floating-point literals
        static constexpr TStringBuf nan_literal = "%nan"; 
        static constexpr TStringBuf positive_inf_literal = "%inf"; 
        static constexpr TStringBuf negative_inf_literal = "%-inf"; 

        percent_scalar_type type;
        union {
            double as_float64;
            bool as_boolean;
        } value;

        percent_scalar(double v) {
            type = percent_scalar_type::float64;
            value.as_float64 = v;
        }

        percent_scalar(bool v) {
            type = percent_scalar_type::boolean;
            value.as_boolean = v;
        }
    };
}