43 #define NCBI_USE_ERRCODE_X Util_ByteSrc
90 "unable to push back " <<
size <<
" byte(s)");
115 : m_ParentCollector(parent)
144 #define IFStreamFlags(isBinary) \
145 (isBinary? (IOS_BASE::in | IOS_BASE::binary): IOS_BASE::in)
172 : m_Source(
source), m_Stream(stream)
217 : m_Reader(reader), m_EOF(
false)
262 +
string(
": ") + fileName);
273 : m_FileMap(fileName), m_CBlocks(num_blocks)
291 m_DefaultSize(0), m_ChunkOffset(0), m_CurOffset(0), m_NextOffset(0),
292 m_FileSize(fmap->GetFileSize())
294 if (num_blocks == 0) {
296 }
else if (num_blocks == 1) {
379 : m_FileName(fileName), m_Binary(binary)
386 : m_FileName(
file.m_FileName), m_Binary(
file.m_Binary)
433 m_FStream(
source->GetFileName().c_str(),
442 +
string(
": ") +
source->GetFileName());
539 : m_DataSize(dataSize),
545 char *
buffer =
new char[dataSize];
561 while (
next &&
next->ReferencedOnlyOnce() ) {
596 : m_CurrentChunk(bytes), m_CurrentChunkOffset(0)
617 size_t c =
min(bufferLength, avail);
673 parent,
bool no_copy)
739 while ( bufferLength ) {
743 bufferLength -= written;
CFileSourceCollector::TFilePos TFilePos
#define IFStreamFlags(isBinary)
CFileSourceCollector::TFileOff TFileOff
Abstract class for implementing "sub collectors".
Class adapter IWriter - CSubSourceCollector.
A very basic data-read interface.
A very basic data-write interface.
Include a standard set of the NCBI C++ Toolkit most basic headers.
static void DLIST_NAME() prepend(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
static DLIST_TYPE *DLIST_NAME() next(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
@ eNoOwnership
No ownership is assumed.
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
#define NCBI_ERRNO_CODE_WRAPPER
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
static void SetFromErrno(void)
Set last error using current "errno" code.
#define NCBI_ERRNO_STR_WRAPPER
void * Map(TOffsetType offset, size_t length)
Map file segment.
size_t GetSize(void *ptr) const
Get length of the mapped segment.
bool MemMapAdvise(void *ptr, EMemMapAdvise advise) const
Advise on mapped memory map usage.
bool Unmap(void *ptr)
Unmap file segment.
void Reset(void)
Reset reference object.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
CRef< CSubSourceCollector > m_ParentCollector
Pointer on parent (or chained) collector.
CRef< CMemoryChunk > m_LastChunk
CRef< CSubSourceCollector > SubSource(size_t prepend, CRef< CSubSourceCollector > parent)
virtual bool IsMultiPart(void) const
const char * GetData(size_t offset) const
CFileSourceCollector::TFilePos TFilePos
bool Pushback(const char *data, size_t size)
~CMemoryByteSourceReader(void)
virtual size_t Read(char *buffer, size_t bufferLength)=0
Read up to bufferLength bytes into buffer return amount of bytes read (if zero - see EndOfData())
bool EndOfData(void) const
Call this method after Read returned zero to determine whether end of data reached or error occurred.
size_t Read(char *buffer, size_t bufferLength)
Read up to bufferLength bytes into buffer return amount of bytes read (if zero - see EndOfData())
~CSubFileByteSourceReader(void)
CMMapByteSourceReader(const CByteSource *source, CMemoryFileMap *fmap, size_t num_blocks=0)
~CStreamByteSourceReader(void)
~CFileSourceCollector(void)
CConstRef< CFileByteSource > m_FileSource
virtual size_t GetNextPart(char **buffer, size_t copy_count)
CStreamByteSourceReader(const CByteSource *source, CNcbiIstream *stream)
virtual CRef< CByteSource > GetSource(void)
Return pointer on "reader" interface.
CRef< CMemoryChunk > m_NextChunk
virtual ~CMMapByteSource(void)
virtual void Seekg(CNcbiStreampos pos)
CRef< CByteSourceReader > Open(void)
CRef< CByteSourceReader > Open(void)
bool EndOfData(void) const
Call this method after Read returned zero to determine whether end of data reached or error occurred.
CNcbiIstream::pos_type TFilePos
virtual bool EndOfData(void) const
Call this method after Read returned zero to determine whether end of data reached or error occurred.
CSubSourceCollector(CRef< CSubSourceCollector > parent)
Constructor.
virtual CRef< CSubSourceCollector > SubSource(size_t prepend, CRef< CSubSourceCollector > parent)
Create CWriterSourceCollector.
bool EndOfData(void) const
Call this method after Read returned zero to determine whether end of data reached or error occurred.
CMMapByteSource(const string &fileName, size_t num_blocks=0)
virtual void Seekg(CNcbiStreampos pos)
CMemoryByteSource(CConstRef< CMemoryChunk > bytes)
virtual void AddChunk(const char *buffer, size_t bufferLength)
Add data to the sub-source.
~CWriterByteSourceReader(void)
virtual CRef< CByteSourceReader > Open(void)
CConstRef< CMemoryChunk > m_Bytes
CRef< CByteSourceReader > m_Reader
virtual CRef< CByteSource > GetSource(void)
Get CByteSource implementation.
size_t Read(char *buffer, size_t bufferLength)
Read up to bufferLength bytes into buffer return amount of bytes read (if zero - see EndOfData())
~CFileByteSourceReader(void)
CNcbiIstream::off_type TFileOff
CFStreamByteSource(CNcbiIstream &in)
CRef< CMemoryChunk > GetNextChunk(void) const
virtual void AddChunk(const char *buffer, size_t bufferLength)
Add data to the sub-source.
CSubFileByteSource(const CFileByteSource &file, TFilePos start, TFileOff length)
~CIRByteSourceReader(void)
CFileSourceCollector::TFileOff TFileOff
CMemoryChunk(const char *data, size_t dataSize, CRef< CMemoryChunk > prevChunk, ECopyData copy=eCopyData)
virtual void Seekg(CNcbiStreampos pos)
void x_GetNextChunkAt(size_t offset)
virtual ~CByteSourceReader(void)
IWriter * m_Writer
Destination interface pointer.
CFileByteSource(const string &name, bool binary)
CFileSourceCollector(CConstRef< CFileByteSource > source, TFilePos start, CRef< CSubSourceCollector > parent)
CRef< CByteSourceReader > Open(void)
virtual ~CWriterSourceCollector()
EOwnership m_Own
Flag to delete IWriter on destruction.
virtual size_t GetNextPart(char **buffer, size_t copy_count)
CWriterCopyByteSourceReader(CByteSourceReader *reader, IWriter *writer)
Constructor.
size_t Read(char *buffer, size_t bufferLength)
Read up to bufferLength bytes into buffer return amount of bytes read (if zero - see EndOfData())
virtual bool Pushback(const char *data, size_t size)
CConstRef< CMemoryChunk > m_CurrentChunk
~CWriterCopyByteSourceReader(void)
virtual bool Pushback(const char *data, size_t size)
~CSubFileByteSource(void)
void SetWriter(IWriter *writer, EOwnership own)
Reset the destination IWriter interface.
virtual void AddChunk(const char *buffer, size_t bufferLength)
Add data to the sub-source.
size_t Read(char *buffer, size_t bufferLength)
Just call Read method on source reader.
CFileSourceCollector::TFilePos TFilePos
virtual void AddChunk(const char *buffer, size_t bufferLength)
Add data to the sub-source.
~CFStreamByteSource(void)
virtual CRef< CSubSourceCollector > SubSource(size_t prepend, CRef< CSubSourceCollector > parent)
Create CWriterSourceCollector.
CIRByteSourceReader(IReader *reader)
size_t Read(char *buffer, size_t bufferLength)
Read up to bufferLength bytes into buffer return amount of bytes read (if zero - see EndOfData())
size_t m_CurrentChunkOffset
size_t GetCurrentChunkAvailable(void) const
CSubFileByteSourceReader(const CFileByteSource *source, TFilePos start, TFileOff length)
CWriterByteSourceReader(CNcbiIstream *stream, IWriter *writer)
Constructor.
CConstRef< CMemoryChunk > m_FirstChunk
CConstRef< CFileByteSource > m_FileSource
bool EndOfData(void) const
Call this method after Read returned zero to determine whether end of data reached or error occurred.
CMemoryChunk::ECopyData m_CopyData
~CMMapByteSourceReader(void)
CMemoryByteSourceReader(CConstRef< CMemoryChunk > bytes)
CMemorySourceCollector(CRef< CSubSourceCollector > parent=CRef< CSubSourceCollector >(), bool no_copy=false)
bool Pushback(const char *data, size_t size)
virtual ~CSubSourceCollector(void)
virtual CRef< CByteSource > GetSource(void)
Get CByteSource implementation.
CFileByteSourceReader(const CFileByteSource *source)
virtual ~CByteSource(void)
~CMemorySourceCollector(void)
CWriterSourceCollector(IWriter *writer, EOwnership own, CRef< CSubSourceCollector > parent)
Constructor.
size_t Read(char *buffer, size_t bufferLength)
Read up to bufferLength bytes into buffer return amount of bytes read (if zero - see EndOfData())
virtual CRef< CSubSourceCollector > SubSource(size_t prepend, CRef< CSubSourceCollector > parent)
CFileSourceCollector::TFileOff TFileOff
bool EndOfData(void) const
Just call EndOfData method on source reader.
CStreamByteSource(CNcbiIstream &in)
bool EndOfData(void) const
Call this method after Read returned zero to determine whether end of data reached or error occurred.
CRef< CByteSourceReader > Open(void)
ERW_Result
Result codes for I/O operations.
virtual ERW_Result Write(const void *buf, size_t count, size_t *bytes_written=0)=0
Write up to "count" bytes from the buffer pointed to by the "buf" argument onto the output device.
static void Stepback(CNcbiIstream &is, CT_CHAR_TYPE *buf, streamsize buf_size, void *del_ptr=0)
virtual ERW_Result Read(void *buf, size_t count, size_t *bytes_read=0)=0
Read as many as "count" bytes into a buffer pointed to by the "buf" argument.
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
static streamsize Readsome(CNcbiIstream &is, CT_CHAR_TYPE *buf, streamsize buf_size)
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
IO_PREFIX::streampos CNcbiStreampos
Portable alias for streampos.
@ eRW_Eof
End of data, should be considered permanent.
enum ENcbiOwnership EOwnership
Ownership relations between objects.
Definition of all error codes used in util (xutil.lib).
const struct ncbi::grid::netcache::search::fields::SIZE size
const CharType(& source)[N]
unsigned long GetVirtualMemoryAllocationGranularity(void)
Return size of an allocation unit (usually it is a multiple of page size).
std::istream & in(std::istream &in_, double &x_)
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)