diff --git a/CMakeLists.txt b/CMakeLists.txt index a3320bd..5038184 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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}) + diff --git a/src/SMURFParser.cpp b/src/SMURFParser.cpp index 5dc20c5..04e9426 100644 --- a/src/SMURFParser.cpp +++ b/src/SMURFParser.cpp @@ -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 &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; +} + } diff --git a/src/SMURFParser.h b/src/SMURFParser.h index 8c8f056..2afc828 100644 --- a/src/SMURFParser.h +++ b/src/SMURFParser.h @@ -38,6 +38,8 @@ namespace smurf_parser { boost::shared_ptr 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 &absolute_conf_yml_files); + } // end of namespace smurf_parser #endif // SMURF_PARSER_H diff --git a/src/test_smurf_parser.cpp b/src/test_smurf_parser.cpp new file mode 100644 index 0000000..5d561e1 --- /dev/null +++ b/src/test_smurf_parser.cpp @@ -0,0 +1,22 @@ +#include "SMURFParser.h" +#include + +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 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: " <