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

libzypp 17.38.15

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
Globals.h
Provides API related macros.
bool
zypp::json::Bool
Definition JsonBool.h:23
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:50
zypp::json::Bool::_value
bool _value
Definition JsonBool.h:54
zypp::json::Bool::Bool
Bool(Bool &&)=default
zypp::json::Bool::asJSON
std::string asJSON() const
JSON representation.
Definition JsonBool.h:46
zypp::json::Bool::Bool
Bool()=default
zypp::json::Bool::operator=
Bool & operator=(bool set)
Definition JsonBool.h:36
zypp::json::Bool::Bool
Bool(bool val)
Definition JsonBool.h:29
zypp::json::Bool::~Bool
~Bool()=default
str
String related utilities and Regular expression matching.
zypp::json
Definition TargetImpl.cc:153
zypp::json::falseJSON
static constexpr std::string_view falseJSON("false")
zypp::json::operator<<
ZYPP_API std::ostream & operator<<(std::ostream &str, const Bool &obj)
relates: Bool Stream output
Definition JsonBool.h:59
zypp::json::trueJSON
static constexpr std::string_view trueJSON("true")
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