Vcsn  2.3a
Be Rational
file-library.hxx
Go to the documentation of this file.
1 
6 #ifndef LIBPORT_FILE_LIBRARY_HXX
7 # define LIBPORT_FILE_LIBRARY_HXX
8 
9 namespace vcsn
10 {
11 
12  template <typename ForwardRange>
13  file_library::file_library(const ForwardRange& r, const char* sep)
14  {
15  push_cwd();
16  push_back(r, sep);
17  }
18 
19  template <typename ForwardRange>
21  file_library::push_back(const ForwardRange& r, const char* sep)
22  {
23  bool inserted = false;
24  auto first = std::begin(r);
25  if (first != std::end(r))
26  {
27  if (first->empty())
28  // Insert the following search path component.
29  push_back(skip_first(r), sep);
30  else
31  for (const std::string& s: split(*first, sep))
32  {
33  if (!s.empty())
34  push_back(s);
35  else if (!inserted)
36  {
37  // Insert the following search path component.
38  push_back(skip_first(r), sep);
39  inserted = true;
40  }
41  }
42  }
43  return *this;
44  }
45 
46  template <typename Iterable>
48  file_library::push_back(const std::string& user_path,
49  const Iterable& default_path,
50  const char* sep)
51  {
52  bool inserted = false;
53  if (user_path.empty())
54  {
55  // Insert the following search path component.
56  for (const std::string& s: default_path)
57  if (!s.empty())
58  push_back(s);
59  }
60  else
61  {
62  for (const std::string& s1: split(user_path, sep))
63  {
64  if (!s1.empty())
65  push_back(s1);
66  else if (!inserted)
67  {
68  for (const std::string& s2: default_path)
69  if (!s2.empty())
70  push_back(s2);
71  inserted = true;
72  }
73  }
74  }
75  return *this;
76  }
77 
78  inline file_library&
80  {
81  return push_back(p);
82  }
83 
84  inline file_library&
86  {
87  return push_front(p);
88  }
89 
90  inline const file_library::path_list_type&
92  {
93  return search_path_;
94  }
95 
98  {
99  return search_path_;
100  }
101 
102  inline std::ostream&
103  operator<<(std::ostream& ostr, const file_library& l)
104  {
105  return l.dump(ostr);
106  }
107 }
108 
109 #endif // !LIBPORT_FILE_LIBRARY_HXX
const path_list_type & search_path_get() const
self_t & push_front(const path &p)
Definition: file-library.cc:81
std::list< path > path_list_type
Broken on Mac OS X (https://trac.macports.org/ticket/41588).
Definition: file-library.hh:29
Definition: a-star.hh:8
self_t & prepend(const path &p)
std::ostream & operator<<(std::ostream &os, direction d)
Pretty-printing.
Definition: direction.cc:19
std::ostream & dump(std::ostream &ostr) const
Manage search paths.
Definition: file-library.hh:22
path_list_type & search_path()
self_t & push_back(const path &p)
Definition: file-library.cc:65
self_t & append(const path &p)
void push_cwd()
Push the working directory on the stack.
Definition: file-library.cc:26
path_list_type search_path_
Inclusion path list.
static strings_type split(const std::string &lib, const char *sep)
Split lib at each occurrence of sep, return the list of components.
Definition: file-library.cc:52
Paths in filesystems, i.e., file names.
Definition: path.hh:21
Provide a variadic mul on top of a binary mul(), and one().
Definition: fwd.hh:46