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