file_base.hpp
4.04 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//
// file_base.hpp
// ~~~~~~~~~~~~~
//
// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_ASIO_FILE_BASE_HPP
#define BOOST_ASIO_FILE_BASE_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
#include <boost/asio/detail/config.hpp>
#if defined(BOOST_ASIO_HAS_FILE) \
|| defined(GENERATING_DOCUMENTATION)
#if !defined(BOOST_ASIO_WINDOWS)
# include <fcntl.h>
#endif // !defined(BOOST_ASIO_WINDOWS)
#include <boost/asio/detail/push_options.hpp>
namespace boost {
namespace asio {
/// The file_base class is used as a base for the basic_stream_file and
/// basic_random_access_file class templates so that we have a common place to
/// define flags.
class file_base
{
public:
#if defined(GENERATING_DOCUMENTATION)
/// A bitmask type (C++ Std [lib.bitmask.types]).
typedef unspecified flags;
/// Open the file for reading.
static const flags read_only = implementation_defined;
/// Open the file for writing.
static const flags write_only = implementation_defined;
/// Open the file for reading and writing.
static const flags read_write = implementation_defined;
/// Open the file in append mode.
static const flags append = implementation_defined;
/// Create the file if it does not exist.
static const flags create = implementation_defined;
/// Ensure a new file is created. Must be combined with @c create.
static const flags exclusive = implementation_defined;
/// Open the file with any existing contents truncated.
static const flags truncate = implementation_defined;
/// Open the file so that write operations automatically synchronise the file
/// data and metadata to disk.
static const flags sync_all_on_write = implementation_defined;
#else
enum flags
{
#if defined(BOOST_ASIO_WINDOWS)
read_only = 1,
write_only = 2,
read_write = 4,
append = 8,
create = 16,
exclusive = 32,
truncate = 64,
sync_all_on_write = 128
#else // defined(BOOST_ASIO_WINDOWS)
read_only = O_RDONLY,
write_only = O_WRONLY,
read_write = O_RDWR,
append = O_APPEND,
create = O_CREAT,
exclusive = O_EXCL,
truncate = O_TRUNC,
sync_all_on_write = O_SYNC
#endif // defined(BOOST_ASIO_WINDOWS)
};
// Implement bitmask operations as shown in C++ Std [lib.bitmask.types].
friend flags operator&(flags x, flags y)
{
return static_cast<flags>(
static_cast<unsigned int>(x) & static_cast<unsigned int>(y));
}
friend flags operator|(flags x, flags y)
{
return static_cast<flags>(
static_cast<unsigned int>(x) | static_cast<unsigned int>(y));
}
friend flags operator^(flags x, flags y)
{
return static_cast<flags>(
static_cast<unsigned int>(x) ^ static_cast<unsigned int>(y));
}
friend flags operator~(flags x)
{
return static_cast<flags>(~static_cast<unsigned int>(x));
}
friend flags& operator&=(flags& x, flags y)
{
x = x & y;
return x;
}
friend flags& operator|=(flags& x, flags y)
{
x = x | y;
return x;
}
friend flags& operator^=(flags& x, flags y)
{
x = x ^ y;
return x;
}
#endif
/// Basis for seeking in a file.
enum seek_basis
{
#if defined(GENERATING_DOCUMENTATION)
/// Seek to an absolute position.
seek_set = implementation_defined,
/// Seek to an offset relative to the current file position.
seek_cur = implementation_defined,
/// Seek to an offset relative to the end of the file.
seek_end = implementation_defined
#else
seek_set = SEEK_SET,
seek_cur = SEEK_CUR,
seek_end = SEEK_END
#endif
};
protected:
/// Protected destructor to prevent deletion through this type.
~file_base()
{
}
};
} // namespace asio
} // namespace boost
#include <boost/asio/detail/pop_options.hpp>
#endif // defined(BOOST_ASIO_HAS_FILE)
// || defined(GENERATING_DOCUMENTATION)
#endif // BOOST_ASIO_FILE_BASE_HPP