NCBI C++ ToolKit
bytesrc.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: bytesrc.cpp 102658 2024-06-21 17:51:55Z gouriano $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: Eugene Vasilchenko
27  *
28  * File Description:
29  * Implementation of CByteSource and CByteSourceReader
30  * and their specializations'.
31  *
32  */
33 
34 #include <ncbi_pch.hpp>
35 #include <corelib/ncbistd.hpp>
36 #include <corelib/stream_utils.hpp>
37 #include <util/bytesrc.hpp>
38 #include <util/util_exception.hpp>
39 #include <util/error_codes.hpp>
40 #include <algorithm>
41 
42 
43 #define NCBI_USE_ERRCODE_X Util_ByteSrc
44 
45 
47 
48 
51 
52 /////////////////////////////////////////////////////////////////////////////
53 // CByteSource
54 /////////////////////////////////////////////////////////////////////////////
55 
57 {
58 }
59 
60 
62 {
63 }
64 
65 
66 /////////////////////////////////////////////////////////////////////////////
67 // CByteSourceReader
68 /////////////////////////////////////////////////////////////////////////////
69 
71 {
72 }
73 
74 
76 {
77 }
78 
79 
81 {
82  return true;
83 }
84 
85 
86 bool CByteSourceReader::Pushback(const char* /*data*/, size_t size)
87 {
88  if ( size ) {
89  ERR_POST_X(1, "CByteSourceReader::Pushback: "
90  "unable to push back " << size << " byte(s)");
91  return false;
92  }
93  return true;
94 }
95 
97 {
98  NCBI_THROW(CUtilException,eWrongCommand,"CByteSourceReader::Seekg: unable to seek");
99 }
100 
102 CByteSourceReader::SubSource(size_t /*prevent*/,
104 {
106 }
107 
108 
109 /////////////////////////////////////////////////////////////////////////////
110 // CSubSourceCollector
111 /////////////////////////////////////////////////////////////////////////////
112 
113 
115  : m_ParentCollector(parent)
116 {
117 }
118 
119 
121 {
122 }
123 
124 
125 void CSubSourceCollector::AddChunk(const char* buffer, size_t bufferLength)
126 {
127  if ( m_ParentCollector ) {
128  m_ParentCollector->AddChunk(buffer, bufferLength);
129  }
130 }
131 
132 
133 /////////////////////////////////////////////////////////////////////////////
134 // CStreamByteSource
135 /////////////////////////////////////////////////////////////////////////////
136 
137 /* Mac compiler doesn't like getting these flags as unsigned int (thiessen)
138 static inline
139 unsigned IFStreamFlags(bool binary)
140 {
141  return binary ? (IOS_BASE::in | IOS_BASE::binary) : IOS_BASE::in;
142 }
143 */
144 #define IFStreamFlags(isBinary) \
145  (isBinary? (IOS_BASE::in | IOS_BASE::binary): IOS_BASE::in)
146 
147 
149  : m_Stream(&in)
150 {
151 }
152 
153 
155 {
156 }
157 
158 
160 {
162  (new CStreamByteSourceReader(this, m_Stream));
163 }
164 
165 
166 /////////////////////////////////////////////////////////////////////////////
167 // CStreamByteSourceReader
168 /////////////////////////////////////////////////////////////////////////////
169 
171  CNcbiIstream* stream)
172  : m_Source(source), m_Stream(stream)
173 {
174 }
175 
176 
178 {
179 }
180 
181 
182 size_t CStreamByteSourceReader::Read(char* buffer, size_t bufferLength)
183 {
184  return (size_t)CStreamUtils::Readsome(*m_Stream, buffer, bufferLength);
185 }
186 
187 
189 {
190  return m_Stream->eof();
191 }
192 
193 
194 bool CStreamByteSourceReader::Pushback(const char* data, size_t size)
195 {
197  m_Stream->clear();
198  return true;
199 }
200 
201 
203 {
204  m_Stream->clear();
205  m_Stream->seekg(pos);
206  if (m_Stream->fail()) {
207  NCBI_THROW(CIOException, eRead, "Failed to set read position");
208  }
209 }
210 
211 
212 /////////////////////////////////////////////////////////////////////////////
213 // CIRByteSourceReader
214 /////////////////////////////////////////////////////////////////////////////
215 
217  : m_Reader(reader), m_EOF(false)
218 {
219 }
220 
221 
223 {
224 }
225 
226 
227 size_t CIRByteSourceReader::Read(char* buffer, size_t bufferLength)
228 {
229  size_t bytes_read;
230  ERW_Result result = m_Reader->Read(buffer, bufferLength, &bytes_read);
231  if ( result == eRW_Eof ) {
232  m_EOF = true;
233  }
234  return bytes_read;
235 }
236 
237 
239 {
240  return m_EOF;
241 }
242 
243 
244 /////////////////////////////////////////////////////////////////////////////
245 // CFStreamByteSource
246 /////////////////////////////////////////////////////////////////////////////
247 
250 {
251 }
252 
253 
254 CFStreamByteSource::CFStreamByteSource(const string& fileName, bool binary)
255  : CStreamByteSource(*new CNcbiIfstream(fileName.c_str(),
256  IFStreamFlags(binary)))
257 {
258  if ( !*m_Stream ) {
260  NCBI_THROW(CUtilException,eNoInput, string("No input data: ")
262  + string(": ") + fileName);
263  }
264 }
265 
266 
268 {
269  delete m_Stream;
270 }
271 
272 CMMapByteSource::CMMapByteSource(const string& fileName, size_t num_blocks)
273  : m_FileMap(fileName), m_CBlocks(num_blocks)
274 {
275 }
276 
278 {
279 }
280 
282 {
285 }
286 
287 
289  : m_Source(source), m_Fmap(fmap), m_Ptr(nullptr),
291  m_DefaultSize(0), m_ChunkOffset(0), m_CurOffset(0), m_NextOffset(0),
292  m_FileSize(fmap->GetFileSize())
293 {
294  if (num_blocks == 0) {
295  num_blocks = 128;
296  } else if (num_blocks == 1) {
297  num_blocks = 2;
298  }
299  if (m_UnitSize == 0) {
300  m_UnitSize = 64 * 1024;
301  }
302  m_DefaultSize = num_blocks * m_UnitSize;
303 }
304 
306 {
307  if (m_Ptr) {
308  m_Fmap->Unmap(m_Ptr);
309  }
310 }
311 
313 {
314  if (m_Ptr) {
315  m_Fmap->Unmap(m_Ptr);
316  m_Ptr = nullptr;
317  }
318  if (offset < m_FileSize) {
324  }
325 }
326 
327 size_t CMMapByteSourceReader::GetNextPart(char** buffer, size_t copy_count)
328 {
329  x_GetNextChunkAt(m_NextOffset - copy_count);
330  if (m_Ptr) {
332  size_t len = m_NextOffset - m_CurOffset;
334  return len;
335  }
336  return 0;
337 }
338 
339 size_t CMMapByteSourceReader::Read(char* buffer, size_t bufferLength)
340 {
341  if (m_CurOffset == m_NextOffset) {
343  }
344  size_t len = 0;
345  if (m_Ptr) {
346  len = min( m_NextOffset - m_CurOffset, bufferLength);
347  if (len != 0) {
348  memcpy(buffer, m_Ptr + (m_CurOffset - m_ChunkOffset), len);
349  m_CurOffset += len;
350  }
351  }
352  return len;
353 }
354 
356 {
357  return m_CurOffset >= m_FileSize;
358 }
359 
360 bool CMMapByteSourceReader::Pushback(const char* data, size_t size)
361 {
362  if (m_Ptr && (m_CurOffset >= m_ChunkOffset + size)) {
363  m_CurOffset -= size;
364  return true;
365  }
366  return false;
367 }
368 
370 {
371  m_NextOffset = pos;
372 }
373 
374 /////////////////////////////////////////////////////////////////////////////
375 // CFileByteSource
376 /////////////////////////////////////////////////////////////////////////////
377 
378 CFileByteSource::CFileByteSource(const string& fileName, bool binary)
379  : m_FileName(fileName), m_Binary(binary)
380 {
381  return;
382 }
383 
384 
386  : m_FileName(file.m_FileName), m_Binary(file.m_Binary)
387 {
388  return;
389 }
390 
391 
393 {
394 }
395 
396 
398 {
400 }
401 
402 
403 /////////////////////////////////////////////////////////////////////////////
404 // CSubFileByteSource
405 /////////////////////////////////////////////////////////////////////////////
406 
408  TFilePos start, TFileOff length)
409  : CParent(file), m_Start(start), m_Length(length)
410 {
411  return;
412 }
413 
414 
416 {
417 }
418 
419 
421 {
424 }
425 
426 /////////////////////////////////////////////////////////////////////////////
427 // CFileByteSourceReader
428 /////////////////////////////////////////////////////////////////////////////
429 
432  m_FileSource(source),
433  m_FStream(source->GetFileName().c_str(),
434  IFStreamFlags(source->IsBinary()))
435 {
436  if ( !m_FStream ) {
437 // THROW1_TRACE(runtime_error, "file not found: " +
438 // source->GetFileName());
440  NCBI_THROW(CUtilException,eNoInput, string("No input data: ")
442  + string(": ") + source->GetFileName());
443  }
444  m_Stream = &m_FStream;
445 }
446 
447 
449 {
450 }
451 
452 
456 {
458  m_Stream->tellg() - TFileOff(prepend),
459  parent));
460 }
461 
462 /////////////////////////////////////////////////////////////////////////////
463 // CSubFileByteSourceReader
464 /////////////////////////////////////////////////////////////////////////////
465 
467  TFilePos start,
468  TFileOff length)
469  : CParent(s), m_Length(length)
470 {
471  m_Stream->seekg(start);
472 }
473 
474 
476 {
477 }
478 
479 
480 size_t CSubFileByteSourceReader::Read(char* buffer, size_t bufferLength)
481 {
482  if ( TFileOff(bufferLength) > m_Length ) {
483  bufferLength = size_t(m_Length);
484  }
485  size_t count = CParent::Read(buffer, bufferLength);
486  m_Length -= TFileOff(count);
487  return count;
488 }
489 
490 
492 {
493  return m_Length == 0;
494 }
495 
496 
497 /////////////////////////////////////////////////////////////////////////////
498 // CFileSourceCollector
499 /////////////////////////////////////////////////////////////////////////////
500 
501 
503  TFilePos start,
505  : CSubSourceCollector(parent),
506  m_FileSource(s),
507  m_Start(start),
508  m_Length(0)
509 {
510 }
511 
512 
514 {
515 }
516 
517 
519  size_t bufferLength)
520 {
521  CSubSourceCollector::AddChunk(buffer, bufferLength);
522  m_Length += TFileOff(bufferLength);
523 }
524 
525 
527 {
529  m_Start, m_Length));
530 }
531 
532 
533 /////////////////////////////////////////////////////////////////////////////
534 // CMemoryChunk
535 /////////////////////////////////////////////////////////////////////////////
536 
537 CMemoryChunk::CMemoryChunk(const char* data, size_t dataSize,
538  CRef<CMemoryChunk> prevChunk, ECopyData copy /*= eCopyData*/)
539  : m_DataSize(dataSize),
540  m_CopyData(copy)
541 {
542  if (m_CopyData == eNoCopyData) {
543  m_Data = data;
544  } else {
545  char *buffer = new char[dataSize];
546  memcpy(buffer, data, dataSize);
547  m_Data = buffer;
548  }
549  if ( prevChunk ) {
550  prevChunk->m_NextChunk = this;
551  }
552 }
553 
555 {
556  if (m_CopyData != eNoCopyData) {
557  delete[] m_Data;
558  }
560  m_NextChunk.Reset();
561  while ( next && next->ReferencedOnlyOnce() ) {
562  CRef<CMemoryChunk> cur = next;
563  next = cur->m_NextChunk;
564  cur->m_NextChunk.Reset();
565  }
566 }
567 
568 
569 /////////////////////////////////////////////////////////////////////////////
570 // CMemoryByteSource
571 /////////////////////////////////////////////////////////////////////////////
572 
574  : m_Bytes(bytes)
575 {
576 }
577 
578 
580 {
581 }
582 
583 
585 {
587 }
588 
589 
590 /////////////////////////////////////////////////////////////////////////////
591 // CMemoryByteSourceReader
592 /////////////////////////////////////////////////////////////////////////////
593 
594 
596  : m_CurrentChunk(bytes), m_CurrentChunkOffset(0)
597 {
598 }
599 
600 
602 {
603 }
604 
605 
606 size_t CMemoryByteSourceReader::Read(char* buffer, size_t bufferLength)
607 {
608  while ( m_CurrentChunk ) {
609  size_t avail = GetCurrentChunkAvailable();
610  if ( avail == 0 ) {
611  // End of current chunk
613  m_CurrentChunk = rest;
615  }
616  else {
617  size_t c = min(bufferLength, avail);
620  return c;
621  }
622  }
623  return 0;
624 }
625 
626 
628 {
629  if (!m_CurrentChunk) {
630  return true;
631  }
632  if (GetCurrentChunkAvailable() != 0) {
633  return false;
634  }
635  return !(m_CurrentChunk->GetNextChunk());
636 }
637 
638 bool CMemoryByteSourceReader::Pushback(const char* data, size_t size)
639 {
640  if (m_CurrentChunkOffset >= size) {
642  return true;
643  }
645 }
646 
647 size_t CMemoryByteSourceReader::GetNextPart(char** buffer, size_t /*copy_count*/)
648 {
649  while ( m_CurrentChunk ) {
650  size_t avail = GetCurrentChunkAvailable();
651  if ( avail == 0 ) {
652  // End of current chunk
654  m_CurrentChunk = rest;
656  }
657  else {
658  size_t c = avail;
659  *buffer = const_cast<char*>(m_CurrentChunk->GetData(m_CurrentChunkOffset));
661  return c;
662  }
663  }
664  return 0;
665 }
666 
667 
668 /////////////////////////////////////////////////////////////////////////////
669 // CMemorySourceCollector
670 /////////////////////////////////////////////////////////////////////////////
671 
673  parent, bool no_copy)
674  : CSubSourceCollector(parent),
675  m_CopyData(no_copy ? CMemoryChunk::eNoCopyData : CMemoryChunk::eCopyData)
676 {
677 }
678 
679 
681 {
682 }
683 
684 
686  size_t bufferLength)
687 {
688  CSubSourceCollector::AddChunk(buffer, bufferLength);
689  m_LastChunk = new CMemoryChunk(buffer, bufferLength, m_LastChunk, m_CopyData);
690  if ( !m_FirstChunk ) {
692  }
693 }
694 
695 
697 {
699 }
700 
701 
702 /////////////////////////////////////////////////////////////////////////////
703 // CWriterSourceCollector
704 /////////////////////////////////////////////////////////////////////////////
705 
707  EOwnership own,
709  : CSubSourceCollector(parent),
710  m_Writer(writer),
711  m_Own(own)
712 {
713  return;
714 }
715 
716 
718 {
719  if ( m_Own ) {
720  delete m_Writer;
721  }
722 }
723 
724 
726  EOwnership own)
727 {
728  if ( m_Own ) {
729  delete m_Writer;
730  }
731  m_Writer = writer;
732  m_Own = own;
733 }
734 
735 
736 void CWriterSourceCollector::AddChunk(const char* buffer, size_t bufferLength)
737 {
738  CSubSourceCollector::AddChunk(buffer, bufferLength);
739  while ( bufferLength ) {
740  size_t written;
741  m_Writer->Write(buffer, bufferLength, &written);
742  buffer += written;
743  bufferLength -= written;
744  }
745 }
746 
747 
749 {
750  // Return NULL byte source, this happens because we cannot derive
751  // any readers from IWriter (one way interface)
752  return CRef<CByteSource>();
753 }
754 
755 
756 /////////////////////////////////////////////////////////////////////////////
757 // CWriterByteSourceReader
758 /////////////////////////////////////////////////////////////////////////////
759 
761  IWriter* writer)
762  : CStreamByteSourceReader(0 /* CByteSource* */, stream),
763  m_Writer(writer)
764 {
765  _ASSERT(writer);
766 }
767 
768 
770 {
771 }
772 
773 
777 {
778  return
781 }
782 
783 
784 /////////////////////////////////////////////////////////////////////////////
785 // CWriterCopyByteSourceReader
786 /////////////////////////////////////////////////////////////////////////////
787 
789  : m_Reader(reader),
790  m_Writer(writer)
791 {
792  _ASSERT(reader);
793  _ASSERT(writer);
794 }
795 
796 
798 {
799 }
800 
801 
802 size_t CWriterCopyByteSourceReader::Read(char* buffer, size_t bufferLength)
803 {
804  return m_Reader->Read(buffer, bufferLength);
805 }
806 
807 
809 {
810  return m_Reader->EndOfData();
811 }
812 
813 
817 {
818  return
821 }
822 
823 
CFileSourceCollector::TFilePos TFilePos
Definition: bytesrc.cpp:49
#define IFStreamFlags(isBinary)
Definition: bytesrc.cpp:144
CFileSourceCollector::TFileOff TFileOff
Definition: bytesrc.cpp:50
CMemoryFileMap –.
Definition: ncbifile.hpp:2669
Abstract class for implementing "sub collectors".
Definition: bytesrc.hpp:113
CSystemInfo –.
Class adapter IWriter - CSubSourceCollector.
Definition: bytesrc.hpp:437
A very basic data-read interface.
A very basic data-write interface.
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define false
Definition: bool.h:36
static void DLIST_NAME() prepend(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
Definition: dlist.tmpl.h:66
static DLIST_TYPE *DLIST_NAME() next(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
Definition: dlist.tmpl.h:56
int offset
Definition: replacements.h:160
char data[12]
Definition: iconv.c:80
@ eNoOwnership
No ownership is assumed.
Definition: ncbi_types.h:135
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
Definition: ncbidiag.hpp:550
#define NCBI_ERRNO_CODE_WRAPPER
Definition: ncbiexpt.hpp:1529
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
static void SetFromErrno(void)
Set last error using current "errno" code.
Definition: ncbierror.cpp:220
#define NCBI_ERRNO_STR_WRAPPER
Definition: ncbiexpt.hpp:1530
void * Map(TOffsetType offset, size_t length)
Map file segment.
Definition: ncbifile.cpp:5786
size_t GetSize(void *ptr) const
Get length of the mapped segment.
Definition: ncbifile.hpp:4260
bool MemMapAdvise(void *ptr, EMemMapAdvise advise) const
Advise on mapped memory map usage.
Definition: ncbifile.hpp:4272
bool Unmap(void *ptr)
Unmap file segment.
Definition: ncbifile.cpp:5824
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
CRef< CSubSourceCollector > m_ParentCollector
Pointer on parent (or chained) collector.
Definition: bytesrc.hpp:148
CRef< CMemoryChunk > m_LastChunk
Definition: bytesrc.hpp:430
CRef< CSubSourceCollector > SubSource(size_t prepend, CRef< CSubSourceCollector > parent)
Definition: bytesrc.cpp:454
virtual bool IsMultiPart(void) const
Definition: bytesrc.hpp:91
const char * GetData(size_t offset) const
Definition: bytesrc.hpp:354
CNcbiIstream * m_Stream
Definition: bytesrc.hpp:248
CFileSourceCollector::TFilePos TFilePos
Definition: bytesrc.hpp:520
bool Pushback(const char *data, size_t size)
Definition: bytesrc.cpp:360
TFileOff m_Length
Definition: bytesrc.hpp:512
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.
Definition: bytesrc.cpp:627
TFilePos m_Start
Definition: bytesrc.hpp:511
~CFileByteSource(void)
Definition: bytesrc.cpp:392
~CStreamByteSource(void)
Definition: bytesrc.cpp:154
CNcbiIfstream m_FStream
Definition: bytesrc.hpp:339
size_t Read(char *buffer, size_t bufferLength)
Read up to bufferLength bytes into buffer return amount of bytes read (if zero - see EndOfData())
Definition: bytesrc.cpp:339
CMMapByteSourceReader(const CByteSource *source, CMemoryFileMap *fmap, size_t num_blocks=0)
Definition: bytesrc.cpp:288
~CFileSourceCollector(void)
Definition: bytesrc.cpp:513
CConstRef< CFileByteSource > m_FileSource
Definition: bytesrc.hpp:487
virtual size_t GetNextPart(char **buffer, size_t copy_count)
Definition: bytesrc.cpp:327
CStreamByteSourceReader(const CByteSource *source, CNcbiIstream *stream)
Definition: bytesrc.cpp:170
virtual CRef< CByteSource > GetSource(void)
Return pointer on "reader" interface.
Definition: bytesrc.cpp:748
CRef< CMemoryChunk > m_NextChunk
Definition: bytesrc.hpp:368
virtual ~CMMapByteSource(void)
Definition: bytesrc.cpp:277
IReader * m_Reader
Definition: bytesrc.hpp:264
virtual void Seekg(CNcbiStreampos pos)
Definition: bytesrc.cpp:202
CRef< CByteSourceReader > Open(void)
Definition: bytesrc.cpp:584
~CMemoryChunk(void)
Definition: bytesrc.cpp:554
CRef< CByteSourceReader > Open(void)
Definition: bytesrc.cpp:159
bool EndOfData(void) const
Call this method after Read returned zero to determine whether end of data reached or error occurred.
Definition: bytesrc.cpp:355
CNcbiIstream::pos_type TFilePos
Definition: bytesrc.hpp:475
virtual bool EndOfData(void) const
Call this method after Read returned zero to determine whether end of data reached or error occurred.
Definition: bytesrc.cpp:80
CSubSourceCollector(CRef< CSubSourceCollector > parent)
Constructor.
Definition: bytesrc.cpp:114
virtual CRef< CSubSourceCollector > SubSource(size_t prepend, CRef< CSubSourceCollector > parent)
Create CWriterSourceCollector.
Definition: bytesrc.cpp:775
bool EndOfData(void) const
Call this method after Read returned zero to determine whether end of data reached or error occurred.
Definition: bytesrc.cpp:491
CMMapByteSource(const string &fileName, size_t num_blocks=0)
Definition: bytesrc.cpp:272
virtual void Seekg(CNcbiStreampos pos)
Definition: bytesrc.cpp:96
CMemoryByteSource(CConstRef< CMemoryChunk > bytes)
Definition: bytesrc.cpp:573
virtual void AddChunk(const char *buffer, size_t bufferLength)
Add data to the sub-source.
Definition: bytesrc.cpp:125
virtual CRef< CByteSourceReader > Open(void)
Definition: bytesrc.cpp:281
CConstRef< CMemoryChunk > m_Bytes
Definition: bytesrc.hpp:385
CRef< CByteSourceReader > m_Reader
Definition: bytesrc.hpp:324
virtual CRef< CByteSource > GetSource(void)
Get CByteSource implementation.
Definition: bytesrc.cpp:696
size_t Read(char *buffer, size_t bufferLength)
Read up to bufferLength bytes into buffer return amount of bytes read (if zero - see EndOfData())
Definition: bytesrc.cpp:227
~CFileByteSourceReader(void)
Definition: bytesrc.cpp:448
CNcbiIstream::off_type TFileOff
Definition: bytesrc.hpp:476
CFStreamByteSource(CNcbiIstream &in)
Definition: bytesrc.cpp:248
CRef< CMemoryChunk > GetNextChunk(void) const
Definition: bytesrc.hpp:358
CMemoryFileMap m_FileMap
Definition: bytesrc.hpp:205
CByteSourceReader(void)
Definition: bytesrc.cpp:70
const char * m_Data
Definition: bytesrc.hpp:365
virtual void AddChunk(const char *buffer, size_t bufferLength)
Add data to the sub-source.
Definition: bytesrc.cpp:685
CSubFileByteSource(const CFileByteSource &file, TFilePos start, TFileOff length)
Definition: bytesrc.cpp:407
~CIRByteSourceReader(void)
Definition: bytesrc.cpp:222
CFileSourceCollector::TFileOff TFileOff
Definition: bytesrc.hpp:498
CMemoryChunk(const char *data, size_t dataSize, CRef< CMemoryChunk > prevChunk, ECopyData copy=eCopyData)
Definition: bytesrc.cpp:537
virtual void Seekg(CNcbiStreampos pos)
Definition: bytesrc.cpp:369
void x_GetNextChunkAt(size_t offset)
Definition: bytesrc.cpp:312
virtual ~CByteSourceReader(void)
Definition: bytesrc.cpp:75
IWriter * m_Writer
Destination interface pointer.
Definition: bytesrc.hpp:467
CFileByteSource(const string &name, bool binary)
Definition: bytesrc.cpp:378
size_t m_CBlocks
Definition: bytesrc.hpp:206
CFileSourceCollector(CConstRef< CFileByteSource > source, TFilePos start, CRef< CSubSourceCollector > parent)
Definition: bytesrc.cpp:502
CRef< CByteSourceReader > Open(void)
Definition: bytesrc.cpp:397
virtual ~CWriterSourceCollector()
Definition: bytesrc.cpp:717
EOwnership m_Own
Flag to delete IWriter on destruction.
Definition: bytesrc.hpp:468
virtual size_t GetNextPart(char **buffer, size_t copy_count)
Definition: bytesrc.cpp:647
CWriterCopyByteSourceReader(CByteSourceReader *reader, IWriter *writer)
Constructor.
Definition: bytesrc.cpp:788
size_t Read(char *buffer, size_t bufferLength)
Read up to bufferLength bytes into buffer return amount of bytes read (if zero - see EndOfData())
Definition: bytesrc.cpp:182
ECopyData m_CopyData
Definition: bytesrc.hpp:367
virtual bool Pushback(const char *data, size_t size)
Definition: bytesrc.cpp:86
CConstRef< CMemoryChunk > m_CurrentChunk
Definition: bytesrc.hpp:412
CByteSource(void)
Definition: bytesrc.cpp:56
virtual bool Pushback(const char *data, size_t size)
Definition: bytesrc.cpp:638
~CSubFileByteSource(void)
Definition: bytesrc.cpp:415
void SetWriter(IWriter *writer, EOwnership own)
Reset the destination IWriter interface.
Definition: bytesrc.cpp:725
virtual void AddChunk(const char *buffer, size_t bufferLength)
Add data to the sub-source.
Definition: bytesrc.cpp:736
~CMemoryByteSource(void)
Definition: bytesrc.cpp:579
CNcbiIstream * m_Stream
Definition: bytesrc.hpp:161
size_t Read(char *buffer, size_t bufferLength)
Just call Read method on source reader.
Definition: bytesrc.cpp:802
CFileSourceCollector::TFilePos TFilePos
Definition: bytesrc.hpp:497
virtual void AddChunk(const char *buffer, size_t bufferLength)
Add data to the sub-source.
Definition: bytesrc.cpp:518
~CFStreamByteSource(void)
Definition: bytesrc.cpp:267
virtual CRef< CSubSourceCollector > SubSource(size_t prepend, CRef< CSubSourceCollector > parent)
Create CWriterSourceCollector.
Definition: bytesrc.cpp:815
CIRByteSourceReader(IReader *reader)
Definition: bytesrc.cpp:216
size_t Read(char *buffer, size_t bufferLength)
Read up to bufferLength bytes into buffer return amount of bytes read (if zero - see EndOfData())
Definition: bytesrc.cpp:606
size_t GetCurrentChunkAvailable(void) const
Definition: bytesrc.hpp:406
CSubFileByteSourceReader(const CFileByteSource *source, TFilePos start, TFileOff length)
Definition: bytesrc.cpp:466
CWriterByteSourceReader(CNcbiIstream *stream, IWriter *writer)
Constructor.
Definition: bytesrc.cpp:760
CConstRef< CMemoryChunk > m_FirstChunk
Definition: bytesrc.hpp:429
CConstRef< CFileByteSource > m_FileSource
Definition: bytesrc.hpp:338
bool EndOfData(void) const
Call this method after Read returned zero to determine whether end of data reached or error occurred.
Definition: bytesrc.cpp:238
CMemoryChunk::ECopyData m_CopyData
Definition: bytesrc.hpp:431
~CMMapByteSourceReader(void)
Definition: bytesrc.cpp:305
CMemoryByteSourceReader(CConstRef< CMemoryChunk > bytes)
Definition: bytesrc.cpp:595
CMemorySourceCollector(CRef< CSubSourceCollector > parent=CRef< CSubSourceCollector >(), bool no_copy=false)
Definition: bytesrc.cpp:672
bool Pushback(const char *data, size_t size)
Definition: bytesrc.cpp:194
virtual ~CSubSourceCollector(void)
Definition: bytesrc.cpp:120
virtual CRef< CByteSource > GetSource(void)
Get CByteSource implementation.
Definition: bytesrc.cpp:526
CFileByteSourceReader(const CFileByteSource *source)
Definition: bytesrc.cpp:430
virtual ~CByteSource(void)
Definition: bytesrc.cpp:61
CWriterSourceCollector(IWriter *writer, EOwnership own, CRef< CSubSourceCollector > parent)
Constructor.
Definition: bytesrc.cpp:706
size_t Read(char *buffer, size_t bufferLength)
Read up to bufferLength bytes into buffer return amount of bytes read (if zero - see EndOfData())
Definition: bytesrc.cpp:480
virtual CRef< CSubSourceCollector > SubSource(size_t prepend, CRef< CSubSourceCollector > parent)
Definition: bytesrc.cpp:102
CMemoryFileMap * m_Fmap
Definition: bytesrc.hpp:229
CFileSourceCollector::TFileOff TFileOff
Definition: bytesrc.hpp:521
bool EndOfData(void) const
Just call EndOfData method on source reader.
Definition: bytesrc.cpp:808
CStreamByteSource(CNcbiIstream &in)
Definition: bytesrc.cpp:148
bool EndOfData(void) const
Call this method after Read returned zero to determine whether end of data reached or error occurred.
Definition: bytesrc.cpp:188
CRef< CByteSourceReader > Open(void)
Definition: bytesrc.cpp:420
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.
Definition: ncbistre.hpp:146
static streamsize Readsome(CNcbiIstream &is, CT_CHAR_TYPE *buf, streamsize buf_size)
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
Definition: ncbistre.hpp:439
#define CT_CHAR_TYPE
Definition: ncbistre.hpp:729
IO_PREFIX::streampos CNcbiStreampos
Portable alias for streampos.
Definition: ncbistre.hpp:134
@ 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).
FILE * file
int len
const struct ncbi::grid::netcache::search::fields::SIZE size
const CharType(& source)[N]
Definition: pointer.h:1149
unsigned long GetVirtualMemoryAllocationGranularity(void)
Return size of an allocation unit (usually it is a multiple of page size).
#define nullptr
Definition: ncbimisc.hpp:45
T min(T x_, T y_)
std::istream & in(std::istream &in_, double &x_)
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
Definition: njn_matrix.hpp:613
@ eRead
Definition: ns_types.hpp:56
#define count
static uint8_t * buffer
Definition: pcre2test.c:1016
#define _ASSERT
else result
Definition: token2.c:20
Modified on Fri Sep 20 14:57:36 2024 by modify_doxy.py rev. 669887