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

#include <Packet.h>

Collaboration diagram for e57::PacketReadCache:

Classes

struct  CacheEntry
 

Public Member Functions

 PacketReadCache (CheckedFile *cFile, unsigned packetCount)
 
std::unique_ptr< PacketLocklock (uint64_t packetLogicalOffset, char *&pkt)
 
void dump (int indent=0, std::ostream &os=std::cout)
 

Protected Member Functions

void unlock (unsigned cacheIndex)
 
void readPacket (unsigned oldestEntry, uint64_t packetLogicalOffset)
 

Protected Attributes

unsigned lockCount_ = 0
 
unsigned useCount_ = 0
 
CheckedFilecFile_ = nullptr
 
std::vector< CacheEntryentries_
 

Detailed Description

Definition at line 51 of file Packet.h.

Constructor & Destructor Documentation

◆ PacketReadCache()

PacketReadCache::PacketReadCache ( CheckedFile cFile,
unsigned  packetCount 
)

Definition at line 77 of file Packet.cpp.

References e57::E57_ERROR_INTERNAL, E57_EXCEPTION2, and e57::toString().

Member Function Documentation

◆ dump()

◆ lock()

std::unique_ptr< PacketLock > PacketReadCache::lock ( uint64_t  packetLogicalOffset,
char *&  pkt 
)

Only allow one locked packet at a time.

Offset can't be 0

Linear scan for matching packet offset in cache

Found a match, so don't have to read anything

Mark entry with current useCount (keeps track of age of entry).

Publish buffer address to caller

Create lock so we are sure that we will be unlocked when use is finished.

Increment cache lock just before return

Get here if didn't find a match already in cache.

Find least recently used (LRU) packet buffer

Publish buffer address to caller

Create lock so we are sure we will be unlocked when use is finished.

Increment cache lock just before return

Definition at line 85 of file Packet.cpp.

References e57::E57_ERROR_INTERNAL, E57_EXCEPTION2, QtCompat::endl(), entries_, lockCount_, PacketLock, readPacket(), e57::toString(), and useCount_.

Referenced by e57::CompressedVectorReaderImpl::CompressedVectorReaderImpl().

◆ readPacket()

void PacketReadCache::readPacket ( unsigned  oldestEntry,
uint64_t  packetLogicalOffset 
)
protected

Read header of packet first to get length. Use EmptyPacketHeader since it has the fields common to all packets.

Can't verify packet header here, because it is not really an EmptyPacketHeader.

Be paranoid about packetLength before read

Now read in whole packet into preallocated buffer_. Note buffer is

Verify that packet is good.

Mark entry with current useCount (keeps track of age of entry). This is a cache, so a small hiccup when useCount_ overflows won't hurt.

Definition at line 179 of file Packet.cpp.

References cFile_, e57::DATA_PACKET, e57::DATA_PACKET_MAX, e57::E57_ERROR_BAD_CV_PACKET, e57::E57_ERROR_INTERNAL, E57_EXCEPTION2, e57::EMPTY_PACKET, QtCompat::endl(), entries_, e57::INDEX_PACKET, e57::CheckedFile::Logical, EmptyPacketHeader::packetLogicalLengthMinus1, EmptyPacketHeader::packetType, e57::CheckedFile::read(), e57::CheckedFile::seek(), e57::toString(), useCount_, EmptyPacketHeader::verify(), e57::DataPacket::verify(), and IndexPacket::verify().

Referenced by lock().

◆ unlock()

void PacketReadCache::unlock ( unsigned  cacheIndex)
protected

Member Data Documentation

◆ cFile_

CheckedFile* e57::PacketReadCache::cFile_ = nullptr
protected

Definition at line 79 of file Packet.h.

Referenced by readPacket().

◆ entries_

std::vector<CacheEntry> e57::PacketReadCache::entries_
protected

Definition at line 81 of file Packet.h.

Referenced by dump(), lock(), and readPacket().

◆ lockCount_

unsigned e57::PacketReadCache::lockCount_ = 0
protected

Definition at line 77 of file Packet.h.

Referenced by dump(), lock(), and unlock().

◆ useCount_

unsigned e57::PacketReadCache::useCount_ = 0
protected

Definition at line 78 of file Packet.h.

Referenced by dump(), lock(), and readPacket().


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