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 <optional>
23 #include <ignition/utils/ImplPtr.hh>
24 #include <sdf/sdf_config.h>
25 #include "sdf/system_util.hh"
26 
27 #ifdef _WIN32
28 // Disable warning C4251 which is triggered by
29 // std::string
30 #pragma warning(push)
31 #pragma warning(disable: 4251)
32 #endif
33 
34 namespace sdf
35 {
36  // Inline bracket to help doxygen filtering.
37  inline namespace SDF_VERSION_NAMESPACE {
38  //
39 
46  enum class ErrorCode
47  {
48  // \brief No error
49  NONE = 0,
50 
52  FILE_READ,
53 
56  DUPLICATE_NAME,
57 
59  RESERVED_NAME,
60 
62  ATTRIBUTE_MISSING,
63 
65  ATTRIBUTE_INVALID,
66 
68  ATTRIBUTE_DEPRECATED,
69 
72  ATTRIBUTE_INCORRECT_TYPE,
73 
75  ELEMENT_MISSING,
76 
78  ELEMENT_INVALID,
79 
81  ELEMENT_DEPRECATED,
82 
86  ELEMENT_INCORRECT_TYPE,
87 
89  URI_INVALID,
90 
92  URI_LOOKUP,
93 
95  DIRECTORY_NONEXISTANT,
96 
98  MODEL_CANONICAL_LINK_INVALID,
99 
101  MODEL_WITHOUT_LINK,
102 
104  NESTED_MODELS_UNSUPPORTED,
105 
107  LINK_INERTIA_INVALID,
108 
110  JOINT_CHILD_LINK_INVALID,
111 
113  JOINT_PARENT_LINK_INVALID,
114 
116  JOINT_PARENT_SAME_AS_CHILD,
117 
120  FRAME_ATTACHED_TO_INVALID,
121 
123  FRAME_ATTACHED_TO_CYCLE,
124 
126  FRAME_ATTACHED_TO_GRAPH_ERROR,
127 
130  POSE_RELATIVE_TO_INVALID,
131 
133  POSE_RELATIVE_TO_CYCLE,
134 
136  POSE_RELATIVE_TO_GRAPH_ERROR,
137 
139  STRING_READ,
140 
142  MODEL_PLACEMENT_FRAME_INVALID,
143 
145  VERSION_DEPRECATED,
146 
149  MERGE_INCLUDE_UNSUPPORTED,
150  };
151 
153  {
155  public: Error();
156 
161  public: Error(const ErrorCode _code, const std::string &_message);
162 
168  public: Error(const ErrorCode _code, const std::string &_message,
169  const std::string &_filePath);
170 
178  public: Error(const ErrorCode _code, const std::string &_message,
179  const std::string &_filePath, int _lineNumber);
180 
184  public: ErrorCode Code() const;
185 
188  public: std::string Message() const;
189 
193  public: std::optional<std::string> FilePath() const;
194 
198  public: void SetFilePath(const std::string &_filePath);
199 
202  public: std::optional<int> LineNumber() const;
203 
206  public: void SetLineNumber(int _lineNumber);
207 
211  public: std::optional<std::string> XmlPath() const;
212 
217  public: void SetXmlPath(const std::string &_xmlPath);
218 
222  public: explicit operator bool() const;
223 
231  public: bool operator==(const bool _value) const;
232 
237  public: friend SDFORMAT_VISIBLE std::ostream &operator<<(
238  std::ostream &_out, const sdf::Error &_err);
239 
241  IGN_UTILS_IMPL_PTR(dataPtr)
242  };
243  }
244 }
245 #ifdef _WIN32
246 #pragma warning(pop)
247 #endif
248 
249 
250 #endif
Definition: Error.hh:153
ErrorCode Code() const
Get the error code.
void SetLineNumber(int _lineNumber)
Sets the line number that is associated with this error.
friend std::ostream & operator<<(std::ostream &_out, const sdf::Error &_err)
Output operator for an error.
Error()
Default constructor.
Error(const ErrorCode _code, const std::string &_message, const std::string &_filePath, int _lineNumber)
Constructor.
bool operator==(const bool _value) const
Compare this Error to a boolean value.
void SetFilePath(const std::string &_filePath)
Sets the file path that is associated with this error.
std::optional< std::string > FilePath() const
Get the file path associated with this error.
std::string Message() const
Get the error message, which is a description of the error.
std::optional< std::string > XmlPath() const
Get the XPath-like trace that is associated with this error.
std::optional< int > LineNumber() const
Get the line number associated with this error.
Error(const ErrorCode _code, const std::string &_message, const std::string &_filePath)
Constructor.
void SetXmlPath(const std::string &_xmlPath)
Safe bool conversion.
Error(const ErrorCode _code, const std::string &_message)
Constructor.
ErrorCode
Set of error codes.
Definition: Error.hh:47
namespace for Simulation Description Format parser
Definition: Actor.hh:34
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system_util.hh:41