| 1 |
#ifndef PROTON_ERROR_CONDITION_H |
| 2 |
#define PROTON_ERROR_CONDITION_H |
| 3 |
|
| 4 |
/* |
| 5 |
* |
| 6 |
* Licensed to the Apache Software Foundation (ASF) under one |
| 7 |
* or more contributor license agreements. See the NOTICE file |
| 8 |
* distributed with this work for additional information |
| 9 |
* regarding copyright ownership. The ASF licenses this file |
| 10 |
* to you under the Apache License, Version 2.0 (the |
| 11 |
* "License"); you may not use this file except in compliance |
| 12 |
* with the License. You may obtain a copy of the License at |
| 13 |
* |
| 14 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 15 |
* |
| 16 |
* Unless required by applicable law or agreed to in writing, |
| 17 |
* software distributed under the License is distributed on an |
| 18 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 19 |
* KIND, either express or implied. See the License for the |
| 20 |
* specific language governing permissions and limitations |
| 21 |
* under the License. |
| 22 |
* |
| 23 |
*/ |
| 24 |
|
| 25 |
#include "./internal/export.hpp" |
| 26 |
#include "./value.hpp" |
| 27 |
|
| 28 |
#include <string> |
| 29 |
#include <iosfwd> |
| 30 |
|
| 31 |
/// @file |
| 32 |
/// @copybrief proton::error_condition |
| 33 |
|
| 34 |
struct pn_condition_t; |
| 35 |
|
| 36 |
namespace proton { |
| 37 |
|
| 38 |
/// Describes an endpoint error state. |
| 39 |
class error_condition { |
| 40 |
/// @cond INTERNAL |
| 41 |
error_condition(pn_condition_t* c); |
| 42 |
/// @endcond |
| 43 |
|
| 44 |
public: |
| 45 |
/// Create an empty error condition. |
| 46 |
error_condition() = default; |
| 47 |
|
| 48 |
/// Create an error condition with only a description. A default |
| 49 |
/// name will be used ("proton:io:error"). |
| 50 |
PN_CPP_EXTERN error_condition(std::string description); |
| 51 |
|
| 52 |
/// Create an error condition with a name and description. |
| 53 |
PN_CPP_EXTERN error_condition(std::string name, std::string description); |
| 54 |
|
| 55 |
/// **Unsettled API** - Create an error condition with name, |
| 56 |
/// description, and informational properties. |
| 57 |
PN_CPP_EXTERN error_condition(std::string name, std::string description, proton::value properties); |
| 58 |
|
| 59 |
/// @cond INTERNAL |
| 60 |
error_condition(const error_condition&) = default; |
| 61 |
error_condition& operator=(const error_condition&) = default; |
| 62 |
error_condition(error_condition&&) = default; |
| 63 |
error_condition& operator=(error_condition&&) = default; |
| 64 |
/// @endcond |
| 65 |
|
| 66 |
/// If you are using a C++11 compiler, you may use an |
| 67 |
/// error_condition in boolean contexts. The expression will be |
| 68 |
/// true if the error_condition is set. |
| 69 |
PN_CPP_EXTERN explicit operator bool() const; |
| 70 |
|
| 71 |
/// No condition set. |
| 72 |
PN_CPP_EXTERN bool operator!() const; |
| 73 |
|
| 74 |
/// No condition has been set. |
| 75 |
PN_CPP_EXTERN bool empty() const; |
| 76 |
|
| 77 |
/// Condition name. |
| 78 |
PN_CPP_EXTERN std::string name() const; |
| 79 |
|
| 80 |
/// Descriptive string for condition. |
| 81 |
PN_CPP_EXTERN std::string description() const; |
| 82 |
|
| 83 |
/// Extra information for condition. |
| 84 |
PN_CPP_EXTERN value properties() const; |
| 85 |
|
| 86 |
/// Simple printable string for condition. |
| 87 |
PN_CPP_EXTERN std::string what() const; |
| 88 |
|
| 89 |
private: |
| 90 |
std::string name_; |
| 91 |
std::string description_; |
| 92 |
proton::value properties_; |
| 93 |
|
| 94 |
/// @cond INTERNAL |
| 95 |
friend class internal::factory<error_condition>; |
| 96 |
/// @endcond |
| 97 |
}; |
| 98 |
|
| 99 |
/// @return true if name, description and properties are all equal |
| 100 |
PN_CPP_EXTERN bool operator==(const error_condition& x, const error_condition& y); |
| 101 |
|
| 102 |
/// Human readable string |
| 103 |
PN_CPP_EXTERN std::ostream& operator<<(std::ostream& o, const error_condition& err); |
| 104 |
|
| 105 |
} // proton |
| 106 |
|
| 107 |
#endif // PROTON_ERROR_CONDITION_H |