TorqueScript  0.2
fileobject.hpp
1 
15 #pragma once
16 
17 #include <string>
18 #include <memory>
19 #include <unordered_map>
20 
21 #include <torquescript/consoleobject.hpp>
22 #include <torquescript/filehandlebase.hpp>
23 #include <torquescript/executionscope.hpp>
24 
25 namespace TorqueScript
26 {
31  class FileObject : public ConsoleObject
32  {
33  DECLARE_CONSOLE_OBJECT_BODY()
34 
35  public:
36  FileObject(Interpreter* interpreter);
37 
43  bool openForWrite(const std::string& path);
44 
45  bool openForRead(const std::string& path);
46 
47  bool isEOF();
48 
49  std::string readLine();
50 
56  void write(const std::string& written);
57  void close();
58 
59  static void initializeMemberFields(ConsoleObjectDescriptor* descriptor);
60 
61  static ConsoleObject* instantiateFromDescriptor(Interpreter* interpreter, ObjectInstantiationDescriptor& descriptor);
62 
63  private:
64  std::unique_ptr<FileHandleBase> mHandle;
65  };
66 
67  DECLARE_CONSOLE_OBJECT(FileObject, ConsoleObject)
68 }
Definition: consoleobject.hpp:45
Base class for object instances recognized by the interpreter. These object instances may contain mem...
Definition: consoleobject.hpp:143
A FileObject is a class that may be used to interact with the filesystem provided by the PlatformCont...
Definition: fileobject.hpp:32
void write(const std::string &written)
Writes a string to the file, if the FileObject has been opened with write mode enabled.
bool openForWrite(const std::string &path)
Opens a file at the specified path in write-only mode.
The interpreter class represents a high level instance of the TorqueScript interpreter....
Definition: interpreter.hpp:46
Definition: ast.hpp:28
Struct describing a tree of console object initializations.
Definition: executionscope.hpp:48