Atoms Crowd  7.0.0
FileStream.h
1 // ===========================================================================
2 // Copyright (c) 2015-2024 Toolchefs Ltd. All rights reserved.
3 //
4 // Use of this software is subject to the terms of the Toolchefs license
5 // agreement provided at the time of installation or download, or which
6 // otherwise accompanies this software in either electronic or hard copy form.
7 // ===========================================================================
8 #pragma once
9 #pragma once
10 #include <ToolchefsSTL/Globals.h>
11 #include <ToolchefsSTL/String.h>
12 #include <stdio.h>
13 
14 namespace ToolchefsSTL
15 {
16  class TOOLCHEFSSTL_EXPORT FileStream
17  {
18  public:
19 
20  enum class Mode: uint8_t
21  {
22  read = 0,
23  write = 1,
24  append = 2,
25  };
26 
27  enum class SeekPosition : uint8_t
28  {
29  Start = 0,
30  Current = 1,
31  End = 2
32  };
33 
34  FileStream() noexcept;
35 
36  FileStream(const String& filePath, Mode mode = Mode::read, bool update = false, bool asBinary = true) noexcept;
37 
38  ~FileStream() noexcept;
39 
40  FileStream(FileStream&& rhs) noexcept;
41 
42  FileStream& operator=(FileStream&& rhs) noexcept;
43 
44  bool open(const String& filePath, Mode mode = Mode::read, bool update = false, bool asBinary = true);
45 
46  bool openTempFile() noexcept;
47 
48  void close() noexcept;
49 
50  bool isOpen() const noexcept;
51 
52  void seek(int64_t offset, SeekPosition pos = SeekPosition::Current) noexcept;
53 
54  int64_t tell() const noexcept;
55 
56  size_t read(void* ptr, size_t size, size_t count) const noexcept;
57 
58  size_t write(const void* ptr, size_t size, size_t count) noexcept;
59 
60  fpos_t getPos() const noexcept;
61 
62  void setPos(const fpos_t& pos) noexcept;
63 
64  size_t size() noexcept;
65 
66  FileStream& operator<<(const ToolchefsSTL::String& value);
67  FileStream& operator<<(const char* value);
68  FileStream& operator<<(const bool value);
69  FileStream& operator<<(const int8_t value);
70  FileStream& operator<<(const uint8_t value);
71  FileStream& operator<<(const int16_t value);
72  FileStream& operator<<(const uint16_t value);
73  FileStream& operator<<(const int32_t value);
74  FileStream& operator<<(const uint32_t value);
75  FileStream& operator<<(const int64_t value);
76  FileStream& operator<<(const uint64_t value);
77  FileStream& operator<<(const float value);
78  FileStream& operator<<(const double value);
79 
80  FileStream& operator>>(ToolchefsSTL::String& value);
81  FileStream& operator>>(bool& value);
82  FileStream& operator>>(int8_t& value);
83  FileStream& operator>>(uint8_t& value);
84  FileStream& operator>>(int16_t& value);
85  FileStream& operator>>(uint16_t& value);
86  FileStream& operator>>(int32_t& value);
87  FileStream& operator>>(uint32_t& value);
88  FileStream& operator>>(int64_t& value);
89  FileStream& operator>>(uint64_t& value);
90  FileStream& operator>>(float& value);
91  FileStream& operator>>(double& value);
92 
93  String getLine() noexcept;
94 
95  String readAll() noexcept;
96 
97  private:
98 
99  FileStream(const FileStream&) = delete;
100 
101  FileStream& operator=(const FileStream&) = delete;
102 
103  private:
104 
105  FILE* m_filePtr;
106  bool m_isBinary;
107  };
108 }
Definition: FileStream.h:17
Definition: String.h:19