Elements  5.8
A C++ base framework for the Euclid Software.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Configuration.cpp
Go to the documentation of this file.
1 
24 
25 #include <algorithm> // for remove_if
26 #include <iterator>
27 #include <map>
28 #include <string> // for string
29 #include <vector> // for vector
30 
31 #include <boost/filesystem/operations.hpp>
32 #include <boost/filesystem/path.hpp>
33 
34 #include "ElementsKernel/Path.h" // for Path::VARIABLE, Path::Type
35 #include "ElementsKernel/System.h" // for DEFAULT_INSTALL_PREFIX
36 
37  // for Path::getLocationsFromEnv
38 using std::string;
40 
41 namespace Elements {
42 
45 }
46 
47 // Instantiation of the most expected types
48 template path getConfigurationPath(const path& file_name, bool raise_exception);
49 template path getConfigurationPath(const string& file_name, bool raise_exception);
50 
52 
53  auto location_list = Path::getLocationsFromEnv(Path::VARIABLE.at(Path::Type::configuration), exist_only);
54 
55  // the search is extended to the default system /usr/share/conf
56  location_list.push_back(path(System::DEFAULT_INSTALL_PREFIX) / "share" / "conf");
57 
58  if (exist_only) {
59  auto new_end = std::remove_if(location_list.begin(),
60  location_list.end(),
61  [](path p){
62  return boost::filesystem::exists(p);
63  });
64  location_list.erase(new_end, location_list.end());
65  }
66 
67  return location_list;
68 }
69 
70 } // namespace Elements
ELEMENTS_API std::string getConfigurationVariableName()
ELEMENTS_API std::vector< boost::filesystem::path > getConfigurationLocations(bool exist_only=false)
ELEMENTS_API std::vector< boost::filesystem::path > getLocationsFromEnv(const std::string &path_variable, bool exist_only=false)
function to get the locations from an environment variable
Definition: Path.cpp:79
T remove_if(T...args)
boost::filesystem::path getConfigurationPath(const T &file_name, bool raise_exception)
STL class.
This file is intended to iron out all the differences between systems (currently Linux and MacOSX) ...
boost::filesystem::path path
Definition: DataSyncUtils.h:33
ELEMENTS_API const std::map< Type, const std::string > VARIABLE
map containing the name of the path variable for each type
Definition: Path.cpp:46
STL class.
provide functions to retrieve resources pointed by environment variables
const std::string DEFAULT_INSTALL_PREFIX
constant for the canonical installation prefix (on Linux and MacOSX at least)
Definition: System.h:90
provide functions to retrieve configuration files