ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
e57::CheckedFile Class Reference

#include <CheckedFile.h>

Collaboration diagram for e57::CheckedFile:

Public Types

enum  Mode { ReadOnly , WriteCreate , WriteExisting }
 
enum  OffsetMode { Logical , Physical }
 

Public Member Functions

 CheckedFile (const e57::ustring &fileName, Mode mode, ReadChecksumPolicy policy)
 
 CheckedFile (const char *input, uint64_t size, ReadChecksumPolicy policy)
 
 ~CheckedFile ()
 
void read (char *buf, size_t nRead, size_t bufSize=0)
 
void write (const char *buf, size_t nWrite)
 
CheckedFileoperator<< (const e57::ustring &s)
 
CheckedFileoperator<< (int64_t i)
 
CheckedFileoperator<< (uint64_t i)
 
CheckedFileoperator<< (float f)
 
CheckedFileoperator<< (double d)
 
void seek (uint64_t offset, OffsetMode omode=Logical)
 
uint64_t position (OffsetMode omode=Logical)
 
uint64_t length (OffsetMode omode=Logical)
 
void extend (uint64_t newLength, OffsetMode omode=Logical)
 
e57::ustring fileName () const
 
void close ()
 
void unlink ()
 

Static Public Member Functions

static uint64_t logicalToPhysical (uint64_t logicalOffset)
 
static uint64_t physicalToLogical (uint64_t physicalOffset)
 

Static Public Attributes

static constexpr size_t physicalPageSizeLog2 = 10
 
static constexpr size_t physicalPageSize = 1 << physicalPageSizeLog2
 
static constexpr uint64_t physicalPageSizeMask = physicalPageSize - 1
 
static constexpr size_t logicalPageSize = physicalPageSize - 4
 

Detailed Description

Definition at line 42 of file CheckedFile.h.

Member Enumeration Documentation

◆ Mode

Enumerator
ReadOnly 
WriteCreate 
WriteExisting 

Definition at line 51 of file CheckedFile.h.

◆ OffsetMode

Enumerator
Logical 
Physical 

Definition at line 58 of file CheckedFile.h.

Constructor & Destructor Documentation

◆ CheckedFile() [1/2]

CheckedFile::CheckedFile ( const e57::ustring fileName,
Mode  mode,
ReadChecksumPolicy  policy 
)

File truncated to zero length if already exists

Definition at line 139 of file CheckedFile.cpp.

References length(), O_BINARY, Physical, physicalToLogical(), ReadOnly, SEEK_END, SEEK_SET, WriteCreate, and WriteExisting.

◆ CheckedFile() [2/2]

CheckedFile::CheckedFile ( const char *  input,
uint64_t  size,
ReadChecksumPolicy  policy 
)

Definition at line 168 of file CheckedFile.cpp.

References physicalToLogical(), SEEK_END, SEEK_SET, and size.

◆ ~CheckedFile()

CheckedFile::~CheckedFile ( )

??? what if already closed?

Definition at line 209 of file CheckedFile.cpp.

References close().

Member Function Documentation

◆ close()

void CheckedFile::close ( )

◆ extend()

void CheckedFile::extend ( uint64_t  newLength,
OffsetMode  omode = Logical 
)

Make sure we are trying to make file longer

Calc how may zero bytes we have to add to end

Seek to current end of file

Calc first write size (may be partial page) Watch out for different int sizes here.

Allocate temp page buffer

When done, leave cursor at end of file

Definition at line 539 of file CheckedFile.cpp.

References e57::E57_ERROR_FILE_IS_READ_ONLY, e57::E57_ERROR_INTERNAL, E57_EXCEPTION2, length(), Logical, logicalPageSize, Physical, physicalPageSize, physicalToLogical(), seek(), and e57::toString().

Referenced by e57::ImageFileImpl::allocateSpace().

◆ fileName()

e57::ustring e57::CheckedFile::fileName ( ) const
inline

Definition at line 79 of file CheckedFile.h.

◆ length()

uint64_t CheckedFile::length ( OffsetMode  omode = Logical)

Definition at line 515 of file CheckedFile.cpp.

