/usr/include/deal.II/base/path_search.h is in libdeal.ii-dev 8.1.0-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | // ---------------------------------------------------------------------
// $Id: path_search.h 30036 2013-07-18 16:55:32Z maier $
//
// Copyright (C) 2005 - 2013 by the deal.II authors
//
// This file is part of the deal.II library.
//
// The deal.II library is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE at
// the top level of the deal.II distribution.
//
// ---------------------------------------------------------------------
#ifndef __deal2__path_search_h
#define __deal2__path_search_h
#include <deal.II/base/config.h>
#include <deal.II/base/exceptions.h>
#include <string>
#include <fstream>
#include <map>
#include <vector>
#include <memory>
DEAL_II_NAMESPACE_OPEN
/**
* Support for searching files in a list of paths and with a list of
* suffixes.
*
* A list of search paths is maintained for each file class supported.
* A file class is defined by a unique string. The classes provided are
* <dl>
* <dt> MESH <dd> mesh input files in various formats (see GridIn)
* <dt> PARAMETER <dd> Parameter files (<tt>.prm</tt>)
* </dl>
*
* Additional file classes can be added easily by using add_class().
*
* Usage: First, you construct a PathSearch object for a certain file class,
* e.g. meshes. Then, you use the find() method to obtain a full path
* name and you can open the file.
* @code
* #include <deal.II/base/path_search.h>
*
DEAL_II_NAMESPACE_OPEN
* PathSearch search("MESH");
* std::string full_name = search.find("grid");
* std::ifstream in(full_name.c_str());
* ...
* @endcode
*
* This piece of code will first traverse all paths in the list set up
* for file class <TT>MESH</tt>. If it manages to open a file, it
* returns the <tt>istream</tt> object. If not, it will try to append
* the first suffix of the suffix list and do the same. And so on. If
* no file is found in the end, an exception is thrown.
*
* If you want to restrict your search to a certain mesh format,
* <tt>.inp</tt> for instance, then either use <tt>"grid.inp"</tt> in
* the code above or use the alternative find(const std::string&,const
* std::string&,const char*) function
* @code
* std::string full_name = search.find("grid", ".inp");
* @endcode
*
* Path lists are by default starting with the current directory
* (<tt>"./"</tt>), followed optionally by a standard directory of
* deal.II. Use show() to find out the path list
* for a given class. Paths and suffixes can be added using the
* functions add_path() and add_suffix(), respectively.
*
* @note Directories in the path list should always end with a
* trailing <tt>"/"</tt>, while suffixes should always start with a
* dot. These characters are not added automatically (allowing you to
* do some real file name editing).
*
* @todo Add support for environment variables like in kpathsea.
*
* @ingroup input
* @author Guido Kanschat, Luca Heltai 2005
*/
class PathSearch
{
public:
/**
* Position for adding a new item
* to a list.
*/
enum Position
{
/// Add new item at end of list
back,
/// Add new item at front of list
front,
/// Add in path list after empty element
after_none
};
/**
* Constructor. The first argument is a
* string identifying the class of files
* to be searched for.
*
* The debug argument determines
* the verbosity of this class.
*/
PathSearch (const std::string &cls,
const unsigned int debug=0);
/**
* Find a file in the class
* specified by the constructor
* and return its complete path
* name (including a possible
* suffix).
*
* File search works by actually
* trying to open the file. If @p
* fopen is successful with the
* provided @p open_mode, then
* the file is found, otherwise
* the search continues.
*
* @warning Be careful with @p
* open_mode! In particular, use
* <tt>"w"</tt> with great care!
* If the file does not exist, it
* cannot be found. If it does
* exist, the @p fopen function
* will truncate it to zero
* length.
*
* @param filename The base
* name of the file to be found,
* without path components and
* suffix.
* @param open_mode The mode
* handed over to the @p fopen
* function.
*/
std::string find (const std::string &filename,
const char *open_mode = "r");
/**
* Find a file in the class
* specified by the constructor
* and return its complete path
* name. Do not use the standard
* suffix list, but only try to
* apply the suffix given.
*
* File search works by actually
* trying to open the file. If @p
* fopen is successful with the
* provided @p open_mode, then
* the file is found, otherwise
* the search continues.
*
* @warning Be careful with @p
* open_mode! In particular, use
* <tt>"w"</tt> with great care!
* If the file does not exist, it
* cannot be found. If it does
* exist, the @p fopen function
* will truncate it to zero
* length.
*
* @param filename The base
* name of the file to be found,
* without path components and
* suffix.
* @param suffix The suffix to be
* used for opening.
* @param open_mode The mode
* handed over to the @p fopen
* function.
*/
std::string find (const std::string &filename,
const std::string &suffix,
const char *open_mode = "r");
/**
* Show the paths and suffixes
* used for this object.
*/
template <class STREAM>
void show(STREAM &stream) const;
/**
* Add a new class.
*/
static void add_class (const std::string &cls);
/**
* Add a path to the current
* class. See
* PathSearch::Position for
* possible position arguments.
*/
void add_path (const std::string &path, Position pos = back);
/**
* Add a path to the current
* class. See
* PathSearch::Position for
* possible position arguments.
*/
void add_suffix (const std::string &suffix, Position pos = back);
/**
* This class was not
* registered in the path
* search mechanism.
* @ingroup Exceptions
*/
DeclException1(ExcNoClass,
std::string,
<< "The class "
<< arg1
<< " must be registered before referring it in PathSearch");
/**
* The PathSearch class could not
* find a file with this name in
* its path list.
* @ingroup Exceptions
*/
DeclException2(ExcFileNotFound,
std::string, std::string,
<< "The file \"" << arg1
<< "\" was not found in the path for files of class "
<< arg2);
private:
/**
* Type of values in the class
* maps.
*/
typedef std::map<std::string, std::vector<std::string> >::value_type map_type;
/**
* Initialize the static list
* objects for further use.
*/
static void initialize_classes();
/**
* Get path list for a certain
* class. Used to set up
* #my_path_list in constructor.
*/
static std::vector<std::string> &get_path_list(const std::string &cls);
/**
* Get suffix list for a certain
* class. Used to set up
* #my_suffix_list in constructor.
*/
static std::vector<std::string> &get_suffix_list(const std::string &cls);
/**
* The file class handled by this object.
*/
const std::string cls;
/**
* All path lists for all
* classes, such that we can
* build them only once.
*/
static std::map<std::string, std::vector<std::string> > path_lists;
/**
* List of suffixes for each
* class.
*/
static std::map<std::string, std::vector<std::string> > suffix_lists;
/**
* Path list for the class this
* object belongs to.
*/
std::vector<std::string> &my_path_list;
/**
* Suffix list for the class this
* object belongs to.
*/
std::vector<std::string> &my_suffix_list;
/**
* Debug flag. No output if zero.
*/
const unsigned int debug;
/**
* The empty string.
*/
static std::string empty;
};
/* ----------------------------- inline functions ------------------------- */
template <class STREAM>
inline
void
PathSearch::show(STREAM &out) const
{
out << "DEAL_II_" << cls << "PATH=\"";
bool first = true;
for (std::vector<std::string>::iterator p = my_path_list.begin();
p != my_path_list.end(); ++p)
{
if (!first)
out << ':';
out << *p;
first = false;
}
out << '"' << std::endl << " Suffixes";
for (std::vector<std::string>::iterator s = my_suffix_list.begin();
s != my_suffix_list.end(); ++s)
out << " \"" << *s << '"';
out << std::endl;
}
DEAL_II_NAMESPACE_CLOSE
#endif
|