libzypp  17.37.5
JsonBool.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
9 #ifndef ZYPP_CORE_PARSER_JSON_JSON_BOOL_DEFINED
10 #define ZYPP_CORE_PARSER_JSON_JSON_BOOL_DEFINED
11 
12 #include <string_view>
13 #include <string>
14 
15 namespace zypp::json {
16 
17  static constexpr std::string_view trueJSON("true");
18  static constexpr std::string_view falseJSON("false");
19 
20  class Bool {
21 
22  public:
23  Bool() = default; //default false
24  ~Bool() = default;
25 
26  Bool( bool val ) : _value(val) {}
27 
28  Bool( const Bool & ) = default;
29  Bool( Bool && ) = default;
30  Bool &operator=(const Bool &) = default;
31  Bool &operator=(Bool &&) = default;
32 
33  Bool &operator=(bool set ) {
34  _value = set;
35  return *this;
36  }
37 
38  operator bool() const {
39  return _value;
40  }
41 
43  std::string asJSON() const
44  { return std::string(_value ? trueJSON : falseJSON); }
45 
47  std::ostream & dumpOn( std::ostream & str ) const
48  { return str << (_value ? trueJSON : falseJSON); }
49 
50  private:
51  bool _value = false;
52 
53  };
54 
56  inline std::ostream & operator<<( std::ostream & str, const Bool & obj )
57  {
58  return obj.dumpOn( str );
59  }
60 }
61 
62 #endif
String related utilities and Regular expression matching.
std::ostream & dumpOn(std::ostream &str) const
Stream output.
Definition: JsonBool.h:47
Bool & operator=(const Bool &)=default
std::string asJSON() const
JSON representation.
Definition: JsonBool.h:43
Bool(bool val)
Definition: JsonBool.h:26
Bool & operator=(bool set)
Definition: JsonBool.h:33
static constexpr std::string_view trueJSON("true")
std::ostream & operator<<(std::ostream &str, const Bool &obj)
Definition: JsonBool.h:56
static constexpr std::string_view falseJSON("false")