]> git.tdb.fi Git - builder.git/blobdiff - source/virtualfilesystem.h
Move file-to-target mapping to a separate class
[builder.git] / source / virtualfilesystem.h
diff --git a/source/virtualfilesystem.h b/source/virtualfilesystem.h
new file mode 100644 (file)
index 0000000..16f8c6d
--- /dev/null
@@ -0,0 +1,55 @@
+#ifndef VIRTUALFILESYSTEM_H_
+#define VIRTUALFILESYSTEM_H_
+
+#include <list>
+#include <map>
+#include <msp/fs/path.h>
+
+class Builder;
+class FileTarget;
+
+class VirtualFileSystem
+{
+public:
+       typedef std::list<std::string> SearchPath;
+
+private:
+       typedef std::map<std::string, FileTarget *> TargetMap;
+
+       Builder &builder;
+       TargetMap targets;
+       TargetMap include_cache;
+       TargetMap library_cache;
+
+public:
+       VirtualFileSystem(Builder &);
+
+       FileTarget *get_target(const Msp::FS::Path &) const;
+
+       void register_path(const Msp::FS::Path &, FileTarget *);
+
+       /** Tries to locate a header based on location of including file and include
+       path.  Considers known targets as well as existing files.  If a matching
+       target is not found but a file exists, a new SystemHeader target will be
+       created and returned. */
+       FileTarget *find_header(const std::string &, const Msp::FS::Path &, const SearchPath &);
+
+       /** Tries to locate a library in a library path.  The library name should be
+       the same as would be given to the linker with -l, i.e. without the "lib"
+       prefix or extension.  Considers known targets as well as existing files.  If
+       a matching target is not found but a file exists, a new SystemLibrary target
+       will be created and returned. */
+       FileTarget *find_library(const std::string &, const SearchPath &, LibMode);
+
+private:
+       /**
+       Check if a header exists, either as a target or a file.  Returns an existing
+       target of one was found, or a new SystemHeader target if there was no known
+       target but the file exists.
+       */
+       FileTarget *get_header(const Msp::FS::Path &);
+
+       FileTarget *get_library(const std::string &, const Msp::FS::Path &, LibMode);
+};
+
+#endif