Melon
A C++ library designed for RadishOS.
Loading...
Searching...
No Matches
File.hpp
1#pragma once
2
3#include "../../String.hpp"
4#include "../Memory/Buffer.hpp"
5
6#include <stdio.h>
7
8namespace Melon::FileSystem
9{
11 enum class SeekOrigin
12 {
13 Begin = SEEK_SET,
14 Curr = SEEK_CUR,
15 End = SEEK_END
16 };
17
19 class File
20 {
21 FILE *stream;
22
23 public:
27 File(const String::String &path, const String::String &modes);
28
31 File(FILE *stream);
32
34 ~File();
35
37 void close(this File &self);
38
43
46 Memory::Buffer<char> read(this File &self);
47
53 String::String readLine(this File &self, Typing::USize lineno);
54
57 int descriptor(this const File &self);
58
62 void seek(this File &self, long offset, SeekOrigin origin);
63
67 void write(this File &self, const Memory::Buffer<char> &buf, Typing::USize bytes);
68
73 bool isOpen(this const File &self);
74 };
75} // namespace Melon::FileSystem
int descriptor(this const File &self)
Gets the file descriptor of this stream.
Definition File.cpp:88
Memory::Buffer< char > read(this File &self)
Read until EOF.
Definition File.cpp:51
void close(this File &self)
Close the file if it is open.
Definition File.cpp:32
File(const String::String &path, const String::String &modes)
Open constructor.
Definition File.cpp:13
void seek(this File &self, long offset, SeekOrigin origin)
Seek to a certain position in the file.
Definition File.cpp:93
String::String readLine(this File &self, Typing::USize lineno)
Read a line from the file.
Definition File.cpp:64
bool isOpen(this const File &self)
Checks if the file is open.
Definition File.cpp:103
void write(this File &self, const Memory::Buffer< char > &buf, Typing::USize bytes)
Write bytes to a file.
Definition File.cpp:98
Memory::Buffer< char > readBytes(this File &self, Typing::USize bytes)
Read bytes from the file.
Definition File.cpp:40
Container for raw memory.
Definition Buffer.hpp:18
A dynamic string.
Definition String.hpp:11
Contains functions and classes to interact with the filesystem.
Definition FileSystem.hpp:5
SeekOrigin
All possible values for File::seek().
Definition File.hpp:12
@ Begin
Beginning of the file.
Definition File.hpp:13
@ Curr
Current cursor position.
Definition File.hpp:14
@ End
End of the file.
Definition File.hpp:15
size_t USize
Biggest unsigned type.
Definition Typing.hpp:38