Lumiera  0.pre.03
»edit your freedom«
searchpath.hpp
Go to the documentation of this file.
1 /*
2  SEARCHPATH.hpp - helpers for searching directory lists and locating modules
3 
4  Copyright (C)
5  2011, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 */
13 
14 
24 #ifndef COMMON_SEARCHPATH_H
25 #define COMMON_SEARCHPATH_H
26 
27 #include "lib/error.hpp"
28 #include "lib/nocopy.hpp"
29 
30 #include <boost/filesystem.hpp>
31 #include <string>
32 #include <regex>
33 
34 
35 namespace lib {
36 
37  using std::string;
38 
39  using SubMatch = std::smatch::value_type const&;
40 
41  namespace error = lumiera::error;
42  namespace fsys = boost::filesystem;
43 
44  using LERR_(ITER_EXHAUST);
45 
46 
48  string findExePath();
49 
52  string replaceMagicLinkerTokens (string const& src);
53 
54 
64  {
65  string pathSpec_;
66  std::sregex_iterator pos_,
67  end_;
68 
69  static const std::regex EXTRACT_PATHSPEC;
70 
71  public:
72  SearchPathSplitter (string const& searchPath)
73  : pathSpec_(replaceMagicLinkerTokens (searchPath))
74  , pos_(pathSpec_.begin(),pathSpec_.end(), EXTRACT_PATHSPEC)
75  , end_()
76  { }
77 
78  explicit operator bool() const { return isValid(); }
79 
80  bool
81  isValid() const
82  {
83  return pos_ != end_;
84  }
85 
86  string
87  next ()
88  {
89  if (!isValid())
90  throw error::Logic ("Search path exhausted."
91  ,LERR_(ITER_EXHAUST));
92 
93  string currentPathElement = pos_->str();
94  ++pos_;
95  return currentPathElement;
96  }
97  };
98 
99 
100 
109  string resolveModulePath (fsys::path moduleName, string searchPath = "");
110 
111 
112 
113 } // namespace lib
114 #endif
string findExePath()
retrieve the location of the executable
Definition: searchpath.cpp:44
Any copy and copy construction prohibited.
Definition: nocopy.hpp:37
Implementation namespace for support and library code.
string replaceMagicLinkerTokens(string const &src)
replace $ORIGIN tokens in the given string
Definition: searchpath.cpp:65
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:190
Mix-Ins to allow or prohibit various degrees of copying and cloning.
Lumiera error handling (C++ interface).
Helper: Access a path Specification as a sequence of filesystem Paths.
Definition: searchpath.hpp:62
string resolveModulePath(fsys::path moduleName, string searchPath)
helper to establish the location to search for loadable modules, configuration files, icons and further resources.
Definition: searchpath.cpp:79