1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#pragma once
#include <pybind11/pybind11.h>
#include "iscript.h"
#include "iscriptinterface.h"
#include "ifilesystem.h"
namespace script
{
/**
* Adaptor interface for a VFS traversor object.
*/
class VirtualFileSystemVisitor
{
public:
virtual ~VirtualFileSystemVisitor() {}
/**
* Required visit method. Takes the filename is relative
* to the base path passed to the GlobalFileSystem().foreachFile method.
*/
virtual void visit(const std::string& filename) = 0;
};
// Scripts will derive from this class
class FileVisitorWrapper :
public VirtualFileSystemVisitor
{
public:
void visit(const std::string& filename) override
{
// Wrap this method to python
PYBIND11_OVERLOAD_PURE(
void, /* Return type */
VirtualFileSystemVisitor, /* Parent class */
visit, /* Name of function in C++ (must match Python name) */
filename /* Argument(s) */
);
}
};
/**
* greebo: This class registers the VFS interface with the
* scripting system.
*/
class FileSystemInterface :
public IScriptInterface
{
public:
// Reads a text file and returns the contents to the script
// Filename is a VFS path, not an absolute OS path
// Returns an empty string if not found
std::string readTextFile(const std::string& filename);
// Wrapped methods, see "ifilesystem.h" for documentation
void forEachFile(const std::string& basedir, const std::string& extension,
VirtualFileSystemVisitor& visitor, std::size_t depth);
int getFileCount(const std::string& filename);
std::string findFile(const std::string& name);
std::string findRoot(const std::string& name);
// IScriptInterface implementation
void registerInterface(py::module& scope, py::dict& globals) override;
};
} // namespace script
|