Elements  6.2
A C++ base framework for the Euclid Software.
Auxiliary.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> // for exists
32 
33 #include "ElementsKernel/Path.h" // for Type, Item, VARIABLE
34 #include "ElementsKernel/System.h" // for DEFAULT_INSTALL_PREFIX
35 
36 using std::string;
37 
38 namespace Elements {
39 inline namespace Kernel {
40 
43 }
44 
45 // instantiation of the most expected types
46 template Path::Item getAuxiliaryPath(const Path::Item& file_name, bool raise_exception);
47 template Path::Item getAuxiliaryPath(const string& file_name, bool raise_exception);
48 
50 
52 
53  auto location_list = Path::getLocations(Path::Type::auxiliary, exist_only);
54 
55  // extended to /usr/share/aux{dir,}
56  location_list.emplace_back(Path::Item(DEFAULT_INSTALL_PREFIX) / "share" / "auxdir");
57  // for backward compatibility with the former convention
58  location_list.emplace_back(Path::Item(DEFAULT_INSTALL_PREFIX) / "share" / "aux");
59 
60  if (exist_only) {
61  auto new_end = std::remove_if(location_list.begin(), location_list.end(), [](const Path::Item& p) {
62  return (not boost::filesystem::exists(p));
63  });
64  location_list.erase(new_end, location_list.end());
65  }
66 
67  return location_list;
68 }
69 
70 namespace Auxiliary {
71 
72 string getVariableName() {
73  return getAuxiliaryVariableName();
74 }
75 
76 // instantiation of the most expected types
77 template Path::Item getPath(const Path::Item& file_name, bool raise_exception);
78 template Path::Item getPath(const std::string& file_name, bool raise_exception);
79 
81  return getAuxiliaryLocations(exist_only);
82 }
83 
84 } // namespace Auxiliary
85 
86 } // namespace Kernel
87 } // namespace Elements
Elements::Kernel::Path::Item
boost::filesystem::path Item
Definition: Path.h:56
System.h
This file is intended to iron out all the differences between systems (currently Linux and MacOSX)
Elements::Kernel::Auxiliary::getVariableName
ELEMENTS_API std::string getVariableName()
alias for the getAuxiliaryVariableName function
Definition: Auxiliary.cpp:72
std::string
STL class.
Path.h
provide functions to retrieve resources pointed by environment variables
std::vector
STL class.
Elements::Kernel::getAuxiliaryLocations
ELEMENTS_API std::vector< Path::Item > getAuxiliaryLocations(bool exist_only=false)
Definition: Auxiliary.cpp:49
Elements::Kernel::Path::getLocations
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:88
Elements::Kernel::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::Kernel::getAuxiliaryVariableName
ELEMENTS_API std::string getAuxiliaryVariableName()
retrieve the variable name used for the auxiliary file lookup
Definition: Auxiliary.cpp:41
std::remove_if
T remove_if(T... args)
Elements::Kernel::Auxiliary::getLocations
ELEMENTS_API std::vector< Path::Item > getLocations(bool exist_only=false)
alias for the getAuxiliaryLocations function
Definition: Auxiliary.cpp:80
Elements::Kernel::Path::Type::auxiliary
@ auxiliary
Elements::Kernel::getAuxiliaryPath
ELEMENTS_API Path::Item getAuxiliaryPath(const T &file_name, bool raise_exception=true)
Auxiliary.h
provide functions to retrieve auxiliary files
Elements::Kernel::Auxiliary::getPath
ELEMENTS_API Path::Item getPath(const T &file_name, bool raise_exception=true)
alias for the getAuxiliaryPath function
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
Elements
Definition: callBackExample.h:35