libzypp: zypp-core/parser/json/JsonNumber.h Source File

libzypp 17.38.15

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
20 class ZYPP_API Number {
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
Globals.h
Provides API related macros.
zypp::json::Int
Definition JsonNumber.h:60
zypp::json::Int::asJSON
std::string asJSON() const
JSON representation.
Definition JsonNumber.h:81
zypp::json::Int::dumpOn
std::ostream & dumpOn(std::ostream &str) const
Stream output.
Definition JsonNumber.h:85
zypp::json::Int::operator=
Int & operator=(Int &&)=default
zypp::json::Int::Int
Int(Int &&)=default
zypp::json::Int::Int
Int(const Int &)=default
zypp::json::Int::operator=
Int & operator=(const Int &)=default
zypp::json::Int::Int
Int(std::int64_t v)
Definition JsonNumber.h:64
zypp::json::Int::~Int
~Int()=default
zypp::json::Int::value
std::int64_t value() const
Definition JsonNumber.h:76
zypp::json::Int::_value
std::int64_t _value
Definition JsonNumber.h:89
zypp::json::Int::Int
Int()=default
zypp::json::Number
Definition JsonNumber.h:20
zypp::json::Number::_value
double _value
Definition JsonNumber.h:50
zypp::json::Number::value
double value() const
Definition JsonNumber.h:37
zypp::json::Number::dumpOn
std::ostream & dumpOn(std::ostream &str) const
Stream output.
Definition JsonNumber.h:46
zypp::json::Number::Number
Number(Number &&)=default
zypp::json::Number::asJSON
std::string asJSON() const
JSON representation.
Definition JsonNumber.h:42
zypp::json::Number::~Number
~Number()=default
zypp::json::Number::Number
Number()=default
zypp::json::Number::Number
Number(double v)
Definition JsonNumber.h:24
zypp::json::Number::Number
Number(float v)
Definition JsonNumber.h:25
zypp::json::Number::operator=
Number & operator=(const Number &)=default
zypp::json::Number::operator=
Number & operator=(Number &&)=default
zypp::json::Number::Number
Number(const Number &)=default
zypp::json::UInt
Definition JsonNumber.h:98
zypp::json::UInt::UInt
UInt(const UInt &)=default
zypp::json::UInt::~UInt
~UInt()=default
zypp::json::UInt::asJSON
std::string asJSON() const
JSON representation.
Definition JsonNumber.h:119
zypp::json::UInt::dumpOn
std::ostream & dumpOn(std::ostream &str) const
Stream output.
Definition JsonNumber.h:123
zypp::json::UInt::UInt
UInt()=default
zypp::json::UInt::_value
std::uint64_t _value
Definition JsonNumber.h:127
zypp::json::UInt::operator=
UInt & operator=(UInt &&)=default
zypp::json::UInt::UInt
UInt(std::uint64_t v)
Definition JsonNumber.h:102
zypp::json::UInt::UInt
UInt(UInt &&)=default
zypp::json::UInt::operator=
UInt & operator=(const UInt &)=default
zypp::json::UInt::value
std::uint64_t value() const
Definition JsonNumber.h:114
str
String related utilities and Regular expression matching.
zypp::json
Definition TargetImpl.cc:153
zypp::json::operator<<
ZYPP_API std::ostream & operator<<(std::ostream &str, const Bool &obj)
relates: Bool Stream output
Definition JsonBool.h:59
zypp::ZYPP_API
const Arch Arch_empty ZYPP_API
relates: Arch This is an empty Arch represented by an empty string.
Definition Arch.h:173