]> git.tdb.fi Git - builder.git/blob - source/virtualfilesystem.h
Move file-to-target mapping to a separate class
[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
11 class VirtualFileSystem
12 {
13 public:
14         typedef std::list<std::string> SearchPath;
15
16 private:
17         typedef std::map<std::string, FileTarget *> TargetMap;
18
19         Builder &builder;
20         TargetMap targets;
21         TargetMap include_cache;
22         TargetMap library_cache;
23
24 public:
25         VirtualFileSystem(Builder &);
26
27         FileTarget *get_target(const Msp::FS::Path &) const;
28
29         void register_path(const Msp::FS::Path &, FileTarget *);
30
31         /** Tries to locate a header based on location of including file and include
32         path.  Considers known targets as well as existing files.  If a matching
33         target is not found but a file exists, a new SystemHeader target will be
34         created and returned. */
35         FileTarget *find_header(const std::string &, const Msp::FS::Path &, const SearchPath &);
36
37         /** Tries to locate a library in a library path.  The library name should be
38         the same as would be given to the linker with -l, i.e. without the "lib"
39         prefix or extension.  Considers known targets as well as existing files.  If
40         a matching target is not found but a file exists, a new SystemLibrary target
41         will be created and returned. */
42         FileTarget *find_library(const std::string &, const SearchPath &, LibMode);
43
44 private:
45         /**
46         Check if a header exists, either as a target or a file.  Returns an existing
47         target of one was found, or a new SystemHeader target if there was no known
48         target but the file exists.
49         */
50         FileTarget *get_header(const Msp::FS::Path &);
51
52         FileTarget *get_library(const std::string &, const Msp::FS::Path &, LibMode);
53 };
54
55 #endif