References Physical, SEEK_CUR, SEEK_END, and SEEK_SET.

Referenced by CheckedFile(), e57::ImageFileImpl::close(), extend(), read(), and write().

◆ logicalToPhysical()

uint64_t e57::CheckedFile::logicalToPhysical ( uint64_t  logicalOffset)
inlinestatic

◆ operator<<() [1/5]

CheckedFile & CheckedFile::operator<< ( const e57::ustring s)

Definition at line 345 of file CheckedFile.cpp.

References write().

◆ operator<<() [2/5]

CheckedFile & CheckedFile::operator<< ( double  d)

Definition at line 371 of file CheckedFile.cpp.

◆ operator<<() [3/5]

CheckedFile & CheckedFile::operator<< ( float  f)

Definition at line 365 of file CheckedFile.cpp.

◆ operator<<() [4/5]

CheckedFile & CheckedFile::operator<< ( int64_t  i)

Definition at line 351 of file CheckedFile.cpp.

◆ operator<<() [5/5]

CheckedFile & CheckedFile::operator<< ( uint64_t  i)

Definition at line 358 of file CheckedFile.cpp.

◆ physicalToLogical()

uint64_t e57::CheckedFile::physicalToLogical ( uint64_t  physicalOffset)
inlinestatic

◆ position()

uint64_t CheckedFile::position ( OffsetMode  omode = Logical)

Get current file cursor position

Definition at line 502 of file CheckedFile.cpp.

References Physical, physicalToLogical(), and SEEK_CUR.

Referenced by e57::ImageFileImpl::close(), read(), and write().

◆ read()

void CheckedFile::read ( char *  buf,
size_t  nRead,
size_t  bufSize = 0 
)

Allocate temp page buffer

When done, leave cursor just past end of last byte read

Definition at line 221 of file CheckedFile.cpp.

References e57::CHECKSUM_POLICY_ALL, e57::CHECKSUM_POLICY_NONE, e57::E57_ERROR_INTERNAL, E57_EXCEPTION2, length(), Logical, logicalPageSize, min(), physicalPageSize, position(), seek(), and e57::toString().

Referenced by E57FileInputStream::readBytes(), and e57::PacketReadCache::readPacket().

◆ seek()

void CheckedFile::seek ( uint64_t  offset,
OffsetMode  omode = Logical 
)

◆ unlink()

void CheckedFile::unlink ( )

Try to remove the file, don't report a failure

Definition at line 665 of file CheckedFile.cpp.

References close(), QtCompat::endl(), and result.

Referenced by e57::ImageFileImpl::cancel().

◆ write()

void CheckedFile::write ( const char *  buf,
size_t  nWrite 
)

Allocate temp page buffer

When done, leave cursor just past end of buf

Definition at line 284 of file CheckedFile.cpp.

References e57::E57_ERROR_FILE_IS_READ_ONLY, E57_EXCEPTION2, length(), Logical, logicalPageSize, min(), Physical, physicalPageSize, position(), and seek().

Referenced by e57::ImageFileImpl::close(), and operator<<().

Member Data Documentation

◆ logicalPageSize

constexpr size_t CheckedFile::logicalPageSize = physicalPageSize - 4
staticconstexpr

Definition at line 48 of file CheckedFile.h.

Referenced by extend(), logicalToPhysical(), physicalToLogical(), read(), and write().

◆ physicalPageSize

constexpr size_t CheckedFile::physicalPageSize = 1 << physicalPageSizeLog2
staticconstexpr

Definition at line 46 of file CheckedFile.h.

Referenced by e57::ImageFileImpl::close(), extend(), logicalToPhysical(), read(), and write().

◆ physicalPageSizeLog2

constexpr size_t CheckedFile::physicalPageSizeLog2 = 10
staticconstexpr

Definition at line 45 of file CheckedFile.h.

Referenced by physicalToLogical().

◆ physicalPageSizeMask

constexpr uint64_t CheckedFile::physicalPageSizeMask = physicalPageSize - 1
staticconstexpr

Definition at line 47 of file CheckedFile.h.

Referenced by physicalToLogical().


The documentation for this class was generated from the following files: