Debian Codegraph @

cpp/src/error_condition.cpp

raw
1 /*
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 */
21 #include "proton/error_condition.hpp"
22
23 #include <proton/condition.h>
24
25 #include "proton_bits.hpp"
26
27 #include <ostream>
28
29 namespace proton {
30
31 error_condition::error_condition(pn_condition_t* c) :
32 name_(str(pn_condition_get_name(c))),
33 description_(str(pn_condition_get_description(c))),
34 properties_(value(pn_condition_info(c)))
35 {}
36
37
38 error_condition::error_condition(std::string description) :
39 name_("proton:io:error"),
40 description_(description)
41 {}
42
43 error_condition::error_condition(std::string name, std::string description) :
44 name_(name),
45 description_(description)
46 {}
47
48 error_condition::error_condition(std::string name, std::string description, value properties) :
49 name_(name),
50 description_(description),
51 properties_(properties)
52 {}
53
54 error_condition::operator bool() const {
55 return !name_.empty();
56 }
57
58 bool error_condition::operator!() const {
59 return name_.empty();
60 }
61
62 bool error_condition::empty() const {
63 return name_.empty();
64 }
65
66 std::string error_condition::name() const {
67 return name_;
68 }
69
70 std::string error_condition::description() const {
71 return description_;
72 }
73
74 value error_condition::properties() const {
75 return properties_;
76 }
77
78 std::string error_condition::what() const {
79 if (!*this) {
80 return "No error condition";
81 } else {
82 std::string s(name_);
83 if (!description_.empty()) {
84 s += ": ";
85 s += description_;
86 }
87 return s;
88 }
89 }
90
91 bool operator==(const error_condition& x, const error_condition& y) {
92 return x.name() == y.name() && x.description() == y.description()
93 && x.properties() == y.properties();
94 }
95
96 std::ostream& operator<<(std::ostream& o, const error_condition& err) {
97 return o << err.what();
98 }
99
100 }