Skip to content
Snippets Groups Projects
Commit e1dd6c14 authored by Fabian Tërnava's avatar Fabian Tërnava
Browse files

added filepath to read methods

parent 40652c9f
No related branches found
No related tags found
No related merge requests found
......@@ -130,7 +130,7 @@ namespace armarx::aron::typereader::xml
{
for (const auto& include : (*codeincludes).nodes())
{
auto i = readCodeInclude(include, includePaths);
auto i = readCodeInclude(include, filePath.parent_path(), includePaths);
if (not i.empty()) this->systemIncludes.push_back(i);
}
}
......@@ -140,7 +140,7 @@ namespace armarx::aron::typereader::xml
{
for (const auto& include : (*aronincludes).nodes())
{
auto i = readAronInclude(include, includePaths);
auto i = readAronInclude(include, filePath.parent_path(), includePaths);
if (not i.empty()) this->aronIncludes.push_back(i);
}
}
......@@ -152,7 +152,7 @@ namespace armarx::aron::typereader::xml
{
if (util::HasTagName(include, constantes::SYSTEM_INCLUDE_TAG)) // if its a system include tag then we know that it must be a code include
{
auto i = readCodeInclude(include, includePaths);
auto i = readCodeInclude(include, filePath.parent_path(), includePaths);
if (not i.empty()) this->systemIncludes.push_back(i);
}
else
......@@ -174,12 +174,12 @@ namespace armarx::aron::typereader::xml
{
if (what.ends_with(ARON_FILE_SUFFIX))
{
auto i = readAronInclude(include, includePaths);
auto i = readAronInclude(include, filePath.parent_path(), includePaths);
if (not i.empty()) this->aronIncludes.push_back(i);
}
else // we believe that this is a code include since it is not an xml file
{
auto i = readCodeInclude(include, includePaths);
auto i = readCodeInclude(include, filePath.parent_path(), includePaths);
if (not i.empty()) this->systemIncludes.push_back(i);
}
}
......@@ -194,15 +194,14 @@ namespace armarx::aron::typereader::xml
{
if (util::HasTagName(generateType, constantes::OBJECT_TAG))
{
for (const auto& additionalInclude : getAdditionalIncludesFromReplacements(generateType, filePath))
for (const auto& additionalInclude : getAdditionalIncludesFromReplacements(generateType, filePath.parent_path()))
{
RapidXmlReaderPtr reader = RapidXmlReader::FromXmlString("<PackagePath package=\""+additionalInclude.first+"\" path=\""+additionalInclude.second+"\"/>");
auto node = reader->getRoot();
auto i = this->readAronInclude(node, includePaths);
auto i = this->readAronInclude(node, filePath, includePaths);
if (not i.empty() && std::find(this->aronIncludes.begin(), this->aronIncludes.end(), i) == this->aronIncludes.end())
{
std::cout << "OUT IS: " << i << std::endl;
this->aronIncludes.push_back(i);
}
}
......@@ -237,7 +236,7 @@ namespace armarx::aron::typereader::xml
}
}
std::pair<std::string, std::string> Reader::readPackagePathInclude(const RapidXmlReaderNode& node, const std::vector<std::filesystem::path>& includePaths)
std::pair<std::string, std::string> Reader::readPackagePathInclude(const RapidXmlReaderNode& node, const std::filesystem::path&, const std::vector<std::filesystem::path>& includePaths)
{
util::EnforceTagName(node, constantes::PACKAGE_PATH_TAG);
std::string package = util::GetAttribute(node, constantes::PACKAGE_ATTRIBUTE_NAME);
......@@ -258,7 +257,7 @@ namespace armarx::aron::typereader::xml
throw error::AronException(__PRETTY_FUNCTION__, "Could not find an file `" + includepath.string() + "`. Search paths are: " + simox::alg::to_string(includePaths));
}
std::pair<std::string, std::string> Reader::readInclude(const RapidXmlReaderNode& node, const std::vector<std::filesystem::path>& includePaths)
std::pair<std::string, std::string> Reader::readInclude(const RapidXmlReaderNode& node, const std::filesystem::path& filepath, const std::vector<std::filesystem::path>& includePaths)
{
util::EnforceTagName(node, constantes::INCLUDE_TAG);
std::string value = util::GetAttribute(node, constantes::INCLUDE_ATTRIBUTE_NAME);
......@@ -267,10 +266,10 @@ namespace armarx::aron::typereader::xml
value = simox::alg::replace_all(value, "<", "");
value = simox::alg::replace_all(value, ">", "");
return {value, "\"" + value + "\""};
return {value, "<" + value + ">"};
}
std::pair<std::string, std::string> Reader::readSystemInclude(const RapidXmlReaderNode& node, const std::vector<std::filesystem::path>& includePaths)
std::pair<std::string, std::string> Reader::readSystemInclude(const RapidXmlReaderNode& node, const std::filesystem::path&, const std::vector<std::filesystem::path>& includePaths)
{
util::EnforceTagName(node, constantes::SYSTEM_INCLUDE_TAG);
std::string value = util::GetAttribute(node, constantes::INCLUDE_ATTRIBUTE_NAME);
......@@ -279,41 +278,41 @@ namespace armarx::aron::typereader::xml
value = simox::alg::replace_all(value, "<", "");
value = simox::alg::replace_all(value, ">", "");
return {value, "<" + value + ">"};
return {"", "<" + value + ">"};
}
std::string Reader::readCodeInclude(const RapidXmlReaderNode& node, const std::vector<std::filesystem::path>& includePaths)
std::string Reader::readCodeInclude(const RapidXmlReaderNode& node, const std::filesystem::path& filepath, const std::vector<std::filesystem::path>& includePaths)
{
if (util::HasTagName(node, constantes::PACKAGE_PATH_TAG))
{
return readPackagePathInclude(node, includePaths).second;
return readPackagePathInclude(node, filepath, includePaths).second;
}
if (util::HasTagName(node, constantes::INCLUDE_TAG))
{
return readInclude(node, includePaths).second;
return readInclude(node, filepath, includePaths).second;
}
if (util::HasTagName(node, constantes::SYSTEM_INCLUDE_TAG))
{
return readSystemInclude(node, includePaths).second;
return readSystemInclude(node, filepath, includePaths).second;
}
throw error::ValueNotValidException(__PRETTY_FUNCTION__, "Could not parse a code include. The tag is wrong.", node.name());
}
std::string Reader::readAronInclude(const RapidXmlReaderNode& node, const std::vector<std::filesystem::path>& includePaths)
std::string Reader::readAronInclude(const RapidXmlReaderNode& node, const std::filesystem::path& filepath, const std::vector<std::filesystem::path>& includePaths)
{
std::string include;
std::string orig_include;
std::string include_unescaped;
if (util::HasTagName(node, constantes::PACKAGE_PATH_TAG))
{
auto p = readPackagePathInclude(node, includePaths);
orig_include = p.first;
auto p = readPackagePathInclude(node, filepath, includePaths);
include_unescaped = p.first;
include = p.second;
}
if (util::HasTagName(node, constantes::INCLUDE_TAG))
{
auto p = readInclude(node, includePaths);
orig_include = p.first;
auto p = readInclude(node, filepath, includePaths);
include_unescaped = p.first;
include = p.second;
}
......@@ -325,7 +324,7 @@ namespace armarx::aron::typereader::xml
// parse parent xml file and add objects to alreday known
Reader anotherReader;
anotherReader.parseFile(orig_include, includePaths);
anotherReader.parseFile(include_unescaped, includePaths);
for (const auto& previouslyKnown : anotherReader.factory.allPreviouslyKnownPublicTypes)
{
factory.allPreviouslyKnownPublicTypes.push_back(previouslyKnown);
......
......@@ -60,12 +60,12 @@ namespace armarx::aron::typereader::xml
std::vector<std::pair<std::string, std::string>> getAdditionalIncludesFromReplacements(const RapidXmlReaderNode& node, const std::filesystem::path& filePath);
// parse includes
std::pair<std::string, std::string> readPackagePathInclude(const RapidXmlReaderNode& node, const std::vector<std::filesystem::path>& includePaths);
std::pair<std::string, std::string> readInclude(const RapidXmlReaderNode& node, const std::vector<std::filesystem::path>& includePaths);
std::pair<std::string, std::string> readSystemInclude(const RapidXmlReaderNode& node, const std::vector<std::filesystem::path>& includePaths);
std::pair<std::string, std::string> readPackagePathInclude(const RapidXmlReaderNode& node, const std::filesystem::path& filename, const std::vector<std::filesystem::path>& includePaths);
std::pair<std::string, std::string> readInclude(const RapidXmlReaderNode& node, const std::filesystem::path& filename, const std::vector<std::filesystem::path>& includePaths);
std::pair<std::string, std::string> readSystemInclude(const RapidXmlReaderNode& node, const std::filesystem::path& filename, const std::vector<std::filesystem::path>& includePaths);
std::string readCodeInclude(const RapidXmlReaderNode& node, const std::vector<std::filesystem::path>& includePaths);
std::string readAronInclude(const RapidXmlReaderNode& node, const std::vector<std::filesystem::path>& includePaths);
std::string readCodeInclude(const RapidXmlReaderNode& node, const std::filesystem::path& filename, const std::vector<std::filesystem::path>& includePaths);
std::string readAronInclude(const RapidXmlReaderNode& node, const std::filesystem::path& filename, const std::vector<std::filesystem::path>& includePaths);
// parse top-level objects
type::ObjectPtr readGenerateObject(const RapidXmlReaderNode& node);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment