Reference documentation for deal.II version 9.2.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
path_search.h
Go to the documentation of this file.
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 
23 
24 #include <fstream>
25 #include <map>
26 #include <memory>
27 #include <string>
28 #include <vector>
29 
30 
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 
282 
283 #endif
PathSearch::get_suffix_list
static std::vector< std::string > & get_suffix_list(const std::string &cls)
Definition: path_search.cc:87
PathSearch::Position
Position
Definition: path_search.h:90
PathSearch
Definition: path_search.h:84
PathSearch::after_none
@ after_none
Add in path list after empty element.
Definition: path_search.h:97
PathSearch::initialize_classes
static void initialize_classes()
Definition: path_search.cc:33
PathSearch::ExcFileNotFound
static ::ExceptionBase & ExcFileNotFound(std::string arg1, std::string arg2)
PathSearch::get_path_list
static std::vector< std::string > & get_path_list(const std::string &cls)
Definition: path_search.cc:70
PathSearch::front
@ front
Add new item at front of list.
Definition: path_search.h:95
PathSearch::ExcNoClass
static ::ExceptionBase & ExcNoClass(std::string arg1)
PathSearch::path_lists
static std::map< std::string, std::vector< std::string > > path_lists
Definition: path_search.h:230
PathSearch::add_suffix
void add_suffix(const std::string &suffix, Position pos=back)
Definition: path_search.cc:232
PathSearch::suffix_lists
static std::map< std::string, std::vector< std::string > > suffix_lists
Definition: path_search.h:235
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
PathSearch::cls
const std::string cls
Definition: path_search.h:225
DeclException1
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:518
PathSearch::empty
static std::string empty
Definition: path_search.h:255
PathSearch::PathSearch
PathSearch(const std::string &cls, const unsigned int debug=0)
Definition: path_search.cc:103
exceptions.h
PathSearch::add_class
static void add_class(const std::string &cls)
Definition: path_search.cc:198
PathSearch::add_path
void add_path(const std::string &path, Position pos=back)
Definition: path_search.cc:214
PathSearch::my_path_list
std::vector< std::string > & my_path_list
Definition: path_search.h:240
config.h
PathSearch::map_type
std::map< std::string, std::vector< std::string > >::value_type map_type
Definition: path_search.h:200
PathSearch::back
@ back
Add new item at end of list.
Definition: path_search.h:93
PathSearch::show
void show(StreamType &stream) const
Definition: path_search.h:264
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
PathSearch::debug
const unsigned int debug
Definition: path_search.h:250
value_type
first
Point< 2 > first
Definition: grid_out.cc:4352
PathSearch::my_suffix_list
std::vector< std::string > & my_suffix_list
Definition: path_search.h:245
PathSearch::find
std::string find(const std::string &filename, const char *open_mode="r")
Definition: path_search.cc:171
DeclException2
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:541