Ocean
FileResolver.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_IO_FILE_RESOLVER_H
9 #define META_OCEAN_IO_FILE_RESOLVER_H
10 
11 #include "ocean/io/IO.h"
12 #include "ocean/io/Directory.h"
13 #include "ocean/io/File.h"
14 #include "ocean/io/Path.h"
15 
16 #include "ocean/base/Singleton.h"
17 
18 #include <vector>
19 
20 #include <vector>
21 
22 namespace Ocean
23 {
24 
25 namespace IO
26 {
27 
28 /**
29  * This class implements a file and url resolver.<br>
30  * This resolver is implemented as singleton.<br>
31  * However, it can be used as local object anyway.<br>
32  * @ingroup io
33  */
34 class OCEAN_IO_EXPORT FileResolver : public Singleton<FileResolver>
35 {
36  public:
37 
38  /**
39  * Creates a new resolver object.
40  * Beware: Do not use this constructor if the global resolver object is requestet.
41  */
43 
44  /**
45  * Registers the reference path.
46  * @param reference Reference path to register
47  * @return True, if the reference path is a valid absolute path
48  */
49  bool addReferencePath(const Directory& reference);
50 
51  /**
52  * Resolves the absolute paths of a file.
53  * @param file File to resolve
54  * @param checkExistence False, to return file paths even if they do not exist
55  * @return Resolved absolute file paths
56  */
57  Files resolve(const File& file, const bool checkExistence = false) const;
58 
59  /**
60  * Resolves absolute paths of several files.
61  * @param files Files to resolve
62  * @param checkExistence False, to return file paths even if they do not exist
63  * @return Resolved absolute file paths
64  */
65  Files resolve(const Files& files, const bool checkExistence = false) const;
66 
67  /**
68  * Resolves the absolute paths of a file by an additional reference path.
69  * @param file File to resolve
70  * @param reference Additional reference path
71  * @param checkExistence False, to return file paths even if they do not existh
72  * @return Resolved absolute file paths
73  */
74  Files resolve(const File& file, const Path& reference, const bool checkExistence = false) const;
75 
76  /**
77  * Resolves the absolute paths of several file by an additional reference path.
78  * @param files Files to resolve
79  * @param reference Additional reference path
80  * @param checkExistence False, to return file paths even if they do not exist
81  * @return Resolved absolute file paths
82  */
83  Files resolve(const Files& files, const Path& reference, const bool checkExistence = false) const;
84 
85  private:
86 
87  /// Registered reference paths.
89 };
90 
91 }
92 
93 }
94 
95 #endif // META_OCEAN_IO_FILE_RESOLVER_H
This class holds a directory.
Definition: Directory.h:36
This class holds a file.
Definition: File.h:36
This class implements a file and url resolver.
Definition: FileResolver.h:35
Files resolve(const File &file, const Path &reference, const bool checkExistence=false) const
Resolves the absolute paths of a file by an additional reference path.
Files resolve(const Files &files, const Path &reference, const bool checkExistence=false) const
Resolves the absolute paths of several file by an additional reference path.
Directories referencePaths
Registered reference paths.
Definition: FileResolver.h:88
FileResolver()
Creates a new resolver object.
bool addReferencePath(const Directory &reference)
Registers the reference path.
Files resolve(const File &file, const bool checkExistence=false) const
Resolves the absolute paths of a file.
Files resolve(const Files &files, const bool checkExistence=false) const
Resolves absolute paths of several files.
This class holds a path.
Definition: Path.h:27
This template class is the base class for all singleton objects.
Definition: Singleton.h:71
std::vector< Directory > Directories
Definition of a vector holding directories.
Definition: Directory.h:22
std::vector< File > Files
Definition of a vector holding files.
Definition: File.h:23
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15