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) Lumiera.org
5  2011, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
33 #ifndef COMMON_SEARCHPATH_H
34 #define COMMON_SEARCHPATH_H
35 
36 #include "lib/error.hpp"
37 #include "lib/nocopy.hpp"
38 
39 #include <boost/filesystem.hpp>
40 #include <string>
41 #include <regex>
42 
43 
44 namespace lib {
45 
46  using std::string;
47 
48  using SubMatch = std::smatch::value_type const&;
49 
50  namespace error = lumiera::error;
51  namespace fsys = boost::filesystem;
52 
53  using LERR_(ITER_EXHAUST);
54 
55 
57  string findExePath();
58 
61  string replaceMagicLinkerTokens (string const& src);
62 
63 
73  {
74  string pathSpec_;
75  std::sregex_iterator pos_,
76  end_;
77 
78  static const std::regex EXTRACT_PATHSPEC;
79 
80  public:
81  SearchPathSplitter (string const& searchPath)
82  : pathSpec_(replaceMagicLinkerTokens (searchPath))
83  , pos_(pathSpec_.begin(),pathSpec_.end(), EXTRACT_PATHSPEC)
84  , end_()
85  { }
86 
87  explicit operator bool() const { return isValid(); }
88 
89  bool
90  isValid() const
91  {
92  return pos_ != end_;
93  }
94 
95  string
96  next ()
97  {
98  if (!isValid())
99  throw error::Logic ("Search path exhausted."
100  ,LERR_(ITER_EXHAUST));
101 
102  string currentPathElement = pos_->str();
103  ++pos_;
104  return currentPathElement;
105  }
106  };
107 
108 
109 
118  string resolveModulePath (fsys::path moduleName, string searchPath = "");
119 
120 
121 
122 } // namespace lib
123 #endif
string findExePath()
retrieve the location of the executable
Definition: searchpath.cpp:53
Any copy and copy construction prohibited.
Definition: nocopy.hpp:46
Implementation namespace for support and library code.
string replaceMagicLinkerTokens(string const &src)
replace $ORIGIN tokens in the given string
Definition: searchpath.cpp:74
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:199
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:71
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:88