Tkrzw
|
File implementation with the std::fstream. More...
#include <tkrzw_file_std.h>
Public Member Functions | |
StdFile () | |
Default constructor. More... | |
~StdFile () | |
Destructor. More... | |
StdFile (const StdFile &rhs)=delete | |
Copy and assignment are disabled. More... | |
StdFile & | operator= (const StdFile &rhs)=delete |
Status | Open (const std::string &path, bool writable, int32_t options=OPEN_DEFAULT) override |
Opens a file. More... | |
Status | Close () override |
Closes the file. More... | |
Status | Read (int64_t off, void *buf, size_t size) override |
Reads data. More... | |
Status | Write (int64_t off, const void *buf, size_t size) override |
Writes data. More... | |
Status | Append (const void *buf, size_t size, int64_t *off=nullptr) override |
Appends data at the end of the file. More... | |
Status | Expand (size_t inc_size, int64_t *old_size=nullptr) override |
Expands the file size without writing data. More... | |
Status | Truncate (int64_t size) override |
Truncates the file. More... | |
Status | TruncateFakely (int64_t size) override |
Truncate the file fakely. More... | |
Status | Synchronize (bool hard, int64_t off=0, int64_t size=0) override |
Synchronizes the content of the file to the file system. More... | |
Status | GetSize (int64_t *size) override |
Gets the size of the file. More... | |
Status | SetAllocationStrategy (int64_t init_size, double inc_factor) override |
Sets allocation strategy. More... | |
Status | CopyProperties (File *file) override |
Copies internal properties to another file object. More... | |
Status | GetPath (std::string *path) override |
Gets the path of the file. More... | |
Status | Rename (const std::string &new_path) override |
Renames the file. More... | |
Status | DisablePathOperations () override |
Disables operations related to the path. More... | |
int64_t | Lock () |
Lock this object. More... | |
int64_t | Unlock () |
Unlock this object. More... | |
Status | ReadInCriticalSection (int64_t off, void *buf, size_t size) |
Reads data in the critical section by the lock. More... | |
Status | WriteInCriticalSection (int64_t off, const void *buf, size_t size) |
Writes data in the critical section by the lock. More... | |
bool | IsOpen () const override |
Checks whether the file is open. More... | |
bool | IsMemoryMapping () const override |
Checks whether operations are done by memory mapping. More... | |
bool | IsAtomic () const override |
Checks whether updating operations are atomic and thread-safe. More... | |
std::unique_ptr< File > | MakeFile () const override |
Makes a new file object of the same concrete class. More... | |
Public Member Functions inherited from tkrzw::File | |
virtual | ~File ()=default |
Destructor. More... | |
virtual std::string | ReadSimple (int64_t off, size_t size) |
Reads data, in a simple way. More... | |
virtual bool | WriteSimple (int64_t off, std::string_view data) |
Writes data, in a simple way. More... | |
virtual int64_t | AppendSimple (const std::string &data) |
Appends data at the end of the file, in a simple way. More... | |
virtual int64_t | ExpandSimple (size_t inc_size) |
Expands the file size without writing data, in a simple way. More... | |
virtual int64_t | GetSizeSimple () |
Gets the size of the file, in a simple way. More... | |
virtual std::string | GetPathSimple () |
Gets the path of the file, in a simple way. More... | |
const std::type_info & | GetType () const |
Gets the type information of the actual class. More... | |
Additional Inherited Members | |
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... | |
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... | |
File implementation with the std::fstream.
All operations are thread-safe; Multiple threads can access the same file concurrently.
tkrzw::StdFile::StdFile | ( | ) |
Default constructor.
tkrzw::StdFile::~StdFile | ( | ) |
Destructor.
|
explicitdelete |
Copy and assignment are disabled.
|
overridevirtual |
Opens a file.
path | A path of the file. |
writable | If true, the file is writable. If false, it is read-only. |
options | Bit-sum options of File::OpenOption enums. OPEN_NO_WAIT are OPEN_NO_LOCK are ignored. |
Implements tkrzw::File.
|
overridevirtual |
|
overridevirtual |
Reads data.
off | The offset of a source region. |
buf | The pointer to the destination buffer. |
size | The size of the data to be read. |
Implements tkrzw::File.
|
overridevirtual |
Writes data.
off | The offset of the destination region. |
buf | The pointer to the source buffer. |
size | The size of the data to be written. |
Implements tkrzw::File.
|
overridevirtual |
Appends data at the end of the file.
buf | The pointer to the source buffer. |
size | The size of the data to be written. |
off | The pointer to an integer object to contain the offset at which the data has been put. If it is nullptr, it is ignored. |
Implements tkrzw::File.
|
overridevirtual |
Expands the file size without writing data.
inc_size | The size to increment the file size by. |
old_size | The pointer to an integer object to contain the old size of the file. If it is nullptr, it is ignored. |
Implements tkrzw::File.
|
overridevirtual |
Truncates the file.
size | The new size of the file. |
Implements tkrzw::File.
|
overridevirtual |
Truncate the file fakely.
size | The new size of the file. |
This doesn't modify the actual file but modifies the internal length parameter, which affects behavior of Close, Synchronize, Append, Expand, and GetSize. If the specified size is more than the actual file size, the operation fails.
Implements tkrzw::File.
|
overridevirtual |
Synchronizes the content of the file to the file system.
hard | True to do physical synchronization with the hardware or false to do only logical synchronization with the file system. |
off | The offset of the region to be synchronized. |
size | The size of the region to be synchronized. If it is zero, the length to the end of file is specified. |
This is a dummy implementation and has no effect.
Implements tkrzw::File.
|
overridevirtual |
Gets the size of the file.
size | The pointer to an integer object to contain the result size. |
Implements tkrzw::File.
|
overridevirtual |
Sets allocation strategy.
init_size | An initial size of allocation. |
inc_factor | A factor to increase the size of allocation. |
This is a dummy implementation and has no effect.
Implements tkrzw::File.
Copies internal properties to another file object.
file | The other file object. |
Implements tkrzw::File.
|
overridevirtual |
Gets the path of the file.
path | The pointer to a string object to store the path. |
Implements tkrzw::File.
|
overridevirtual |
Renames the file.
new_path | A new path of the file. |
Implements tkrzw::File.
|
overridevirtual |
Disables operations related to the path.
This should be called if the file is overwritten by external operations.
Implements tkrzw::File.
int64_t tkrzw::StdFile::Lock | ( | ) |
Lock this object.
Unlock must be done by the caller.
int64_t tkrzw::StdFile::Unlock | ( | ) |
Unlock this object.
This is allowed only by the lock holder.
Status tkrzw::StdFile::ReadInCriticalSection | ( | int64_t | off, |
void * | buf, | ||
size_t | size | ||
) |
Reads data in the critical section by the lock.
off | The offset of a source region. |
buf | The pointer to the destination buffer. |
size | The size of the data to be read. |
This is allowed only by the lock holder.
Status tkrzw::StdFile::WriteInCriticalSection | ( | int64_t | off, |
const void * | buf, | ||
size_t | size | ||
) |
Writes data in the critical section by the lock.
off | The offset of the destination region. |
buf | The pointer to the source buffer. |
size | The size of the data to be written. |
This is allowed only by the lock holder.
|
overridevirtual |
Checks whether the file is open.
Implements tkrzw::File.
|
overridevirtual |
Checks whether operations are done by memory mapping.
Implements tkrzw::File.
|
overridevirtual |
Checks whether updating operations are atomic and thread-safe.
Implements tkrzw::File.
|
overridevirtual |
Makes a new file object of the same concrete class.
Implements tkrzw::File.