All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
31 namespace sdf
32 {
39  enum class ErrorCode
40  {
41  // \brief No error
42  NONE = 0,
43 
45  FILE_READ,
46 
50 
53 
56 
59 
62 
65 
68 
73 
76 
78  URI_LOOKUP,
79 
82  };
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
140  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
A URI is invalid.
A error occured while trying to resolve a URI.
Indicates that a required SDF attribute is missing.
A filesystem directory does not exist.
Definition: Error.hh:84
friend std::ostream & operator<<(std::ostream &_out, const sdf::Error &_err)
Output operator for an error.
Definition: Error.hh:122
Indicates that a required SDF element is missing.
This error indicates that an SDF element is deprecated.
std::string Message() const
Get the error message, which is a description of the error.
This error indicates that an SDF attribute is deprecated.
#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.
Indicates that reading an SDF file failed.
Indicates that an incorrect SDF element type was encountered.
This error indicates that an SDF attribute is invalid.
ErrorCode
Set of error codes.
Definition: Error.hh:39
ErrorCode Code() const
Get the error code.