Reference documentation for deal.II version 8.1.0
path_search.h
1 // ---------------------------------------------------------------------
2 // @f$Id: path_search.h 30036 2013-07-18 16:55:32Z maier @f$
3 //
4 // Copyright (C) 2005 - 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16 
17 #ifndef __deal2__path_search_h
18 #define __deal2__path_search_h
19 
20 
21 #include <deal.II/base/config.h>
23 
24 #include <string>
25 #include <fstream>
26 #include <map>
27 #include <vector>
28 #include <memory>
29 
30 
32 
90 {
91 public:
96  enum Position
97  {
104  };
105 
114  PathSearch (const std::string &cls,
115  const unsigned int debug=0);
116 
148  std::string find (const std::string &filename,
149  const char *open_mode = "r");
150 
185  std::string find (const std::string &filename,
186  const std::string &suffix,
187  const char *open_mode = "r");
188 
193  template <class STREAM>
194  void show(STREAM &stream) const;
195 
199  static void add_class (const std::string &cls);
200 
207  void add_path (const std::string &path, Position pos = back);
208 
215  void add_suffix (const std::string &suffix, Position pos = back);
216 
223  DeclException1(ExcNoClass,
224  std::string,
225  << "The class "
226  << arg1
227  << " must be registered before referring it in PathSearch");
234  DeclException2(ExcFileNotFound,
235  std::string, std::string,
236  << "The file \"" << arg1
237  << "\" was not found in the path for files of class "
238  << arg2);
239 
240 private:
245  typedef std::map<std::string, std::vector<std::string> >::value_type map_type;
246 
251  static void initialize_classes();
252 
258  static std::vector<std::string> &get_path_list(const std::string &cls);
259 
265  static std::vector<std::string> &get_suffix_list(const std::string &cls);
266 
270  const std::string cls;
271 
277  static std::map<std::string, std::vector<std::string> > path_lists;
278 
283  static std::map<std::string, std::vector<std::string> > suffix_lists;
284 
289  std::vector<std::string> &my_path_list;
290 
295  std::vector<std::string> &my_suffix_list;
296 
300  const unsigned int debug;
301 
305  static std::string empty;
306 };
307 
308 
309 /* ----------------------------- inline functions ------------------------- */
310 
311 
312 template <class STREAM>
313 inline
314 void
315 PathSearch::show(STREAM &out) const
316 {
317  out << "DEAL_II_" << cls << "PATH=\"";
318  bool first = true;
319  for (std::vector<std::string>::iterator p = my_path_list.begin();
320  p != my_path_list.end(); ++p)
321  {
322  if (!first)
323  out << ':';
324  out << *p;
325  first = false;
326  }
327  out << '"' << std::endl << " Suffixes";
328  for (std::vector<std::string>::iterator s = my_suffix_list.begin();
329  s != my_suffix_list.end(); ++s)
330  out << " \"" << *s << '"';
331  out << std::endl;
332 }
333 
334 DEAL_II_NAMESPACE_CLOSE
335 
336 #endif
337 
static std::string empty
Definition: path_search.h:305
static std::map< std::string, std::vector< std::string > > suffix_lists
Definition: path_search.h:283
static void add_class(const std::string &cls)
static std::vector< std::string > & get_suffix_list(const std::string &cls)
Add new item at front of list.
Definition: path_search.h:101
static std::vector< std::string > & get_path_list(const std::string &cls)
void add_path(const std::string &path, Position pos=back)
DeclException1(ExcNoClass, std::string,<< "The class "<< arg1<< " must be registered before referring it in PathSearch")
const unsigned int debug
Definition: path_search.h:300
Add new item at end of list.
Definition: path_search.h:99
std::vector< std::string > & my_suffix_list
Definition: path_search.h:295
const std::string cls
Definition: path_search.h:270
std::vector< std::string > & my_path_list
Definition: path_search.h:289
std::string find(const std::string &filename, const char *open_mode="r")
std::map< std::string, std::vector< std::string > >::value_type map_type
Definition: path_search.h:245
static void initialize_classes()
void add_suffix(const std::string &suffix, Position pos=back)
static std::map< std::string, std::vector< std::string > > path_lists
Definition: path_search.h:277
PathSearch(const std::string &cls, const unsigned int debug=0)
void show(STREAM &stream) const
Definition: path_search.h:315
DeclException2(ExcFileNotFound, std::string, std::string,<< "The file \""<< arg1<< "\" was not found in the path for files of class "<< arg2)
Add in path list after empty element.
Definition: path_search.h:103