Loading...
Searching...
No Matches
Error.hh
Go to the documentation of this file.
1/*
2 * Copyright 2017 Open Source Robotics Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16*/
17#ifndef SDF_ERROR_HH_
18#define SDF_ERROR_HH_
19
20#include <iostream>
21#include <string>
22#include "sdf/system_util.hh"
23
24#ifdef _WIN32
25// Disable warning C4251 which is triggered by
26// std::string
27#pragma warning(push)
28#pragma warning(disable: 4251)
29#endif
30
31namespace sdf
32{
83
85 {
87 public: Error() = default;
88
93 public: Error(const ErrorCode _code, const std::string &_message);
94
98 public: ErrorCode Code() const;
99
102 public: std::string Message() const;
103
107 public: explicit operator bool() const;
108
116 public: bool operator==(const bool _value) const;
117
122 public: friend std::ostream &operator<<(std::ostream &_out,
123 const sdf::Error &_err)
124 {
125 _out << "Error Code "
126 << static_cast<std::underlying_type<sdf::ErrorCode>::type>(_err.Code())
127 << " Msg: " << _err.Message();
128 return _out;
129 }
130
132 private: ErrorCode code = ErrorCode::NONE;
133
134#ifdef _WIN32
135 // Disable warning C4251 which is triggered by
136 // std::string
137 #pragma warning(push)
138 #pragma warning(disable: 4251)
139#endif
141 private: std::string message = "";
142#ifdef _WIN32
143 #pragma warning(pop)
144#endif
145 };
146}
147#ifdef _WIN32
148#pragma warning(pop)
149#endif
150
151
152#endif
Definition Error.hh:85
std::string Message() const
Get the error message, which is a description of the error.
Error(const ErrorCode _code, const std::string &_message)
Constructor.
ErrorCode Code() const
Get the error code.
bool operator==(const bool _value) const
Compare this Error to a boolean value.
Error()=default
default constructor
friend std::ostream & operator<<(std::ostream &_out, const sdf::Error &_err)
Output operator for an error.
Definition Error.hh:122
namespace for Simulation Description Format parser
Definition Console.hh:36
ErrorCode
Set of error codes.
Definition Error.hh:40
@ ELEMENT_DEPRECATED
This error indicates that an SDF element is deprecated.
Definition Error.hh:67
@ URI_INVALID
A URI is invalid.
Definition Error.hh:75
@ DUPLICATE_NAME
A duplicate name was found for an element where unique names are required.
Definition Error.hh:49
@ ATTRIBUTE_INVALID
This error indicates that an SDF attribute is invalid.
Definition Error.hh:55
@ URI_LOOKUP
A error occured while trying to resolve a URI.
Definition Error.hh:78
@ ELEMENT_INVALID
This error indicates that an SDF element is invalid.
Definition Error.hh:64
@ DIRECTORY_NONEXISTANT
A filesystem directory does not exist.
Definition Error.hh:81
@ ELEMENT_MISSING
Indicates that a required SDF element is missing.
Definition Error.hh:61
@ FILE_READ
Indicates that reading an SDF file failed.
Definition Error.hh:45
@ ELEMENT_INCORRECT_TYPE
Indicates that an incorrect SDF element type was encountered.
Definition Error.hh:72
@ ATTRIBUTE_DEPRECATED
This error indicates that an SDF attribute is deprecated.
Definition Error.hh:58
@ NONE
Definition Error.hh:42
@ ATTRIBUTE_MISSING
Indicates that a required SDF attribute is missing.
Definition Error.hh:52
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition system_util.hh:48