libzypp  17.38.17
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 
18 namespace 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
std::uint64_t value() const
Definition: JsonNumber.h:114
std::string asJSON() const
JSON representation.
Definition: JsonNumber.h:81
Int(std::int64_t v)
Definition: JsonNumber.h:64
ZYPP_API std::ostream & operator<<(std::ostream &str, const Bool &obj)
relates: Bool Stream output
Definition: JsonBool.h:59
UInt(std::uint64_t v)
Definition: JsonNumber.h:102
std::string asJSON() const
JSON representation.
Definition: JsonNumber.h:42
String related utilities and Regular expression matching.
Edition * _value
Definition: SysContent.cc:311
std::string asJSON() const
JSON representation.
Definition: JsonNumber.h:119
const Arch Arch_empty ZYPP_API
relates: Arch This is an empty Arch represented by an empty string.
Definition: Arch.h:173
std::int64_t value() const
Definition: JsonNumber.h:76
Provides API related macros.
std::ostream & dumpOn(std::ostream &str) const
Stream output.
Definition: JsonNumber.h:85
Number(double v)
Definition: JsonNumber.h:24
std::ostream & dumpOn(std::ostream &str) const
Stream output.
Definition: JsonNumber.h:123
double value() const
Definition: JsonNumber.h:37
std::ostream & dumpOn(std::ostream &str) const
Stream output.
Definition: JsonNumber.h:46