Reference documentation for deal.II version GIT 8ad845fa53 2023-12-10 20:50:02+00:00
\(\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 - 2022 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 
84 {
85 public:
89  enum Position
90  {
97  };
98 
105  PathSearch(const std::string &cls, const unsigned int debug = 0);
106 
123  std::string
124  find(const std::string &filename, const char *open_mode = "r");
125 
144  std::string
145  find(const std::string &filename,
146  const std::string &suffix,
147  const char *open_mode = "r");
148 
152  template <typename StreamType>
153  void
154  show(StreamType &stream) const;
155 
159  static void
160  add_class(const std::string &cls);
161 
166  void
167  add_path(const std::string &path, Position pos = back);
168 
173  void
174  add_suffix(const std::string &suffix, Position pos = back);
175 
181  std::string,
182  << "The class " << arg1
183  << " must be registered before referring it in PathSearch.");
190  std::string,
191  std::string,
192  << "The file \"" << arg1 << "\" was not found in the path for "
193  << "files of class " << arg2 << '.');
194 
195 private:
199  using map_type = std::map<std::string, std::vector<std::string>>::value_type;
200 
204  static void
206 
211  static std::vector<std::string> &
212  get_path_list(const std::string &cls);
213 
218  static std::vector<std::string> &
219  get_suffix_list(const std::string &cls);
220 
224  const std::string cls;
225 
229  static std::map<std::string, std::vector<std::string>> path_lists;
230 
234  static std::map<std::string, std::vector<std::string>> suffix_lists;
235 
239  std::vector<std::string> &my_path_list;
240 
244  std::vector<std::string> &my_suffix_list;
245 
249  const unsigned int debug;
250 
254  static std::string empty;
255 };
256 
257 
258 /* ----------------------------- inline functions ------------------------- */
259 
260 
261 template <typename StreamType>
262 inline void
263 PathSearch::show(StreamType &out) const
264 {
265  out << "DEAL_II_" << cls << "PATH=\"";
266  bool first = true;
267  for (const auto &p : my_path_list)
268  {
269  if (!first)
270  out << ':';
271  out << p;
272  first = false;
273  }
274  out << '"' << std::endl << " Suffixes";
275  for (const auto &s : my_suffix_list)
276  out << " \"" << s << '"';
277  out << std::endl;
278 }
279 
281 
282 #endif
std::string find(const std::string &filename, const char *open_mode="r")
Definition: path_search.cc:171
static std::vector< std::string > & get_path_list(const std::string &cls)
Definition: path_search.cc:70
void show(StreamType &stream) const
Definition: path_search.h:263
static std::vector< std::string > & get_suffix_list(const std::string &cls)
Definition: path_search.cc:87
static std::map< std::string, std::vector< std::string > > path_lists
Definition: path_search.h:229
const std::string cls
Definition: path_search.h:224
void add_path(const std::string &path, Position pos=back)
Definition: path_search.cc:214
std::vector< std::string > & my_suffix_list
Definition: path_search.h:244
static std::map< std::string, std::vector< std::string > > suffix_lists
Definition: path_search.h:234
static void add_class(const std::string &cls)
Definition: path_search.cc:198
const unsigned int debug
Definition: path_search.h:249
std::vector< std::string > & my_path_list
Definition: path_search.h:239
@ back
Add new item at end of list.
Definition: path_search.h:92
@ after_none
Add in path list after empty element.
Definition: path_search.h:96
@ front
Add new item at front of list.
Definition: path_search.h:94
void add_suffix(const std::string &suffix, Position pos=back)
Definition: path_search.cc:232
std::map< std::string, std::vector< std::string > >::value_type map_type
Definition: path_search.h:199
PathSearch(const std::string &cls, const unsigned int debug=0)
Definition: path_search.cc:103
static std::string empty
Definition: path_search.h:254
static void initialize_classes()
Definition: path_search.cc:33
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:477
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:478
Point< 2 > first
Definition: grid_out.cc:4614
static ::ExceptionBase & ExcNoClass(std::string arg1)
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:540
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:517
static ::ExceptionBase & ExcFileNotFound(std::string arg1, std::string arg2)