libzypp 17.38.14
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#include <ostream>
15
16#include <zypp-core/Globals.h>
17
18namespace zypp::json {
19
20 static constexpr std::string_view trueJSON("true");
21 static constexpr std::string_view falseJSON("false");
22
23 class ZYPP_API Bool {
24
25 public:
26 Bool() = default; //default false
27 ~Bool() = default;
28
29 Bool( bool val ) : _value(val) {}
30
31 Bool( const Bool & ) = default;
32 Bool( Bool && ) = default;
33 Bool &operator=(const Bool &) = default;
34 Bool &operator=(Bool &&) = default;
35
36 Bool &operator=(bool set ) {
37 _value = set;
38 return *this;
39 }
40
41 operator bool() const {
42 return _value;
43 }
44
46 std::string asJSON() const
47 { return std::string(_value ? trueJSON : falseJSON); }
48
50 std::ostream & dumpOn( std::ostream & str ) const
51 { return str << (_value ? trueJSON : falseJSON); }
52
53 private:
54 bool _value = false;
55
56 };
57
59 inline ZYPP_API std::ostream & operator<<( std::ostream & str, const Bool & obj )
60 {
61 return obj.dumpOn( str );
62 }
63}
64
65#endif
Provides API related macros.
Bool(const Bool &)=default
Bool & operator=(const Bool &)=default
Bool & operator=(Bool &&)=default
std::ostream & dumpOn(std::ostream &str) const
Stream output.
Definition JsonBool.h:50
Bool(Bool &&)=default
std::string asJSON() const
JSON representation.
Definition JsonBool.h:46
Bool & operator=(bool set)
Definition JsonBool.h:36
Bool(bool val)
Definition JsonBool.h:29
String related utilities and Regular expression matching.
static constexpr std::string_view falseJSON("false")
ZYPP_API std::ostream & operator<<(std::ostream &str, const Bool &obj)
relates: Bool Stream output
Definition JsonBool.h:59
static constexpr std::string_view trueJSON("true")
const Arch Arch_empty ZYPP_API
relates: Arch This is an empty Arch represented by an empty string.
Definition Arch.h:173