Tkrzw
Public Types | Public Member Functions | List of all members
tkrzw::PositionalFile Class Referenceabstract

Interface for positional access file implementations. More...

#include <tkrzw_file_pos.h>

Public Types

enum  AccessOption : int32_t {
  ACCESS_DEFAULT = 0 , ACCESS_DIRECT = 1 << 0 , ACCESS_SYNC = 1 << 1 , ACCESS_PADDING = 1 << 2 ,
  ACCESS_PAGECACHE = 1 << 3
}
 Enumeration of options for SetAccessStrategy. More...
 
- Public Types inherited from tkrzw::File
enum  OpenOption : int32_t {
  OPEN_DEFAULT = 0 , OPEN_TRUNCATE = 1 << 0 , OPEN_NO_CREATE = 1 << 1 , OPEN_NO_WAIT = 1 << 2 ,
  OPEN_NO_LOCK = 1 << 3 , OPEN_SYNC_HARD = 1 << 4
}
 Enumeration of options for Open. More...
 

Public Member Functions

virtual ~PositionalFile ()=default
 Destructor. More...
 
virtual Status SetHeadBuffer (int64_t size)=0
 Sets the head buffer to cache the beginning region of the file. More...
 
virtual Status SetAccessStrategy (int64_t block_size, int32_t options)=0
 Sets access strategy. More...
 
virtual int64_t GetBlockSize () const =0
 Gets the block size. More...
 
virtual bool IsDirectIO () const =0
 Checks whether the access mode is direct I/O. More...
 
- Public Member Functions inherited from tkrzw::File
virtual ~File ()=default
 Destructor. More...
 
virtual Status Open (const std::string &path, bool writable, int32_t options=OPEN_DEFAULT)=0
 Opens a file. More...
 
virtual Status Close ()=0
 Closes the file. More...
 
virtual Status Read (int64_t off, void *buf, size_t size)=0
 Reads data. More...
 
virtual std::string ReadSimple (int64_t off, size_t size)
 Reads data, in a simple way. More...
 
virtual Status Write (int64_t off, const void *buf, size_t size)=0
 Writes data. More...
 
virtual bool WriteSimple (int64_t off, std::string_view data)
 Writes data, in a simple way. More...
 
virtual Status Append (const void *buf, size_t size, int64_t *off=nullptr)=0
 Appends data at the end of the file. More...
 
virtual int64_t AppendSimple (const std::string &data)
 Appends data at the end of the file, in a simple way. More...
 
virtual Status Expand (size_t inc_size, int64_t *old_size=nullptr)=0
 Expands the file size without writing data. More...
 
virtual int64_t ExpandSimple (size_t inc_size)
 Expands the file size without writing data, in a simple way. More...
 
virtual Status Truncate (int64_t size)=0
 Truncates the file. More...
 
virtual Status TruncateFakely (int64_t size)=0
 Truncate the file fakely. More...
 
virtual Status Synchronize (bool hard, int64_t off=0, int64_t size=0)=0
 Synchronizes the content of the file to the file system. More...
 
virtual Status GetSize (int64_t *size)=0
 Gets the size of the file. More...
 
virtual int64_t GetSizeSimple ()
 Gets the size of the file, in a simple way. More...
 
virtual Status SetAllocationStrategy (int64_t init_size, double inc_factor)=0
 Sets allocation strategy. More...
 
virtual Status CopyProperties (File *file)=0
 Copies internal properties to another file object. More...
 
virtual Status GetPath (std::string *path)=0
 Gets the path of the file. More...
 
virtual std::string GetPathSimple ()
 Gets the path of the file, in a simple way. More...
 
virtual Status Rename (const std::string &new_path)=0
 Renames the file. More...
 
virtual Status DisablePathOperations ()=0
 Disables operations related to the path. More...
 
virtual bool IsOpen () const =0
 Checks whether the file is open. More...
 
virtual bool IsMemoryMapping () const =0
 Checks whether operations are done by memory mapping. More...
 
virtual bool IsAtomic () const =0
 Checks whether updating operations are atomic and thread-safe. More...
 
virtual std::unique_ptr< FileMakeFile () const =0
 Makes a new file object of the same concrete class. More...
 
const std::type_info & GetType () const
 Gets the type information of the actual class. More...
 

Additional Inherited Members

- Static Public Attributes inherited from tkrzw::File
static constexpr int64_t DEFAULT_ALLOC_INIT_SIZE = 1LL << 20
 The default value of the initial allocation size. More...
 
static constexpr double DEFAULT_ALLOC_INC_FACTOR = 2.0
 The default value of the allocation increment factor. More...
 

Detailed Description

Interface for positional access file implementations.

Member Enumeration Documentation

◆ AccessOption

Enumeration of options for SetAccessStrategy.

Enumerator
ACCESS_DEFAULT 

The default behavior.

ACCESS_DIRECT 

To access the data block directry without caching of the file system.

ACCESS_SYNC 

To synchronize the update operation through the device.

ACCESS_PADDING 

To fill padding bytes for alignment when closing the file.

ACCESS_PAGECACHE 

To use the mini page cache in the process to improve performance.

Constructor & Destructor Documentation

◆ ~PositionalFile()

virtual tkrzw::PositionalFile::~PositionalFile ( )
virtualdefault

Destructor.

Member Function Documentation

◆ SetHeadBuffer()

virtual Status tkrzw::PositionalFile::SetHeadBuffer ( int64_t  size)
pure virtual

Sets the head buffer to cache the beginning region of the file.

Parameters
sizeThe size of the head buffer. If it is not positive, it is not used.
Returns
The result status.

This method must be called after the file is opened.

Implemented in tkrzw::PositionalAtomicFile, and tkrzw::PositionalParallelFile.

◆ SetAccessStrategy()

virtual Status tkrzw::PositionalFile::SetAccessStrategy ( int64_t  block_size,
int32_t  options 
)
pure virtual

Sets access strategy.

Parameters
block_sizeThe block size to which all blocks should be aligned. It must be a power of two and a multiple of the block size of the underlying file system or device.
optionsBit-sum options of PositionalFile::AccessOption enums;
Returns
The result status.

Implemented in tkrzw::PositionalAtomicFile, and tkrzw::PositionalParallelFile.

◆ GetBlockSize()

virtual int64_t tkrzw::PositionalFile::GetBlockSize ( ) const
pure virtual

Gets the block size.

Returns
The block size.

Implemented in tkrzw::PositionalAtomicFile, and tkrzw::PositionalParallelFile.

◆ IsDirectIO()

virtual bool tkrzw::PositionalFile::IsDirectIO ( ) const
pure virtual

Checks whether the access mode is direct I/O.

Returns
True if the access mode is direct I/O, or false if not.

Implemented in tkrzw::PositionalAtomicFile, and tkrzw::PositionalParallelFile.