MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
全部  文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
Public 成员函数 | 静态 Public 成员函数 | Private 属性 | 所有成员列表
oceanbase::ObFileReader类 参考

A utility class for reading files in an efficient manner. 更多...

#include <ob_file_reader.h>

Public 成员函数

 ObFileReader (const string &filename)
 Constructs an ObFileReader object with the specified file name. 更多...
 
RC open_file ()
 Opens the file for reading. 更多...
 
void close_file ()
 Closes the file if it is currently open. 更多...
 
string read_pos (uint32_t pos, uint32_t size)
 Reads a portion of the file from a specified position. 更多...
 
uint32_t file_size ()
 Returns the size of the file. 更多...
 

静态 Public 成员函数

static unique_ptr< ObFileReadercreate_file_reader (const string &filename)
 Creates a new ObFileReader instance. 更多...
 

Private 属性

string filename_
 The name of the file to be read. 更多...
 
int fd_ = -1
 The file descriptor for the currently opened file. 更多...
 

详细描述

A utility class for reading files in an efficient manner.

The ObFileReader class provides a simple interface for reading files. It allows opening, closing, and reading specific portions of a file while also exposing the file size for external use. This class is intended for use in scenarios where file-based data storage, such as SSTables, is accessed.

构造及析构函数说明

◆ ObFileReader()

oceanbase::ObFileReader::ObFileReader ( const string &  filename)
inline

Constructs an ObFileReader object with the specified file name.

The file name is stored internally, but the file is not opened until open_file() is explicitly called.

参数
filenameThe name of the file to be read.

成员函数说明

◆ close_file()

void oceanbase::ObFileReader::close_file ( )

Closes the file if it is currently open.

This method releases the file descriptor (fd_) associated with the file.

◆ create_file_reader()

unique_ptr< ObFileReader > oceanbase::ObFileReader::create_file_reader ( const string &  filename)
static

Creates a new ObFileReader instance.

This static factory method constructs a new ObFileReader object and initializes it with the specified file name.

参数
filenameThe name of the file to be read.
返回
A unique_ptr to the created ObFileReader object.

◆ file_size()

uint32_t oceanbase::ObFileReader::file_size ( )

Returns the size of the file.

This method retrieves the size of the file in bytes. It relies on the file being successfully opened.

返回
The size of the file in bytes.

◆ open_file()

RC oceanbase::ObFileReader::open_file ( )

Opens the file for reading.

This method attempts to open the file specified during the construction of the object. If the file is successfully opened, the internal file descriptor (fd_) is updated.

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

◆ read_pos()

string oceanbase::ObFileReader::read_pos ( uint32_t  pos,
uint32_t  size 
)

Reads a portion of the file from a specified position.

This method reads size bytes starting from position pos in the file.

参数
posThe starting position (offset) in the file.
sizeThe number of bytes to read.
返回
A string containing the requested portion of the file's data.

类成员变量说明

◆ fd_

int oceanbase::ObFileReader::fd_ = -1
private

The file descriptor for the currently opened file.

This integer represents the file descriptor used for reading the file. If no file is open, it is set to -1.

◆ filename_

string oceanbase::ObFileReader::filename_
private

The name of the file to be read.

This string stores the file name specified during the construction of the ObFileReader object.


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