Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fresolver.h
Go to the documentation of this file.
1 /*
2  This file is part of Mitsuba, a physically based rendering system.
3 
4  Copyright (c) 2007-2014 by Wenzel Jakob and others.
5 
6  Mitsuba is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License Version 3
8  as published by the Free Software Foundation.
9 
10  Mitsuba is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 #if !defined(__MITSUBA_CORE_FRESOLVER_H_)
21 #define __MITSUBA_CORE_FRESOLVER_H_
22 
23 #include <mitsuba/mitsuba.h>
24 #include <boost/filesystem.hpp>
25 #include <boost/filesystem/fstream.hpp>
26 #include <deque>
27 
29 
30 /**
31  * \brief File resolution helper
32  *
33  * FileResolver is a convenience class that allows searching for files
34  * within a set of specifiable search paths in a cross-platform
35  * compatible manner (similar to the $PATH variable on various
36  * operating systems).
37  *
38  * \ingroup libcore
39  * \ingroup libpython
40  */
42 public:
43  /**
44  * \brief Create a new file resolver with the default settings
45  *
46  * Create a new file resolver containing the current working
47  * directory as the initial search path.
48  */
49  FileResolver();
50 
51  /**
52  * \brief Resolve a file using the stored list of search paths
53  *
54  * Go through the list of search paths and try to resolve the
55  * supplied path with respect to each one. If everything fails,
56  * the path is returned as-is.
57  */
58  fs::path resolve(const fs::path &path) const;
59 
60  /**
61  * \brief Resolve a file using the stored list of search paths
62  *
63  * In comparison to \ref resolve(), this funtion returns all
64  * matches instead of only the first one.
65  */
66  std::vector<fs::path> resolveAll(const fs::path &path) const;
67 
68  /**
69  * \brief Does the same as \ref resolve(), but returns an
70  * absolute path.
71  */
72  fs::path resolveAbsolute(const fs::path &path) const;
73 
74  /// Create a clone of the file resolver
75  FileResolver *clone() const;
76 
77  /// Append a search path to the resolver
78  void appendPath(const fs::path &path);
79 
80  /// Prepend a search path to the resolver
81  void prependPath(const fs::path &path);
82 
83  /// Clear all stored search paths
84  void clear();
85 
86  /// Return the number of stored paths
87  inline size_t getPathCount() const { return m_paths.size(); }
88 
89  /// Return one of the stored paths
90  inline const fs::path &getPath(size_t index) const { return m_paths[index]; }
91 
92  /// Return a human-readable string representation
93  std::string toString() const;
94 
96 protected:
97  virtual ~FileResolver() { }
98 private:
99  std::deque<fs::path> m_paths;
100 };
101 
103 
104 #endif /* __MITSUBA_CORE_FRESOLVER_H_ */
#define MTS_EXPORT_CORE
Definition: getopt.h:29
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
File resolution helper.
Definition: fresolver.h:41
const fs::path & getPath(size_t index) const
Return one of the stored paths.
Definition: fresolver.h:90
#define MTS_DECLARE_CLASS()
This macro must be used in the initial definition in classes that derive from Object.
Definition: class.h:158
Parent of all Mitsuba classes.
Definition: object.h:38
size_t getPathCount() const
Return the number of stored paths.
Definition: fresolver.h:87
virtual std::string toString() const
Return a human-readable string representation of the object&#39;s contents.
#define MTS_NAMESPACE_END
Definition: platform.h:138