Skip to content
Snippets Groups Projects

Armem/dev

Merged Fabian Reister requested to merge armem/dev into master
All threads resolved!
3 files
+ 67
13
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -29,20 +29,38 @@
// ArmarX
#include <ArmarXCore/core/rapidxml/wrapper/RapidXmlReader.h>
#include <ArmarXCore/core/system/cmake/CMakePackageFinder.h>
#include <RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Data.h>
#include <RobotAPI/libraries/aron/core/navigator/type/NavigatorFactory.h>
namespace fs = std::filesystem;
namespace armarx::aron::xmltypereader
{
void Reader::parseFile(const std::string& filename)
void Reader::parseFile(const std::string& _filename)
{
RapidXmlReaderPtr reader = RapidXmlReader::FromFile(filename);
parse(reader);
std::string filename = _filename;
// Handle C++ style includes like "<path/to/file>".
if (!filename.empty() && filename.front() == '<' && filename.back() == '>')
{
filename = filename.substr(1, filename.size() - 2);
}
parseFile(std::filesystem::path(filename));
}
void Reader::parseFile(const std::filesystem::path& file)
void Reader::parseFile(const std::filesystem::path& _file)
{
fs::path file = _file;
if (!file.empty() && file.is_relative())
{
if (std::optional<fs::path> resolved = detail::resolveRelativePackagePath(file))
{
file = resolved.value();
}
}
RapidXmlReaderPtr reader = RapidXmlReader::FromFile(file.string());
parse(reader);
}
@@ -185,4 +203,30 @@ namespace armarx::aron::xmltypereader
return typenavigator::IntEnumNavigator::DynamicCastAndCheck(factory.create(node, Path()));
}
std::optional<fs::path> detail::resolveRelativePackagePath(const fs::path& path)
{
const std::string package = *path.begin();
armarx::CMakePackageFinder finder(package);
if (finder.packageFound())
{
for (const std::string& includePath : finder.getIncludePathList())
{
fs::path absPath = includePath / path;
if (fs::is_regular_file(absPath))
{
return absPath;
}
}
return std::nullopt;
}
else
{
return std::nullopt;
}
}
}
Loading