Skip to content

Commit

Permalink
adding error parameters to Atmosphere calls
Browse files Browse the repository at this point in the history
Signed-off-by: Marco A. Gutierrez <[email protected]>
  • Loading branch information
Marco A. Gutierrez committed Oct 3, 2022
1 parent ffadff8 commit 1b1f353
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
8 changes: 8 additions & 0 deletions include/sdf/Atmosphere.hh
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ namespace sdf
/// \return SDF element pointer with updated atmosphere values.
public: sdf::ElementPtr ToElement() const;

/// \brief Create and return an SDF element filled with data from this
/// atmosphere.
/// Note that parameter passing functionality is not captured with this
/// function.
/// \param[out] _errors Vector of errors.
/// \return SDF element pointer with updated atmosphere values.
public: sdf::ElementPtr ToElement(sdf::Errors &_errors) const;

/// \brief Private data pointer.
GZ_UTILS_IMPL_PTR(dataPtr)
};
Expand Down
31 changes: 22 additions & 9 deletions src/Atmosphere.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <gz/math/Helpers.hh>
#include "sdf/Atmosphere.hh"
#include "sdf/parser.hh"
#include "Utils.hh"

using namespace sdf;

Expand Down Expand Up @@ -61,7 +62,7 @@ Errors Atmosphere::Load(ElementPtr _sdf)
}

// Read the type
std::string type = _sdf->Get<std::string>("type", "adiabatic").first;
std::string type = _sdf->Get<std::string>(errors, "type", "adiabatic").first;
if (type == "adiabatic")
{
this->dataPtr->type = AtmosphereType::ADIABATIC;
Expand All @@ -73,16 +74,17 @@ Errors Atmosphere::Load(ElementPtr _sdf)
}

// Read the temperature
this->dataPtr->temperature = _sdf->Get<double>("temperature",
this->dataPtr->temperature = _sdf->Get<double>(errors, "temperature",
this->dataPtr->temperature.Kelvin()).first;

// Read the pressure
this->dataPtr->pressure = _sdf->Get<double>("pressure",
this->dataPtr->pressure = _sdf->Get<double>(errors, "pressure",
this->dataPtr->pressure).first;

// Read the temperature gradient
this->dataPtr->temperatureGradient = _sdf->Get<double>("temperature_gradient",
this->dataPtr->temperatureGradient).first;
this->dataPtr->temperatureGradient = _sdf->Get<double>(errors,
"temperature_gradient",
this->dataPtr->temperatureGradient).first;

return errors;
}
Expand Down Expand Up @@ -148,14 +150,25 @@ bool Atmosphere::operator==(const Atmosphere &_atmosphere) const

/////////////////////////////////////////////////
sdf::ElementPtr Atmosphere::ToElement() const
{
sdf::Errors errors;
auto result = this->ToElement(errors);
sdf::throwOrPrintErrors(errors);
return result;
}

/////////////////////////////////////////////////
sdf::ElementPtr Atmosphere::ToElement(sdf::Errors &_errors) const
{
sdf::ElementPtr elem(new sdf::Element);
sdf::initFile("atmosphere.sdf", elem);

elem->GetAttribute("type")->Set("adiabatic");
elem->GetElement("temperature")->Set(this->Temperature().Kelvin());
elem->GetElement("pressure")->Set(this->Pressure());
elem->GetElement("temperature_gradient")->Set(this->TemperatureGradient());
elem->GetAttribute("type")->Set("adiabatic", _errors);
elem->GetElement("temperature", _errors)->Set(
this->Temperature().Kelvin(), _errors);
elem->GetElement("pressure", _errors)->Set(this->Pressure(), _errors);
elem->GetElement("temperature_gradient", _errors)->Set(
this->TemperatureGradient(), _errors);

return elem;
}

0 comments on commit 1b1f353

Please sign in to comment.