MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
Public 成员函数 | 静态 Public 成员函数 | Private 属性 | 所有成员列表
oceanbase::ObFileWriter类 参考

A utility class for writing data to files. 更多...

#include <ob_file_writer.h>

Public 成员函数

 ObFileWriter (const string &filename, bool append=false)
 Constructs an ObFileWriter object with the specified file name and mode. 更多...
 
RC open_file ()
 Opens the file for writing. 更多...
 
void close_file ()
 Closes the file if it is currently open. 更多...
 
RC write (const string_view &data)
 Writes data to the file. 更多...
 
RC flush ()
 Flushes buffered data to disk. 更多...
 
bool is_open () const
 Checks if the file is currently open. 更多...
 
string file_name () const
 Returns the name of the file being written to. 更多...
 

静态 Public 成员函数

static unique_ptr< ObFileWritercreate_file_writer (const string &filename, bool append)
 Creates a new ObFileWriter instance. 更多...
 

Private 属性

string filename_
 The name of the file to be written to.
 
bool append_
 Indicates whether the file should be opened in append mode. 更多...
 
ofstream file_
 The file stream used for writing data.
 

详细描述

A utility class for writing data to files.

The ObFileWriter class provides a convenient interface for writing data to a file. It supports creating and opening files for writing, appending data to existing files, and flushing buffered data to disk. The class ensures proper resource management by providing methods for explicitly closing the file. TODO: use posix

构造及析构函数说明

◆ ObFileWriter()

oceanbase::ObFileWriter::ObFileWriter ( const string &  filename,
bool  append = false 
)
inline

Constructs an ObFileWriter object with the specified file name and mode.

The constructor initializes the file writer with the given file name. The file is not opened until open_file() is called. The append parameter determines whether the file should be opened in append mode or overwrite mode.

参数
filenameThe name of the file to write to.
appendWhether to open the file in append mode (default: false).

成员函数说明

◆ close_file()

void oceanbase::ObFileWriter::close_file ( )

Closes the file if it is currently open.

This method releases the resources associated with the file. After calling this method, the file can no longer be written to until it is reopened.

◆ create_file_writer()

unique_ptr< ObFileWriter > oceanbase::ObFileWriter::create_file_writer ( const string &  filename,
bool  append 
)
static

Creates a new ObFileWriter instance.

This static factory method constructs a new ObFileWriter object with the specified file name and append mode.

参数
filenameThe name of the file to write to.
appendWhether to open the file in append mode (default: false).
返回
A unique_ptr to the created ObFileWriter object.

◆ file_name()

string oceanbase::ObFileWriter::file_name ( ) const
inline

Returns the name of the file being written to.

返回
A string containing the file name.

◆ flush()

RC oceanbase::ObFileWriter::flush ( )

Flushes buffered data to disk.

Ensures that all buffered data is written to the file system. This method is useful for ensuring data integrity in cases where the program may terminate unexpectedly.

返回
An RC (return code) indicating the success or failure of the flush operation.

◆ is_open()

bool oceanbase::ObFileWriter::is_open ( ) const
inline

Checks if the file is currently open.

返回
true if the file is open, false otherwise.

◆ open_file()

RC oceanbase::ObFileWriter::open_file ( )

Opens the file for writing.

This method attempts to open the file specified during the construction of the object. If the file is successfully opened, further write operations can be performed.

返回
An RC (return code) indicating the success or failure of the operation.
注解
If the file cannot be opened (e.g., due to permission issues), an error code is returned.

◆ write()

RC oceanbase::ObFileWriter::write ( const string_view &  data)

Writes data to the file.

Appends the provided data to the file. If the file is not open, the operation will fail.

参数
dataThe data to write to the file, provided as a string_view.
返回
An RC (return code) indicating the success or failure of the operation.

类成员变量说明

◆ append_

bool oceanbase::ObFileWriter::append_
private

Indicates whether the file should be opened in append mode.

If true, data will be appended to the existing file. If false, the existing file (if any) will be overwritten when the file is opened.


该类的文档由以下文件生成: