MySQL 8.0.30
Source Code Documentation
basic_ostream.h
Go to the documentation of this file.
1/* Copyright (c) 2018, 2022, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef BASIC_OSTREAM_INCLUDED
24#define BASIC_OSTREAM_INCLUDED
25#include <my_byteorder.h>
27#include "my_sys.h"
28#include "sql_string.h"
29
30/**
31 The abstract class for basic output streams which provides write
32 operation.
33*/
35 public:
36 /**
37 Write some bytes into the output stream.
38 When all data is written into the stream successfully, then it return
39 false. Otherwise, true is returned. It will never returns false when
40 partial data is written into the stream.
41
42 @param[in] buffer Data to be written
43 @param[in] length Length of the data
44 @retval false Success.
45 @retval true Error.
46 */
47 virtual bool write(const unsigned char *buffer, my_off_t length) = 0;
48 virtual ~Basic_ostream() = default;
49};
50
51/**
52 Truncatable_ostream abstract class provides seek() and truncate() interfaces
53 to all truncatable output streams.
54*/
56 public:
57 /**
58 Truncate some data at the end of the output stream.
59
60 @param[in] offset Where the output stream will be truncated to.
61 @retval false Success
62 @retval true Error
63 */
64 virtual bool truncate(my_off_t offset) = 0;
65 /**
66 Put the write position to a given offset. The offset counts from the
67 beginning of the file.
68
69 @param[in] offset Where the write position will be
70 @retval false Success
71 @retval true Error
72 */
73 virtual bool seek(my_off_t offset) = 0;
74 /**
75 Flush data.
76
77 @retval false Success.
78 @retval true Error.
79 */
80 virtual bool flush() = 0;
81 /**
82 Sync.
83
84 @retval false Success
85 @retval true Error
86 */
87 virtual bool sync() = 0;
88
89 ~Truncatable_ostream() override = default;
90};
91
92/**
93 An output stream based on IO_CACHE class.
94*/
96 public:
100 ~IO_CACHE_ostream() override;
101
102 /**
103 Open the output stream. It opens related file and initialize IO_CACHE.
104
105 @param[in] log_file_key The PSI_file_key for this stream
106 @param[in] file_name The file will be opened
107 @param[in] flags The flags used by IO_CACHE.
108 @retval false Success
109 @retval true Error
110 */
111 bool open(
113 PSI_file_key log_file_key,
114#endif
115 const char *file_name, myf flags);
116 /**
117 Closes the stream. It deinitializes IO_CACHE and close the file
118 it opened.
119
120 @retval false Success
121 @retval true Error
122 */
123 bool close();
124
125 bool write(const unsigned char *buffer, my_off_t length) override;
126 bool seek(my_off_t offset) override;
127 bool truncate(my_off_t offset) override;
128
129 /**
130 Flush data to IO_CACHE's file if there is any data in IO_CACHE's buffer.
131
132 @retval false Success
133 @retval true Error
134 */
135 bool flush() override;
136
137 /**
138 Syncs the file to disk. It doesn't check and flush any remaining data still
139 left in IO_CACHE's buffer. So a call to flush() is necessary in order to
140 persist all data including the data in buffer.
141
142 @retval false Success
143 @retval true Error
144 */
145 bool sync() override;
146
147 private:
149};
150
151/**
152 A basic output stream based on StringBuffer class. It has a stack buffer of
153 size BUFFER_SIZE. It will allocate memory to create a heap buffer if
154 data exceeds the size of heap buffer.
155 */
156template <int BUFFER_SIZE>
158 public StringBuffer<BUFFER_SIZE> {
159 public:
163
164 bool write(const unsigned char *buffer, my_off_t length) override {
166 reinterpret_cast<const char *>(buffer), length);
167 }
168};
169
171 private:
173
174 public:
181 bool write(const unsigned char *buffer, my_off_t length) override;
182};
183
184#endif // BASIC_OSTREAM_INCLUDED
The abstract class for basic output streams which provides write operation.
Definition: basic_ostream.h:34
virtual ~Basic_ostream()=default
virtual bool write(const unsigned char *buffer, my_off_t length)=0
Write some bytes into the output stream.
Definition: basic_ostream.h:170
binary_log::transaction::compression::Compressor * m_compressor
Definition: basic_ostream.h:172
Compressed_ostream()
Definition: basic_ostream.cc:91
binary_log::transaction::compression::Compressor * get_compressor()
Definition: basic_ostream.cc:96
~Compressed_ostream() override
void set_compressor(binary_log::transaction::compression::Compressor *)
Definition: basic_ostream.cc:100
Compressed_ostream(const Compressed_ostream &)=delete
bool write(const unsigned char *buffer, my_off_t length) override
Write some bytes into the output stream.
Definition: basic_ostream.cc:105
Compressed_ostream & operator=(const Compressed_ostream &)=delete
An output stream based on IO_CACHE class.
Definition: basic_ostream.h:95
IO_CACHE m_io_cache
Definition: basic_ostream.h:148
bool close()
Closes the stream.
Definition: basic_ostream.cc:51
bool flush() override
Flush data to IO_CACHE's file if there is any data in IO_CACHE's buffer.
Definition: basic_ostream.cc:81
~IO_CACHE_ostream() override
Definition: basic_ostream.cc:31
IO_CACHE_ostream(const IO_CACHE_ostream &)=delete
bool truncate(my_off_t offset) override
Truncate some data at the end of the output stream.
Definition: basic_ostream.cc:71
bool seek(my_off_t offset) override
Put the write position to a given offset.
Definition: basic_ostream.cc:60
bool open(PSI_file_key log_file_key, const char *file_name, myf flags)
Open the output stream.
Definition: basic_ostream.cc:33
bool write(const unsigned char *buffer, my_off_t length) override
Write some bytes into the output stream.
Definition: basic_ostream.cc:65
bool sync() override
Syncs the file to disk.
Definition: basic_ostream.cc:86
IO_CACHE_ostream & operator=(const IO_CACHE_ostream &)=delete
A basic output stream based on StringBuffer class.
Definition: basic_ostream.h:158
StringBuffer_ostream(const StringBuffer_ostream &)=delete
bool write(const unsigned char *buffer, my_off_t length) override
Write some bytes into the output stream.
Definition: basic_ostream.h:164
StringBuffer_ostream()=default
StringBuffer_ostream & operator=(const StringBuffer_ostream &)=delete
String class wrapper with a preallocated buffer of size buff_sz.
Definition: sql_string.h:629
bool append(const String &s)
Definition: sql_string.cc:445
size_t length() const
Definition: sql_string.h:240
Truncatable_ostream abstract class provides seek() and truncate() interfaces to all truncatable outpu...
Definition: basic_ostream.h:55
virtual bool flush()=0
Flush data.
virtual bool seek(my_off_t offset)=0
Put the write position to a given offset.
~Truncatable_ostream() override=default
virtual bool sync()=0
Sync.
virtual bool truncate(my_off_t offset)=0
Truncate some data at the end of the output stream.
The base compressor abstract class.
Definition: base.h:145
unsigned int PSI_file_key
Instrumented file key.
Definition: psi_file_bits.h:47
static int flags[50]
Definition: hp_test1.cc:39
Functions for reading and storing in machine-independent format.
int myf
Definition: my_inttypes.h:93
ulonglong my_off_t
Definition: my_inttypes.h:71
#define HAVE_PSI_INTERFACE
Definition: my_psi_config.h:38
Common header for many mysys elements.
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:75
std::string file_name(Log_file_id file_id)
Provides name of the log file with the given file id, e.g.
Definition: log0pre_8_0_30.cc:93
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:391
Our own string classes, used pervasively throughout the executor.
Definition: my_sys.h:340