Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
path_search.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2005 - 2019 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_path_search_h
17 #define dealii_path_search_h
18 
19 
20 #include <deal.II/base/config.h>
21 
22 #include <deal.II/base/exceptions.h>
23 
24 #include <fstream>
25 #include <map>
26 #include <memory>
27 #include <string>
28 #include <vector>
29 
30 
31 DEAL_II_NAMESPACE_OPEN
32 
85 {
86 public:
90  enum Position
91  {
98  };
99 
106  PathSearch(const std::string &cls, const unsigned int debug = 0);
107 
124  std::string
125  find(const std::string &filename, const char *open_mode = "r");
126 
145  std::string
146  find(const std::string &filename,
147  const std::string &suffix,
148  const char * open_mode = "r");
149 
153  template <class StreamType>
154  void
155  show(StreamType &stream) const;
156 
160  static void
161  add_class(const std::string &cls);
162 
167  void
168  add_path(const std::string &path, Position pos = back);
169 
174  void
175  add_suffix(const std::string &suffix, Position pos = back);
176 
182  std::string,
183  << "The class " << arg1
184  << " must be registered before referring it in PathSearch.");
191  std::string,
192  std::string,
193  << "The file \"" << arg1 << "\" was not found in the path for "
194  << "files of class " << arg2 << ".");
195 
196 private:
200  using map_type = std::map<std::string, std::vector<std::string>>::value_type;
201 
205  static void
207 
212  static std::vector<std::string> &
213  get_path_list(const std::string &cls);
214 
219  static std::vector<std::string> &
220  get_suffix_list(const std::string &cls);
221 
225  const std::string cls;
226 
230  static std::map<std::string, std::vector<std::string>> path_lists;
231 
235  static std::map<std::string, std::vector<std::string>> suffix_lists;
236 
240  std::vector<std::string> &my_path_list;
241 
245  std::vector<std::string> &my_suffix_list;
246 
250  const unsigned int debug;
251 
255  static std::string empty;
256 };
257 
258 
259 /* ----------------------------- inline functions ------------------------- */
260 
261 
262 template <class StreamType>
263 inline void
264 PathSearch::show(StreamType &out) const
265 {
266  out << "DEAL_II_" << cls << "PATH=\"";
267  bool first = true;
268  for (const auto &p : my_path_list)
269  {
270  if (!first)
271  out << ':';
272  out << p;
273  first = false;
274  }
275  out << '"' << std::endl << " Suffixes";
276  for (const auto &s : my_suffix_list)
277  out << " \"" << s << '"';
278  out << std::endl;
279 }
280 
281 DEAL_II_NAMESPACE_CLOSE
282 
283 #endif
static std::string empty
Definition: path_search.h:255
void show(StreamType &stream) const
Definition: path_search.h:264
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:541
Add in path list after empty element.
Definition: path_search.h:97
static std::map< std::string, std::vector< std::string > > path_lists
Definition: path_search.h:230
static void add_class(const std::string &cls)
Definition: path_search.cc:198
void add_path(const std::string &path, Position pos=back)
Definition: path_search.cc:214
const unsigned int debug
Definition: path_search.h:250
static std::map< std::string, std::vector< std::string > > suffix_lists
Definition: path_search.h:235
static std::vector< std::string > & get_suffix_list(const std::string &cls)
Definition: path_search.cc:87
Add new item at end of list.
Definition: path_search.h:93
std::vector< std::string > & my_suffix_list
Definition: path_search.h:245
std::map< std::string, std::vector< std::string > >::value_type map_type
Definition: path_search.h:200
static ::ExceptionBase & ExcFileNotFound(std::string arg1, std::string arg2)
const std::string cls
Definition: path_search.h:225
static void initialize_classes()
Definition: path_search.cc:33
std::vector< std::string > & my_path_list
Definition: path_search.h:240
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:518
std::string find(const std::string &filename, const char *open_mode="r")
Definition: path_search.cc:171
static ::ExceptionBase & ExcNoClass(std::string arg1)
static std::vector< std::string > & get_path_list(const std::string &cls)
Definition: path_search.cc:70
void add_suffix(const std::string &suffix, Position pos=back)
Definition: path_search.cc:232
PathSearch(const std::string &cls, const unsigned int debug=0)
Definition: path_search.cc:103
Add new item at front of list.
Definition: path_search.h:95