include/deal.II/base/path_search.h

00001 //---------------------------------------------------------------------------
00002 //    @f$Id: path_search.h 25345 2012-03-31 08:37:04Z bangerth @f$
00003 //
00004 //    Copyright (C) 2005, 2006, 2007, 2008, 2012 by the deal.II authors
00005 //
00006 //    This file is subject to QPL and may not be  distributed
00007 //    without copyright and license information. Please refer
00008 //    to the file deal.II/doc/license.html for the  text  and
00009 //    further information on this license.
00010 //
00011 //---------------------------------------------------------------------------
00012 #ifndef __deal2__path_search_h
00013 #define __deal2__path_search_h
00014 
00015 
00016 #include <deal.II/base/config.h>
00017 #include <deal.II/base/exceptions.h>
00018 
00019 #include <string>
00020 #include <fstream>
00021 #include <map>
00022 #include <vector>
00023 #include <memory>
00024 
00025 
00026 DEAL_II_NAMESPACE_OPEN
00027 
00084 class PathSearch
00085 {
00086   public:
00091     enum Position
00092     {
00094           back,
00096           front,
00098           after_none
00099     };
00100 
00109     PathSearch (const std::string& cls,
00110                 const unsigned int debug=0);
00111 
00143     std::string find (const std::string& filename,
00144                       const char* open_mode = "r");
00145 
00180     std::string find (const std::string& filename,
00181                       const std::string& suffix,
00182                       const char* open_mode = "r");
00183 
00188     template <class STREAM>
00189     void show(STREAM& stream) const;
00190 
00194     static void add_class (const std::string& cls);
00195 
00202     void add_path (const std::string& path, Position pos = back);
00203 
00210     void add_suffix (const std::string& suffix, Position pos = back);
00211 
00218     DeclException1(ExcNoClass,
00219                    std::string,
00220                    << "The class "
00221                    << arg1
00222                    << " must be registered before referring it in PathSearch");
00229     DeclException2(ExcFileNotFound,
00230                    std::string, std::string,
00231                    << "The file \"" << arg1
00232                    << "\" was not found in the path for files of class "
00233                    << arg2);
00234 
00235   private:
00240     typedef std::map<std::string, std::vector<std::string> >::value_type map_type;
00241 
00246     static void initialize_classes();
00247 
00253     static std::vector<std::string>& get_path_list(const std::string& cls);
00254 
00260     static std::vector<std::string>& get_suffix_list(const std::string& cls);
00261 
00265     const std::string cls;
00266 
00272     static std::map<std::string, std::vector<std::string> > path_lists;
00273 
00278     static std::map<std::string, std::vector<std::string> > suffix_lists;
00279 
00284     std::vector<std::string>& my_path_list;
00285 
00290     std::vector<std::string>& my_suffix_list;
00291 
00295     const unsigned int debug;
00296 
00300     static std::string empty;
00301 };
00302 
00303 
00304 /* ----------------------------- inline functions ------------------------- */
00305 
00306 
00307 template <class STREAM>
00308 inline
00309 void
00310 PathSearch::show(STREAM& out) const
00311 {
00312   out << "DEAL_II_" << cls << "PATH=\"";
00313   bool first = true;
00314   for (std::vector<std::string>::iterator p = my_path_list.begin();
00315        p != my_path_list.end(); ++p)
00316     {
00317       if (!first)
00318         out << ':';
00319       out << *p;
00320       first = false;
00321     }
00322   out << '"' << std::endl << " Suffixes";
00323   for (std::vector<std::string>::iterator s = my_suffix_list.begin();
00324        s != my_suffix_list.end(); ++s)
00325     out << " \"" << *s << '"';
00326   out << std::endl;
00327 }
00328 
00329 DEAL_II_NAMESPACE_CLOSE
00330 
00331 #endif
00332 
00333 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

deal.II documentation generated on Wed May 23 2012 06:07:31 by doxygen 1.7.3