libzypp 17.38.14
JsonNumber.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9#ifndef ZYPP_CORE_PARSER_JSON_JSON_NUMBER_DEFINED
10#define ZYPP_CORE_PARSER_JSON_JSON_NUMBER_DEFINED
11
12#include <string>
13#include <cstdint>
14#include <ostream>
15
16#include <zypp-core/Globals.h>
17
18namespace zypp::json {
19
21
22 public:
23 Number() = default;
24 explicit Number( double v ) : _value(v) {}
25 explicit Number( float v ) : _value(v) {}
26 ~Number() = default;
27
28 Number( const Number & ) = default;
29 Number( Number && ) = default;
30 Number &operator=(const Number &) = default;
31 Number &operator=(Number &&) = default;
32
33 operator double() const {
34 return _value;
35 }
36
37 double value() const {
38 return _value;
39 }
40
42 std::string asJSON() const
43 { return std::to_string (_value); }
44
46 std::ostream & dumpOn( std::ostream & str ) const
47 { return str << asJSON(); }
48
49 private:
50 double _value = 0;
51
52 };
53
55 inline ZYPP_API std::ostream & operator<<( std::ostream & str, const Number & obj )
56 {
57 return obj.dumpOn( str );
58 }
59
60 class ZYPP_API Int {
61
62 public:
63 Int() = default;
64 Int( std::int64_t v ) : _value(v) {}
65 ~Int() = default;
66
67 Int( const Int & ) = default;
68 Int( Int && ) = default;
69 Int &operator=(const Int &) = default;
70 Int &operator=(Int &&) = default;
71
72 operator std::int64_t() const {
73 return _value;
74 }
75
76 std::int64_t value() const {
77 return _value;
78 }
79
81 std::string asJSON() const
82 { return std::to_string (_value); }
83
85 std::ostream & dumpOn( std::ostream & str ) const
86 { return str << asJSON(); }
87
88 private:
89 std::int64_t _value = 0;
90 };
91
93 inline std::ostream & operator<<( std::ostream & str, const Int & obj )
94 {
95 return obj.dumpOn( str );
96 }
97
98 class ZYPP_API UInt {
99
100 public:
101 UInt() = default;
102 UInt( std::uint64_t v ) : _value(v) {}
103 ~UInt() = default;
104
105 UInt( const UInt & ) = default;
106 UInt( UInt && ) = default;
107 UInt &operator=(const UInt &) = default;
108 UInt &operator=(UInt &&) = default;
109
110 operator std::uint64_t() const {
111 return _value;
112 }
113
114 std::uint64_t value() const {
115 return _value;
116 }
117
119 std::string asJSON() const
120 { return std::to_string (_value); }
121
123 std::ostream & dumpOn( std::ostream & str ) const
124 { return str << asJSON(); }
125
126 private:
127 std::uint64_t _value = 0;
128 };
129
131 inline std::ostream & operator<<( std::ostream & str, const UInt & obj )
132 {
133 return obj.dumpOn( str );
134 }
135
136}
137
138#endif
Provides API related macros.
std::string asJSON() const
JSON representation.
Definition JsonNumber.h:81
std::ostream & dumpOn(std::ostream &str) const
Stream output.
Definition JsonNumber.h:85
Int & operator=(Int &&)=default
Int(Int &&)=default
Int(const Int &)=default
Int & operator=(const Int &)=default
Int(std::int64_t v)
Definition JsonNumber.h:64
~Int()=default
std::int64_t value() const
Definition JsonNumber.h:76
std::int64_t _value
Definition JsonNumber.h:89
double value() const
Definition JsonNumber.h:37
std::ostream & dumpOn(std::ostream &str) const
Stream output.
Definition JsonNumber.h:46
Number(Number &&)=default
std::string asJSON() const
JSON representation.
Definition JsonNumber.h:42
Number & operator=(const Number &)=default
Number & operator=(Number &&)=default
Number(const Number &)=default
UInt(const UInt &)=default
std::string asJSON() const
JSON representation.
Definition JsonNumber.h:119
std::ostream & dumpOn(std::ostream &str) const
Stream output.
Definition JsonNumber.h:123
std::uint64_t _value
Definition JsonNumber.h:127
UInt & operator=(UInt &&)=default
UInt(std::uint64_t v)
Definition JsonNumber.h:102
UInt(UInt &&)=default
UInt & operator=(const UInt &)=default
std::uint64_t value() const
Definition JsonNumber.h:114
String related utilities and Regular expression matching.
ZYPP_API std::ostream & operator<<(std::ostream &str, const Bool &obj)
relates: Bool Stream output
Definition JsonBool.h:59
const Arch Arch_empty ZYPP_API
relates: Arch This is an empty Arch represented by an empty string.
Definition Arch.h:173