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/sdf_config.h>
23 #include "sdf/system_util.hh"
24 
25 #ifdef _WIN32
26 // Disable warning C4251 which is triggered by
27 // std::string
28 #pragma warning(push)
29 #pragma warning(disable: 4251)
30 #endif
31 
32 namespace sdf
33 {
34  // Inline bracke to help doxygen filtering.
35  inline namespace SDF_VERSION_NAMESPACE {
36  //
37 
44  enum class ErrorCode
45  {
46  // \brief No error
47  NONE = 0,
48 
50  FILE_READ,
51 
55 
58 
61 
64 
67 
70 
73 
78 
81 
83  URI_LOOKUP,
84 
87 
90 
93  };
94 
96  {
98  public: Error() = default;
99 
104  public: Error(const ErrorCode _code, const std::string &_message);
105 
109  public: ErrorCode Code() const;
110 
113  public: std::string Message() const;
114 
118  public: explicit operator bool() const;
119 
127  public: bool operator==(const bool _value) const;
128 
133  public: friend std::ostream &operator<<(std::ostream &_out,
134  const sdf::Error &_err)
135  {
136  _out << "Error Code "
137  << static_cast<std::underlying_type<sdf::ErrorCode>::type>(_err.Code())
138  << " Msg: " << _err.Message();
139  return _out;
140  }
141 
143  private: ErrorCode code = ErrorCode::NONE;
144 
145 #ifdef _WIN32
146  // Disable warning C4251 which is triggered by
147  // std::string
148  #pragma warning(push)
149  #pragma warning(disable: 4251)
150 #endif
151  private: std::string message = "";
153 #ifdef _WIN32
154  #pragma warning(pop)
155 #endif
156  };
157  }
158 }
159 #ifdef _WIN32
160 #pragma warning(pop)
161 #endif
162 
163 
164 #endif
Indicates that reading an SDF file failed.
Indicates that reading an SDF string failed.
This error indicates that an SDF attribute is invalid.
This error indicates that an SDF element is deprecated.
A error occured while trying to resolve a URI.
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system_util.hh:48
This error indicates that an SDF element is invalid.
A duplicate name was found for an element where unique names are required.
Definition: Error.hh:95
This error indicates that an SDF attribute is deprecated.
Indicates that a required SDF attribute is missing.
Indicates that a required SDF element is missing.
ErrorCode
Set of error codes.
Definition: Error.hh:44
namespace for Simulation Description Format parser
Definition: AirPressure.hh:25
A filesystem directory does not exist.
Indicates that an incorrect SDF element type was encountered.
A link has invalid inertia.
friend std::ostream & operator<<(std::ostream &_out, const sdf::Error &_err)
Output operator for an error.
Definition: Error.hh:133