Vcsn  2.8
Be Rational
file-library.hxx
Go to the documentation of this file.
1 
6 #include <iterator>
7 
8 namespace vcsn
9 {
10 
11  template <typename ForwardRange>
12  file_library::file_library(const ForwardRange& r, const char* sep)
13  {
14  push_cwd();
15  push_back(r, sep);
16  }
17 
18  template <typename ForwardRange>
20  file_library::push_back(const ForwardRange& r, const char* sep)
21  {
22  bool inserted = false;
23  auto first = std::begin(r);
24  if (first != std::end(r))
25  {
26  if (first->empty())
27  // Insert the following search path component.
28  push_back(skip_first(r), sep);
29  else
30  for (const std::string& s: split(*first, sep))
31  {
32  if (!s.empty())
33  push_back(s);
34  else if (!inserted)
35  {
36  // Insert the following search path component.
37  push_back(skip_first(r), sep);
38  inserted = true;
39  }
40  }
41  }
42  return *this;
43  }
44 
45  template <typename Iterable>
47  file_library::push_back(const std::string& user_path,
48  const Iterable& default_path,
49  const char* sep)
50  {
51  bool inserted = false;
52  if (user_path.empty())
53  {
54  // Insert the following search path component.
55  for (const std::string& s: default_path)
56  if (!s.empty())
57  push_back(s);
58  }
59  else
60  {
61  for (const std::string& s1: split(user_path, sep))
62  {
63  if (!s1.empty())
64  push_back(s1);
65  else if (!inserted)
66  {
67  for (const std::string& s2: default_path)
68  if (!s2.empty())
69  push_back(s2);
70  inserted = true;
71  }
72  }
73  }
74  return *this;
75  }
76 
77  inline file_library&
79  {
80  return push_back(p);
81  }
82 
83  inline file_library&
85  {
86  return push_front(p);
87  }
88 
89  inline const file_library::path_list_type&
91  {
92  return search_path_;
93  }
94 
97  {
98  return search_path_;
99  }
100 
101  inline std::ostream&
102  operator<<(std::ostream& ostr, const file_library& l)
103  {
104  return l.dump(ostr);
105  }
106 }
std::ostream & dump(std::ostream &ostr) const
self_t & prepend(const path &p)
std::ostream & operator<<(std::ostream &os, direction d)
Pretty-printing.
Definition: direction.cc:19
self_t & push_front(const path &p)
Definition: file-library.cc:82
Provide a variadic mul on top of a binary mul(), and one().
Definition: fwd.hh:46
std::list< path > path_list_type
Yes, a list is really handy here, for push/pop front.
Definition: file-library.hh:29
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:53
Definition: a-star.hh:8
void push_cwd()
Push the working directory on the stack.
Definition: file-library.cc:27
self_t & append(const path &p)
path_list_type search_path_
Inclusion path list.
Manage search paths.
Definition: file-library.hh:22
boost::filesystem::path path
Definition: file-library.hh:27
self_t & push_back(const path &p)
Definition: file-library.cc:66
const path_list_type & search_path_get() const
path_list_type & search_path()