]> git.tdb.fi Git - builder.git/blob - source/virtualfilesystem.h
Add documentation for VirtualFileSystem::get_target
[builder.git] / source / virtualfilesystem.h
1 #ifndef VIRTUALFILESYSTEM_H_
2 #define VIRTUALFILESYSTEM_H_
3
4 #include <list>
5 #include <map>
6 #include <msp/fs/path.h>
7
8 class Builder;
9 class FileTarget;
10 class Pattern;
11
12 /**
13 Provides access to the filesystem in a way that takes known targets into
14 account.  Thus, targets may be returned for files that do not exist yet if it's
15 possible to build them.
16 */
17 class VirtualFileSystem
18 {
19 public:
20         typedef std::list<Msp::FS::Path> SearchPath;
21
22 private:
23         typedef std::map<Msp::FS::Path, FileTarget *> TargetMap;
24
25         Builder &builder;
26         TargetMap targets;
27         std::set<Msp::FS::Path> nonexistent;
28
29 public:
30         VirtualFileSystem(Builder &);
31
32         /** Gets an existing target associated with a path.  If no target has claimed
33         that path, 0 is returned. */
34         FileTarget *get_target(const Msp::FS::Path &) const;
35
36         /** Registers a target with the VFS.  A target may be registered at multiple
37         paths if building it results in multiple files. */
38         void register_path(const Msp::FS::Path &, FileTarget *);
39
40         /** Locates a source file.  If a file is found but no target is associated
41         with it, a new package-less target is created with the appropriate tool. */
42         FileTarget *find_header(const std::string &, const SearchPath &);
43
44         /** Locates a library.  The library name should be the same as what would be
45         used in linking with the library.  If a file is found but no target is
46         associated with it, a new package-less target of appropriate type is
47         created. */
48         FileTarget *find_library(const std::string &, const SearchPath &, LibMode);
49
50 private:
51         bool file_exists(const Msp::FS::Path &);
52 };
53
54 #endif