]> git.tdb.fi Git - builder.git/blob - source/virtualfilesystem.h
Comment updates
[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<std::string> SearchPath;
21
22 private:
23         typedef std::map<std::string, FileTarget *> TargetMap;
24
25         Builder &builder;
26         TargetMap targets;
27         TargetMap include_cache;
28         TargetMap library_cache;
29
30 public:
31         VirtualFileSystem(Builder &);
32
33         FileTarget *get_target(const Msp::FS::Path &) const;
34
35         /** Registers a target with the VFS.  A target may be registered at multiple
36         paths if building it results in multiple files. */
37         void register_path(const Msp::FS::Path &, FileTarget *);
38
39         /** Locates a source file.  If a file is found but no target is associated
40         with it, a new package-less target is created with the appropriate tool. */
41         FileTarget *find_header(const std::string &, const SearchPath &);
42
43         /** Locates a library.  The library name should be the same as what would be
44         used in linking with the library.  If a file is found but no target is
45         associated with it, a new package-less target of appropriate type is
46         created. */
47         FileTarget *find_library(const std::string &, const SearchPath &, LibMode);
48
49 private:
50         FileTarget *get_header(const Msp::FS::Path &, const Tool &);
51         FileTarget *get_library(const std::string &, const Msp::FS::Path &, LibMode);
52         Msp::FS::Path try_patterns(const Msp::FS::Path &, const std::list<Pattern> &, const std::string &);
53 };
54
55 #endif