Nui
file.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <filesystem>
4 #include <string>
5 #include <functional>
6 #include <optional>
7 #include <cstdint>
8 #include <ios>
9 
10 namespace Nui
11 {
16  class AsyncFile
17  {
18  public:
19  friend void openFile(
20  char const* filename,
21  std::ios_base::openmode mode,
22  std::function<void(std::optional<AsyncFile>&&)> onOpen);
23  friend void openFile(
24  std::string const& filename,
25  std::ios_base::openmode mode,
26  std::function<void(std::optional<AsyncFile>&&)> onOpen);
27  friend void openFile(
28  std::filesystem::path const& filename,
29  std::ios_base::openmode mode,
30  std::function<void(std::optional<AsyncFile>&&)> onOpen);
31 
32  public:
33  ~AsyncFile();
34 
35  void tellg(std::function<void(int32_t)> cb) const;
36  void tellp(std::function<void(int32_t)> cb) const;
37  void seekg(int32_t pos, std::function<void()> cb, std::ios_base::seekdir dir = std::ios_base::beg);
38  void seekp(int32_t pos, std::function<void()> cb, std::ios_base::seekdir dir = std::ios_base::beg);
39 
40  void read(int32_t size, std::function<void(std::string&&)> cb);
41  void readAll(std::function<void(std::string&&)> cb);
42  void write(std::string const& data, std::function<void()> cb);
43 
44  private:
45  AsyncFile(int32_t id);
46 
47  private:
48  int32_t fileId_;
49  };
50  void openFile(
51  char const* filename,
52  std::ios_base::openmode mode,
53  std::function<void(std::optional<AsyncFile>&&)> onOpen);
54  void openFile(
55  std::string const& filename,
56  std::ios_base::openmode mode,
57  std::function<void(std::optional<AsyncFile>&&)> onOpen);
58  void openFile(
59  std::filesystem::path const& filename,
60  std::ios_base::openmode mode,
61  std::function<void(std::optional<AsyncFile>&&)> onOpen);
62 }
Do note that the use of this class is inefficient.
Definition: file.hpp:17
~AsyncFile()
Definition: file.cpp:15
void read(int32_t size, std::function< void(std::string &&)> cb)
Definition: file.cpp:45
void readAll(std::function< void(std::string &&)> cb)
Definition: file.cpp:50
void seekg(int32_t pos, std::function< void()> cb, std::ios_base::seekdir dir=std::ios_base::beg)
Definition: file.cpp:33
void write(std::string const &data, std::function< void()> cb)
Definition: file.cpp:55
void tellg(std::function< void(int32_t)> cb) const
Definition: file.cpp:23
friend void openFile(char const *filename, std::ios_base::openmode mode, std::function< void(std::optional< AsyncFile > &&)> onOpen)
Definition: file.cpp:61
void tellp(std::function< void(int32_t)> cb) const
Definition: file.cpp:28
void seekp(int32_t pos, std::function< void()> cb, std::ios_base::seekdir dir=std::ios_base::beg)
Definition: file.cpp:39
Definition: file_dialog.hpp:6
void openFile(char const *filename, std::ios_base::openmode mode, std::function< void(std::optional< AsyncFile > &&)> onOpen)
Definition: file.cpp:61