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

libzypp 17.38.6

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
15namespace 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
bool
zypp::json::Bool
Definition JsonBool.h:20
zypp::json::Bool::Bool
Bool(const Bool &)=default
zypp::json::Bool::operator=
Bool & operator=(const Bool &)=default
zypp::json::Bool::operator=
Bool & operator=(Bool &&)=default
zypp::json::Bool::dumpOn
std::ostream & dumpOn(std::ostream &str) const
Stream output.
Definition JsonBool.h:47
zypp::json::Bool::_value
bool _value
Definition JsonBool.h:51
zypp::json::Bool::Bool
Bool(Bool &&)=default
zypp::json::Bool::asJSON
std::string asJSON() const
JSON representation.
Definition JsonBool.h:43
zypp::json::Bool::Bool
Bool()=default
zypp::json::Bool::operator=
Bool & operator=(bool set)
Definition JsonBool.h:33
zypp::json::Bool::Bool
Bool(bool val)
Definition JsonBool.h:26
zypp::json::Bool::~Bool
~Bool()=default
str
String related utilities and Regular expression matching.
zypp::json
Definition TargetImpl.cc:152
zypp::json::falseJSON
static constexpr std::string_view falseJSON("false")
zypp::json::operator<<
std::ostream & operator<<(std::ostream &str, const Bool &obj)
relates: Bool Stream output
Definition JsonBool.h:56
zypp::json::trueJSON
static constexpr std::string_view trueJSON("true")