Skip to content

Commit

Permalink
Merge pull request #288 from agri-gaia/versionRead-optional
Browse files Browse the repository at this point in the history
Make version number optional to ensure compatibility with legacy files
  • Loading branch information
jarkenau authored May 23, 2023
2 parents 73e3c0d + 3f74243 commit e8aeadb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class Hdf5CoreGeneral
std::string readProjectFrameId();

void writeVersion(const std::string& version);
const std::string readVersion();
const std::optional<std::string> readVersion();

// ################
// Geodetic Coordinates
Expand Down
11 changes: 7 additions & 4 deletions seerep_hdf5/seerep_hdf5_core/src/hdf5_core_general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,22 @@ void Hdf5CoreGeneral::writeVersion(const std::string& version)
}
m_file->flush();
}
const std::string Hdf5CoreGeneral::readVersion()

const std::optional<std::string> Hdf5CoreGeneral::readVersion()
{
const std::scoped_lock lock(*m_write_mtx);

std::string version;
try
{
m_file->getAttribute(VERSION).read(version);
version = readAttributeFromHdf5<std::string>(m_file->getName(), *m_file, VERSION);
}
catch (...)
catch (const std::exception& e)
{
throw std::runtime_error("Project " + m_file->getName() + " has no version defined.");
BOOST_LOG_SEV(m_logger, boost::log::trivial::severity_level::warning) << e.what();
return std::nullopt;
}

return version;
}

Expand Down
12 changes: 9 additions & 3 deletions seerep_srv/seerep_core/src/core_project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@ CoreProject::CoreProject(const boost::uuids::uuid& uuid, const std::string path)

m_projectname = m_ioGeneral->readProjectname();
m_frameId = m_ioGeneral->readProjectFrameId();
m_version = m_ioGeneral->readVersion();
/// TODO use the advantages of std::optional

/* get optional class members */
auto geodeticCoordinates = m_ioGeneral->readGeodeticLocation();
auto version = m_ioGeneral->readVersion();

if (version)
{
m_version = version.value();
}

if (geodeticCoordinates)
{
m_geodeticCoordinates = geodeticCoordinates.value();
}

recreateDatatypes();
}

CoreProject::CoreProject(const boost::uuids::uuid& uuid, const std::string path, const std::string projectname,
const std::string mapFrameId, const seerep_core_msgs::GeodeticCoordinates geodeticCoords,
const std::string version)
Expand Down

0 comments on commit e8aeadb

Please sign in to comment.