Elements  5.8
A C++ base framework for the Euclid Software.
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::Path::Type::configuration
@ configuration
System.h
This file is intended to iron out all the differences between systems (currently Linux and MacOSX)
std::string
STL class.
Path.h
provide functions to retrieve resources pointed by environment variables
std::vector
STL class.
ElementsServices::DataSync::path
boost::filesystem::path path
Definition: DataSyncUtils.h:33
Elements::Path::getLocationsFromEnv
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
Elements::getConfigurationPath
ELEMENTS_API boost::filesystem::path getConfigurationPath(const T &file_name, bool raise_exception=true)
std::remove_if
T remove_if(T... args)
Elements::Path::VARIABLE
const ELEMENTS_API std::map< Type, const std::string > VARIABLE
map containing the name of the path variable for each type
Definition: Path.cpp:46
Elements::getConfigurationVariableName
ELEMENTS_API std::string getConfigurationVariableName()
Definition: Configuration.cpp:43
Elements::getConfigurationLocations
ELEMENTS_API std::vector< boost::filesystem::path > getConfigurationLocations(bool exist_only=false)
Definition: Configuration.cpp:51
Elements::System::DEFAULT_INSTALL_PREFIX
const std::string DEFAULT_INSTALL_PREFIX
constant for the canonical installation prefix (on Linux and MacOSX at least)
Definition: System.h:90
Configuration.h
provide functions to retrieve configuration files
Elements
Definition: Auxiliary.h:43