Reference documentation for deal.II version 8.4.2
path_search.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2005 - 2015 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 
176  DeclException1(ExcNoClass,
177  std::string,
178  << "The class "
179  << arg1
180  << " must be registered before referring it in PathSearch");
186  DeclException2(ExcFileNotFound,
187  std::string, std::string,
188  << "The file \"" << arg1
189  << "\" was not found in the path for files of class "
190  << arg2);
191 
192 private:
196  typedef std::map<std::string, std::vector<std::string> >::value_type map_type;
197 
201  static void initialize_classes();
202 
207  static std::vector<std::string> &get_path_list(const std::string &cls);
208 
213  static std::vector<std::string> &get_suffix_list(const std::string &cls);
214 
218  const std::string cls;
219 
223  static std::map<std::string, std::vector<std::string> > path_lists;
224 
228  static std::map<std::string, std::vector<std::string> > suffix_lists;
229 
233  std::vector<std::string> &my_path_list;
234 
238  std::vector<std::string> &my_suffix_list;
239 
243  const unsigned int debug;
244 
248  static std::string empty;
249 };
250 
251 
252 /* ----------------------------- inline functions ------------------------- */
253 
254 
255 template <class StreamType>
256 inline
257 void
258 PathSearch::show(StreamType &out) const
259 {
260  out << "DEAL_II_" << cls << "PATH=\"";
261  bool first = true;
262  for (std::vector<std::string>::iterator p = my_path_list.begin();
263  p != my_path_list.end(); ++p)
264  {
265  if (!first)
266  out << ':';
267  out << *p;
268  first = false;
269  }
270  out << '"' << std::endl << " Suffixes";
271  for (std::vector<std::string>::iterator s = my_suffix_list.begin();
272  s != my_suffix_list.end(); ++s)
273  out << " \"" << *s << '"';
274  out << std::endl;
275 }
276 
277 DEAL_II_NAMESPACE_CLOSE
278 
279 #endif
280 
static std::string empty
Definition: path_search.h:248
void show(StreamType &stream) const
Definition: path_search.h:258
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:223
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
DeclException1(ExcNoClass, std::string,<< "The class "<< arg1<< " must be registered before referring it in PathSearch")
const unsigned int debug
Definition: path_search.h:243
static std::map< std::string, std::vector< std::string > > suffix_lists
Definition: path_search.h:228
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:238
const std::string cls
Definition: path_search.h:218
static void initialize_classes()
Definition: path_search.cc:33
std::vector< std::string > & my_path_list
Definition: path_search.h:233
DeclException2(ExcFileNotFound, std::string, std::string,<< "The file << arg1<< "\ was not found in the path for files of class "<< arg2)
std::string find(const std::string &filename, const char *open_mode="r")
Definition: path_search.cc:172
std::map< std::string, std::vector< std::string > >::value_type map_type
Definition: path_search.h:196
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