From b9cf04d1fa0554f3c838b2fdf829fce314e1fbdb Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Tue, 19 Jan 2021 15:23:01 +0100 Subject: [PATCH] add function get_data_file_path() --- Installation/include/CGAL/config.h | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/Installation/include/CGAL/config.h b/Installation/include/CGAL/config.h index 76d6fd9366c..16f1eb3b87d 100644 --- a/Installation/include/CGAL/config.h +++ b/Installation/include/CGAL/config.h @@ -728,4 +728,50 @@ typedef const void * Nullptr_t; // Anticipate C++0x's std::nullptr_t /// @} #include +//----------------------------------------------------------------------// +// Function to define data directory +//----------------------------------------------------------------------// +#include +#include +#include +#include + +namespace CGAL { + +// Returns filename prefixed by the directory of CGAL containing data. +// This directory is either defined in the environement variable CGAL_DATA_DIR, +// otherwise it is taken from the constant CGAL_DATA_DIR (defined in CMake), +// otherwise it is empty (and thus returns filename unmodified). +inline std::string get_data_file_path(const char* filename) +{ + std::string res; + + const char *cgal_dir=std::getenv("CGAL_DATA_DIR"); + + if (cgal_dir!=nullptr) + { res=std::string(cgal_dir); } +#ifdef CGAL_DATA_DIR + else + { res=std::string(CGAL_DATA_DIR); } +#endif + + if (!res.empty() && res.back()!='/') + { res+=std::string("/"); } + + res+=std::string(filename); + + // Test if the file exists, write a warning otherwise + std::ifstream f(res); + if (!f) + { + std::cerr<<"[WARNING] file "<