Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added getfile path #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
project(smurf_parser)
set(CMAKE_BUILD_TYPE Debug)

set(PROJECT_VERSION 1.0)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR} "${PROJECT_SOURCE_DIR}/cmake")
cmake_minimum_required(VERSION 2.6)
Expand Down Expand Up @@ -112,3 +114,8 @@ install(FILES ${SOURCES_H} DESTINATION include/smurf_parser)

configure_file(${PROJECT_NAME}.pc.in ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION lib/pkgconfig)


add_executable(test_smurf_parser src/test_smurf_parser.cpp ${SOURCES_H} ${TARGET_SRC} )
target_link_libraries(test_smurf_parser ${PROJECT_NAME} ${QT_LIBRARIES} ${QT_QTXML_LIBRARY} ${PKGCONFIG_LIBRARIES} ${WIN_LIBS} ${Boost_LIBRARIES})

65 changes: 65 additions & 0 deletions src/SMURFParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,69 @@ namespace smurf_parser {
return model;
}



boost::filesystem::path resolve_path( const boost::filesystem::path& p, const boost::filesystem::path& base )
{
boost::filesystem::path abs_p = boost::filesystem::absolute(p,base);
boost::filesystem::path result;
for(boost::filesystem::path::iterator it=abs_p.begin(); it!=abs_p.end(); ++it)
{
if(*it == "..")
{
// /a/b/.. is not necessarily /a if b is a symbolic link
if(boost::filesystem::is_symlink(result) )
result /= *it;
// /a/b/../.. is not /a/b/.. under most circumstances
// We can end up with ..s in our result because of symbolic links
else if(result.filename() == "..")
result /= *it;
// Otherwise it should be safe to resolve the parent
else
result = result.parent_path();
}
else if(*it == ".")
{
// Ignore
}
else
{
// Just cat other path entries
result /= *it;
}
}
return result;
}



void getFilesAbsolutePath(std::string path,configmaps::ConfigMap* map, std::string smurffilename,bool expandURIs ,std::string &absolute_urdf_path,std::string &absolute_srd_fpath, std::vector<std::string> &absolute_conf_yml_files)
{
map->append(configmaps::ConfigMap::fromYamlFile(path+smurffilename, expandURIs));
configmaps::ConfigVector::iterator it;
boost::filesystem::path abs_path_of_file;


for(it = (*map)["files"].begin(); it!=(*map)["files"].end(); ++it)
{
boost::filesystem::path filepath((std::string)(*it));
if(filepath.extension().generic_string() == ".urdf")
{
abs_path_of_file=resolve_path(filepath.generic_string(),path) ;
absolute_urdf_path=abs_path_of_file.string();
}
if(filepath.extension().generic_string() == ".srdf")
{
abs_path_of_file=resolve_path(filepath.generic_string(),path) ;
absolute_srd_fpath=abs_path_of_file.string();
}
else if(filepath.extension() == ".yml")
{
abs_path_of_file=resolve_path(filepath.generic_string(),path) ;
absolute_conf_yml_files.push_back(abs_path_of_file.string() );
}
}
return;
}

}
2 changes: 2 additions & 0 deletions src/SMURFParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ namespace smurf_parser {
boost::shared_ptr<urdf::ModelInterface> parseFile(configmaps::ConfigMap* map,
std::string path, std::string smurffilename, bool expandURIs);

void getFilesAbsolutePath(std::string path,configmaps::ConfigMap* map, std::string smurffilename,bool expandURIs ,std::string &absolute_urdf_path,std::string &absolute_srd_fpath, std::vector<std::string> &absolute_conf_yml_files);

} // end of namespace smurf_parser

#endif // SMURF_PARSER_H
22 changes: 22 additions & 0 deletions src/test_smurf_parser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "SMURFParser.h"
#include <stdio.h>

int main(int argc , char** argv)
{
std::string path="/home/basadi/Desktop/mantis.git/smurf/";
configmaps::ConfigMap* map=new configmaps::ConfigMap;
std::string smurffilename="mantis.smurf";
bool expandURIs;
std::string absolute_urdf_path;
std::string absolute_srdf_path;
std::vector<std::string> absolute_conf_yml_files;

smurf_parser::getFilesAbsolutePath(path,map,smurffilename, expandURIs, absolute_urdf_path,absolute_srdf_path,absolute_conf_yml_files);
std::cout<<"absolute_urdf_path: " <<absolute_urdf_path<<std::endl;
std::cout<<"absolute_srdf_path: " <<absolute_srdf_path<<std::endl;
for(std::size_t i=0;i<absolute_conf_yml_files.size();i++)
{
std::cout<<"absolute_conf_yml_files: " <<absolute_conf_yml_files.at(i) <<std::endl;
}

}