CatapultServer  v0.5.0.1 (Elephant)
RawFile.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "catapult/types.h"
23 #include <string>
24 
25 namespace catapult { namespace io {
26 
28  enum class OpenMode {
30  Read_Only,
31 
33  Read_Write,
34 
37  };
38 
40  enum class LockMode {
42  None,
43 
45  File
46  };
47 
49  class RawFile final : public utils::MoveOnly {
50  public:
53  RawFile(const std::string& pathname, OpenMode mode, LockMode lockMode = LockMode::File);
54 
56  RawFile(RawFile&& rhs) = default;
57 
59  RawFile& operator=(RawFile&& rhs) = delete;
60 
61  public:
64  void write(const RawBuffer& dataBuffer);
65 
68  void seek(uint64_t position);
69 
72  void read(const MutableRawBuffer& dataBuffer);
73 
75  uint64_t size() const;
76 
78  uint64_t position() const;
79 
80  private:
81  class FileDescriptorHolder final {
82  public:
83  explicit FileDescriptorHolder(int fd);
87 
88  bool isValid() const;
89 
90  int raw() const;
91  int& rawRef();
92 
93  private:
94  int m_fd;
95  };
96 
97  const std::string m_pathname;
99  uint64_t m_fileSize;
100  uint64_t m_position;
101  };
102 }}
exceptions.h
catapult::io::RawFile
Wrapper for low-level i/o operations on files.
Definition: RawFile.h:49
catapult::io::OpenMode::Read_Write
Open file for both reading and writing. Removes the file if it exists.
catapult::io::RawFile::FileDescriptorHolder::m_fd
int m_fd
Definition: RawFile.h:94
catapult::io::RawFile::FileDescriptorHolder::raw
int raw() const
Definition: RawFile.cpp:267
catapult::io::OpenMode::Read_Only
Open file in read-only mode.
catapult::io::RawFile::seek
void seek(uint64_t position)
Definition: RawFile.cpp:320
catapult::io::LockMode
LockMode
Defines locking mode for the file.
Definition: RawFile.h:40
catapult::io::OpenMode
OpenMode
Defines mode of opening the file.
Definition: RawFile.h:28
catapult::io::RawFile::FileDescriptorHolder::~FileDescriptorHolder
~FileDescriptorHolder()
Definition: RawFile.cpp:256
RawFile.h
catapult::io::RawFile::position
uint64_t position() const
Returns position in the file.
Definition: RawFile.cpp:338
catapult::utils::MutableRawBuffer
BasicRawBuffer< uint8_t > MutableRawBuffer
A mutable binary buffer.
Definition: RawBuffer.h:65
Message
std::string Message
Definition: RawFile.cpp:72
catapult::io::RawFile::size
uint64_t size() const
Returns size of the file.
Definition: RawFile.cpp:334
catapult::io::RawFile::m_position
uint64_t m_position
Definition: RawFile.h:100
catapult::io::FileBlockStorageMode::None
None.
catapult::io::RawFile::FileDescriptorHolder
Definition: RawFile.h:81
catapult::io::LockMode::File
Use file-based locking.
catapult::io::RawFile::RawFile
RawFile(const std::string &pathname, OpenMode mode, LockMode lockMode=LockMode::File)
Definition: RawFile.cpp:293
size
uint64_t size
Definition: MemoryCounters.cpp:65
Value
T Value
Definition: RawFile.cpp:69
catapult::utils::MoveOnly
A class that can be moved but not copied.
Definition: NonCopyable.h:43
IsSuccess
bool IsSuccess
Definition: RawFile.cpp:68
catapult::io::RawFile::operator=
RawFile & operator=(RawFile &&rhs)=delete
Disallow move-assign.
types.h
catapult::io::RawFile::FileDescriptorHolder::FileDescriptorHolder
FileDescriptorHolder(int fd)
Definition: RawFile.cpp:249
catapult::io::OpenMode::Read_Append
Open file for both reading and writing.
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::io::RawFile::FileDescriptorHolder::rawRef
int & rawRef()
Definition: RawFile.cpp:274
catapult::io::RawFile::m_pathname
const std::string m_pathname
Definition: RawFile.h:97
catapult::io::RawFile::write
void write(const RawBuffer &dataBuffer)
Definition: RawFile.cpp:305
catapult::io::RawFile::FileDescriptorHolder::isValid
bool isValid() const
Definition: RawFile.cpp:263
catapult::io::RawFile::read
void read(const MutableRawBuffer &dataBuffer)
Definition: RawFile.cpp:313
ErrorCode
int32_t ErrorCode
Definition: RawFile.cpp:71
catapult::io::RawFile::m_fd
FileDescriptorHolder m_fd
Definition: RawFile.h:98
catapult::io::RawFile::FileDescriptorHolder::operator=
FileDescriptorHolder & operator=(FileDescriptorHolder &&rhs)=delete
catapult::io::RawFile::m_fileSize
uint64_t m_fileSize
Definition: RawFile.h:99
catapult::utils::RawBuffer
BasicRawBuffer< const uint8_t > RawBuffer
A const binary buffer.
Definition: RawBuffer.h:62