Reference documentation for deal.II version 9.0.0
path_search.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2005 - 2017 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 at
12 // the top level of the deal.II distribution.
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 #include <deal.II/base/exceptions.h>
22 
23 #include <string>
24 #include <fstream>
25 #include <map>
26 #include <vector>
27 #include <memory>
28 
29 
30 DEAL_II_NAMESPACE_OPEN
31 
84 {
85 public:
89  enum Position
90  {
97  };
98 
105  PathSearch (const std::string &cls,
106  const unsigned int debug=0);
107 
124  std::string find (const std::string &filename,
125  const char *open_mode = "r");
126 
145  std::string find (const std::string &filename,
146  const std::string &suffix,
147  const char *open_mode = "r");
148 
152  template <class StreamType>
153  void show(StreamType &stream) const;
154 
158  static void add_class (const std::string &cls);
159 
164  void add_path (const std::string &path, Position pos = back);
165 
170  void add_suffix (const std::string &suffix, Position pos = back);
171 
177  std::string,
178  << "The class "
179  << arg1
180  << " must be registered before referring it in PathSearch.");
187  std::string, std::string,
188  << "The file \"" << arg1 << "\" was not found in the path for "
189  << "files of class " << arg2 << ".");
190 
191 private:
195  typedef std::map<std::string, std::vector<std::string> >::value_type map_type;
196 
200  static void initialize_classes();
201 
206  static std::vector<std::string> &get_path_list(const std::string &cls);
207 
212  static std::vector<std::string> &get_suffix_list(const std::string &cls);
213 
217  const std::string cls;
218 
222  static std::map<std::string, std::vector<std::string> > path_lists;
223 
227  static std::map<std::string, std::vector<std::string> > suffix_lists;
228 
232  std::vector<std::string> &my_path_list;
233 
237  std::vector<std::string> &my_suffix_list;
238 
242  const unsigned int debug;
243 
247  static std::string empty;
248 };
249 
250 
251 /* ----------------------------- inline functions ------------------------- */
252 
253 
254 template <class StreamType>
255 inline
256 void
257 PathSearch::show(StreamType &out) const
258 {
259  out << "DEAL_II_" << cls << "PATH=\"";
260  bool first = true;
261  for (std::vector<std::string>::iterator p = my_path_list.begin();
262  p != my_path_list.end(); ++p)
263  {
264  if (!first)
265  out << ':';
266  out << *p;
267  first = false;
268  }
269  out << '"' << std::endl << " Suffixes";
270  for (std::vector<std::string>::iterator s = my_suffix_list.begin();
271  s != my_suffix_list.end(); ++s)
272  out << " \"" << *s << '"';
273  out << std::endl;
274 }
275 
276 DEAL_II_NAMESPACE_CLOSE
277 
278 #endif
279 
static std::string empty
Definition: path_search.h:247
void show(StreamType &stream) const
Definition: path_search.h:257
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:358
Add in path list after empty element.
Definition: path_search.h:96
static std::map< std::string, std::vector< std::string > > path_lists
Definition: path_search.h:222
static void add_class(const std::string &cls)
Definition: path_search.cc:202
void add_path(const std::string &path, Position pos=back)
Definition: path_search.cc:218
const unsigned int debug
Definition: path_search.h:242
static std::map< std::string, std::vector< std::string > > suffix_lists
Definition: path_search.h:227
static std::vector< std::string > & get_suffix_list(const std::string &cls)
Definition: path_search.cc:86
Add new item at end of list.
Definition: path_search.h:92
std::vector< std::string > & my_suffix_list
Definition: path_search.h:237
static ::ExceptionBase & ExcFileNotFound(std::string arg1, std::string arg2)
const std::string cls
Definition: path_search.h:217
static void initialize_classes()
Definition: path_search.cc:33
std::vector< std::string > & my_path_list
Definition: path_search.h:232
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:346
std::string find(const std::string &filename, const char *open_mode="r")
Definition: path_search.cc:172
static ::ExceptionBase & ExcNoClass(std::string arg1)
std::map< std::string, std::vector< std::string > >::value_type map_type
Definition: path_search.h:195
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:237
PathSearch(const std::string &cls, const unsigned int debug=0)
Definition: path_search.cc:101
Add new item at front of list.
Definition: path_search.h:94