Skip to content

Commit

Permalink
Error: move << operator from .hh to .cc file
Browse files Browse the repository at this point in the history
Signed-off-by: Steven Peters <[email protected]>
  • Loading branch information
scpeters committed Jul 13, 2021
1 parent 4e9f2eb commit 7af69a0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
24 changes: 1 addition & 23 deletions include/sdf/Error.hh
Original file line number Diff line number Diff line change
Expand Up @@ -222,29 +222,7 @@ namespace sdf
/// \param[in] _err The error to output.
/// \return Reference to the given output stream
public: friend std::ostream &operator<<(std::ostream &_out,
const sdf::Error &_err)
{
std::string pathInfo = "";

if (_err.XmlPath().has_value())
pathInfo += _err.XmlPath().value();

if (_err.FilePath().has_value())
pathInfo += ":" + _err.FilePath().value();

if (_err.LineNumber().has_value())
pathInfo += ":L" + std::to_string(_err.LineNumber().value());

if (!pathInfo.empty())
pathInfo = "[" + pathInfo + "]: ";

_out << "Error Code "
<< static_cast<std::underlying_type<sdf::ErrorCode>::type>(
_err.Code()) << ": "
<< pathInfo
<< "Msg: " << _err.Message();
return _out;
}
const sdf::Error &_err);

/// \brief Private data pointer.
IGN_UTILS_IMPL_PTR(dataPtr)
Expand Down
25 changes: 25 additions & 0 deletions src/Error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,28 @@ bool Error::operator==(const bool _value) const
return ((this->dataPtr->code != ErrorCode::NONE) && _value) ||
((this->dataPtr->code == ErrorCode::NONE) && !_value);
}

/////////////////////////////////////////////////
std::ostream &operator<<(std::ostream &_out, const sdf::Error &_err)
{
std::string pathInfo = "";

if (_err.XmlPath().has_value())
pathInfo += _err.XmlPath().value();

if (_err.FilePath().has_value())
pathInfo += ":" + _err.FilePath().value();

if (_err.LineNumber().has_value())
pathInfo += ":L" + std::to_string(_err.LineNumber().value());

if (!pathInfo.empty())
pathInfo = "[" + pathInfo + "]: ";

_out << "Error Code "
<< static_cast<std::underlying_type<sdf::ErrorCode>::type>(
_err.Code()) << ": "
<< pathInfo
<< "Msg: " << _err.Message();
return _out;
}

0 comments on commit 7af69a0

Please sign in to comment.