-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.hpp
More file actions
66 lines (48 loc) · 1.66 KB
/
Copy pathfile.hpp
File metadata and controls
66 lines (48 loc) · 1.66 KB
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
/* File: /lib/impl/stream/file.hpp
*
* This file is a part of cpplib project which is distributed under MIT License.
* See file LICENSE for full license details.
*
* Copyright (c) 2020-present Nikita Zuev (V.Slavski!) <[email protected]>
*/
#ifndef CPPLIB__lib__impl__stream__file__hpp
#define CPPLIB__lib__impl__stream__file__hpp
#include <cstdio>
#include <system_error>
#include "../../../lib/data/stream.hpp"
// DECLARATION lib::stream::impl::file
namespace lib::stream::impl {
class file final
: public data::unistream_t
{
public:
/// @todo Add open mode constants/enum?
/// @todo Check `$ man fopen`
void dbg_test();
file() = default;
file( const char * name, const char * mode = "r" );
file( FILE * file_handle );
virtual ~file();
file & operator = ( FILE * file_handle );
bool open( const char * name, const char * mode = "r" );
bool close();
bool is_open() const { return file_ != nullptr; }
void reset();
// IMPLEMENTATION lib::data::rstream_t, lib::data::wstream_t
data::result_t read( const data::buffer_t & buffer ) override;
data::result_t peek( const data::buffer_t & buffer ) override;
data::result_t write( const data::cbuffer_t & buffer ) override;
// IMPLEMENTATION lib::data::unistream_t
bool flush() override;
data::result_t size() override;
// IMPLEMENTATION lib::data::rwstream_t
data::result_t pos( usize position ) override;
data::result_t pos() override;
::std::error_condition error() const override { return error_; }
private:
const ::std::error_condition & set_error_from_errno();
FILE * file_ = nullptr;
::std::error_condition error_;
};
} // namespace lib::stream::impl
#endif // CPPLIB__lib__impl__stream__file__hpp