Elements 6.3.3
A C++ base framework for the Euclid Software.
Loading...
Searching...
No Matches
Configuration.cpp
Go to the documentation of this file.
1
22
24
25#include <algorithm> // for remove_if
26#include <map> // for map
27#include <string> // for string
28#include <vector> // for vector
29
30#include <boost/filesystem/operations.hpp> // for exists
31#include <boost/filesystem/path.hpp> // for operator/, path
32
33#include "ElementsKernel/Path.h" // for Path::VARIABLE, Path::Type
34#include "ElementsKernel/System.h" // for DEFAULT_INSTALL_PREFIX
35
36using std::string;
37
38namespace Elements {
39inline namespace Kernel {
40
44
45// Instantiation of the most expected types
46template Path::Item getConfigurationPath(const Path::Item& file_name, bool raise_exception);
47template Path::Item getConfigurationPath(const string& file_name, bool raise_exception);
48
50
51 auto location_list = Path::getLocations(Path::Type::configuration, exist_only);
52
53 // the search is extended to the default system /usr/share/conf
54 location_list.emplace_back(Path::Item(System::DEFAULT_INSTALL_PREFIX) / "share" / "conf");
55
56 if (exist_only) {
57 auto new_end = std::remove_if(location_list.begin(), location_list.end(), [](const Path::Item& p) {
58 return (not boost::filesystem::exists(p));
59 });
60 location_list.erase(new_end, location_list.end());
61 }
62
63 return location_list;
64}
65
66namespace Configuration {
67
71
72// instantiation of the most expected types
73template Path::Item getPath(const Path::Item& file_name, bool raise_exception);
74template Path::Item getPath(const std::string& file_name, bool raise_exception);
75
77 return getConfigurationLocations(exist_only);
78}
79
80} // namespace Configuration
81
82} // namespace Kernel
83} // namespace Elements
provide functions to retrieve configuration files
provide functions to retrieve resources pointed by environment variables
This file is intended to iron out all the differences between systems (currently Linux and MacOSX)
T at(T... args)
ELEMENTS_API std::string getVariableName()
alias for the getAuxiliaryVariableName function
ELEMENTS_API std::vector< Path::Item > getLocations(bool exist_only=false)
alias for the getConfigurationLocations function
ELEMENTS_API std::string getConfigurationVariableName()
retrieve the variable name used for the configuration file lookup
ELEMENTS_API const std::map< Type, const std::string > VARIABLE
map containing the name of the path variable for each type
Definition Path.cpp:48
ELEMENTS_API std::vector< Item > getLocations(const Type &path_type, bool exist_only=false)
function to get the locations for the specific type
Definition Path.cpp:100
boost::filesystem::path Item
Definition Path.h:57
ELEMENTS_API Path::Item getConfigurationPath(const T &file_name, bool raise_exception=true)
ELEMENTS_API std::vector< Path::Item > getConfigurationLocations(bool exist_only=false)
const std::string DEFAULT_INSTALL_PREFIX
constant for the canonical installation prefix (on Linux and MacOSX at least)
Definition System.h:90
T remove_if(T... args)