41 #define NCBI_USE_ERRCODE_X Util_Stream
57 : m_Error(0), m_BufferPos(0),
58 m_BufferSize(0), m_Buffer(0),
59 m_CurrentPos(0), m_DataEndPos(0),
62 m_CanceledCallback(0),
69 : m_Error(0), m_BufferPos(0),
70 m_BufferSize(0), m_Buffer(const_cast<char*>(
buffer)),
74 m_CanceledCallback(0),
85 NCBI_CATCH_X(1,
"~CIStreamBuffer: exception while closing");
217 const char* pos = m_CurrentPos;
218 const char* end = m_DataEndPos;
222 pos = FillBuffer(pos);
244 }
while ( ++pos < end );
249 pos = FillBuffer(pos);
261 const char* pos = m_CurrentPos;
262 const char* end = m_DataEndPos;
266 pos = FillBuffer(pos);
276 const void* found = memchr(pos, c, end - pos);
278 m_CurrentPos =
static_cast<const char*
>(found);
284 pos = FillBuffer(end);
296 PeekCharNoEOF(limit - 1);
298 const char* pos = m_CurrentPos;
299 size_t bufferSize = m_DataEndPos - pos;
300 if ( bufferSize != 0 ) {
301 const void* found = memchr(pos, c,
min(limit, bufferSize));
303 return static_cast<const char*
>(found) - pos;
322 if (
const ICanceled* callback = m_CanceledCallback ) {
323 if ( callback->IsCanceled() ) {
324 m_Error =
"canceled";
330 _ASSERT(m_CurrentPos >= m_Buffer);
331 if ( m_BufferSize == 0 ) {
332 if (m_Input.NotNull() && m_Input->IsMultiPart()) {
336 size_t count = m_CurrentPos - m_CollectPos;
338 m_Collector->AddChunk(m_CollectPos,
count);
340 m_BufferPos += (m_DataEndPos - m_Buffer);
341 m_BufferSize = m_Input->GetNextPart(&m_Buffer, m_DataEndPos - m_CurrentPos);
342 m_CurrentPos = m_Buffer;
343 m_DataEndPos = m_Buffer + m_BufferSize;
345 m_CollectPos = m_CurrentPos;
348 if (m_CurrentPos != m_DataEndPos) {
357 m_Error =
"end of file";
361 size_t newPosOffset = pos - m_Buffer;
362 if ( m_BufferLockSize == 0 &&
363 (newPosOffset >= m_BufferSize || m_DataEndPos == m_CurrentPos) ) {
366 size_t erase = m_CurrentPos - m_Buffer;
368 const char* newPos = m_CurrentPos - erase;
371 size_t count = m_CurrentPos - m_CollectPos;
373 m_Collector->AddChunk(m_CollectPos,
count);
374 m_CollectPos = newPos;
376 size_t copy_count = m_DataEndPos - m_CurrentPos;
378 memmove(
const_cast<char*
>(newPos), m_CurrentPos, copy_count);
379 m_CurrentPos = newPos;
380 m_DataEndPos -= erase;
383 newPosOffset -= erase;
386 size_t dataSize = m_DataEndPos - m_Buffer;
387 if ( newPosOffset >= m_BufferSize ) {
390 while ( newPosOffset >= newSize ) {
393 if ( m_BufferLockSize != 0 ) {
394 newSize =
min(newSize, m_BufferLockSize);
395 if ( newPosOffset >= newSize ) {
399 char* newBuffer =
new char[newSize];
400 memcpy(newBuffer, m_Buffer, dataSize);
401 m_CurrentPos = newBuffer + (m_CurrentPos - m_Buffer);
403 m_CollectPos = newBuffer + (m_CollectPos - m_Buffer);
404 pos = newBuffer + newPosOffset;
405 m_DataEndPos = newBuffer + dataSize;
407 m_Buffer = newBuffer;
408 m_BufferSize = newSize;
410 size_t load = m_BufferSize - dataSize;
411 while ( load > 0 && pos >= m_DataEndPos ) {
416 m_Error =
"end of file";
419 size_t count = m_Input->Read(
const_cast<char*
>(m_DataEndPos), load);
421 if ( pos < m_DataEndPos )
423 if ( m_Input->EndOfData() ) {
426 _ASSERT(m_Buffer <= m_CurrentPos);
428 _ASSERT(m_DataEndPos <= m_Buffer + m_BufferSize);
430 (m_CollectPos>=m_Buffer &&
431 m_CollectPos<=m_CurrentPos));
434 m_Error =
"end of file";
438 m_Error =
"read fault";
442 m_DataEndPos +=
count;
445 _ASSERT(m_Buffer <= m_CurrentPos);
448 _ASSERT(m_DataEndPos <= m_Buffer + m_BufferSize);
450 (m_CollectPos>=m_Buffer && m_CollectPos<=m_CurrentPos));
475 const char* pos = m_CurrentPos;
477 size_t c = m_DataEndPos - pos;
481 m_CurrentPos = pos +
count;
488 m_CurrentPos = pos += c;
489 pos = FillBuffer(pos);
499 const char* pos = m_CurrentPos;
500 size_t in_buffer = m_DataEndPos - pos;
501 if ( in_buffer >=
count ) {
504 m_CurrentPos = pos +
count;
508 str.assign(pos, in_buffer);
511 m_CurrentPos = pos += in_buffer;
512 pos = FillBuffer(pos);
513 in_buffer = m_DataEndPos - pos;
514 if ( in_buffer >=
count ) {
517 m_CurrentPos = pos +
count;
520 str.append(pos, in_buffer);
528 _ASSERT(lastChar ==
'\n' || lastChar ==
'\r');
529 _ASSERT(m_CurrentPos > m_Buffer && m_CurrentPos[-1] == lastChar);
531 char nextChar = PeekCharNoEOF();
534 if ( (lastChar + nextChar) == (
'\r' +
'\n') )
545 char c = *buff++ = GetChar();
552 if ( PeekChar() ==
'\n' )
556 if ( PeekChar() ==
'\r' )
572 m_Error =
"bad number";
574 "bad number in line " << GetLine());
581 m_Error =
"number overflow";
583 "number overflow in line " << GetLine());
659 if (
n > kMaxBeforeMul || (
n == kMaxBeforeMul && d > kMaxLimitAdd) )
693 if (
n > kMaxBeforeMul || (
n == kMaxBeforeMul && d > kMaxLimitAdd) )
736 if (
n > kMaxBeforeMul || (
n == kMaxBeforeMul && d > kMaxLimitAdd) )
764 d = (
Uint1)(PeekCharNoEOF() -
'0');
770 if (
n > kMaxBeforeMul )
784 : m_Output(
out), m_DeleteOutput(deleteOut), m_Closed(
false), m_Error(0),
785 m_IndentLevel(0), m_BufferPos(0),
787 m_CurrentPos(m_Buffer),
789 m_Line(1), m_LineLength(0),
790 m_BackLimit(0), m_UseIndentation(
true), m_UseEol(
true),
791 m_CanceledCallback(0)
801 NCBI_CATCH_X(2,
"~COStreamBuffer: exception while closing");
806 NCBI_CATCH_X(2,
"~COStreamBuffer: exception deleting output stream");
873 if (
const ICanceled* callback = m_CanceledCallback ) {
874 if ( callback->IsCanceled() ) {
875 m_Error =
"canceled";
879 size_t used = GetUsedSpace();
890 count = used - leave;
893 if ( !m_Output.write(m_Buffer,
count) ) {
894 m_Error =
"write fault";
899 m_CurrentPos -=
count;
902 m_CurrentPos = m_Buffer;
914 if ( !m_Output.flush() ) {
924 size_t usedSize = m_CurrentPos - m_Buffer;
925 size_t needSize = usedSize +
count;
926 size_t bufferSize = m_BufferEnd - m_Buffer;
927 if ( bufferSize < needSize ) {
931 }
while ( bufferSize < needSize );
932 if ( usedSize == 0 ) {
934 m_CurrentPos = m_Buffer =
new char[bufferSize];
935 m_BufferEnd = m_Buffer + bufferSize;
938 char* oldBuffer = m_Buffer;
939 m_Buffer =
new char[bufferSize];
940 m_BufferEnd = m_Buffer + bufferSize;
941 memcpy(m_Buffer, oldBuffer, usedSize);
943 m_CurrentPos = m_Buffer + usedSize;
953 const size_t BSIZE = (
sizeof(v)*
CHAR_BIT) / 3 + 2;
959 char* pos =
b + BSIZE;
962 *--pos = char(
a-10*(
n/=
Uint4(10)));
967 int len = (
int)(
b + BSIZE - pos);
968 char* dst = Skip(
len);
969 for (
int i = 0;
i <
len; ++
i ) {
978 const size_t BSIZE = (
sizeof(v)*
CHAR_BIT) / 3 + 2;
981 char* pos =
b + BSIZE;
984 *--pos = char(
a-10*(
n/=
Uint4(10)));
986 int len = (
int)(
b + BSIZE - pos);
987 char* dst = Skip(
len);
988 for (
int i = 0;
i <
len; ++
i ) {
998 #define PRINT_INT8_CHUNK 1000000000
999 #define PRINT_INT8_CHUNK_SIZE 9
1004 const size_t BSIZE = (
sizeof(v)*
CHAR_BIT) / 3 + 2;
1010 char* pos =
b + BSIZE;
1011 #ifdef PRINT_INT8_CHUNK
1019 *--pos = char(
a-10*(m/=10));
1020 }
while ( pos != end );
1026 *--pos = char(
a-10*(m/=10));
1031 *--pos = char(
a-10*(
n/=
Uint8(10)));
1037 int len = (
int)(
b + BSIZE - pos);
1038 char* dst = Skip(
len);
1039 for (
int i = 0;
i <
len; ++
i ) {
1048 const size_t BSIZE = (
sizeof(v)*
CHAR_BIT) / 3 + 2;
1051 char* pos =
b + BSIZE;
1052 #ifdef PRINT_INT8_CHUNK
1060 *--pos = char(
a-10*(m/=10));
1061 }
while ( pos != end );
1067 *--pos = char(
a-10*(m/=10));
1072 *--pos = char(
a-10*(
n/=10));
1075 int len = (
int)(
b + BSIZE - pos);
1076 char* dst = Skip(
len);
1077 for (
int i = 0;
i <
len; ++
i ) {
1090 size_t linePos = m_LineLength;
1091 char* pos = m_CurrentPos;
1092 bool goodPlace =
false;
1093 while ( pos > m_Buffer && linePos > 0 ) {
1096 if ( linePos <= lineLength && (
isspace((
unsigned char) (*pos)) ||
1101 else if ( *pos ==
'\n' || *pos ==
'"' ) {
1108 if (pos > m_Buffer && *(pos-1) ==
'\n') {
1114 if ( linePos < lineLength ) {
1115 pos += lineLength - linePos;
1116 linePos = lineLength;
1119 while ( pos > m_Buffer && *(pos - 1) ==
'"' ) {
1123 if ( pos == m_Buffer ) {
1125 while ( pos < m_CurrentPos && *pos ==
'"' ) {
1133 size_t count = m_CurrentPos - pos;
1135 m_LineLength =
count;
1145 while ( dataLength > 0 ) {
1158 memcpy(m_CurrentPos,
data, dataLength);
1159 m_CurrentPos += dataLength;
1174 if ( reader.EndOfData() )
1179 m_CurrentPos +=
count;
Interface for testing cancellation request in a long lasting operation.
NLM_EXTERN Nlm_CharPtr LIBCALL SkipChar(char FAR *theString, char Char)
std::ofstream out("events_result.xml")
main entry point for tests
static const char * str(char *buf, int n)
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
#define NCBI_CATCH_X(err_subcode, message)
Catch CExceptions as well with default error code and given error subcode placed in diagnostics.
#define NCBI_THROW_FMT(exception_class, err_code, message)
The same as NCBI_THROW but with message processed as output to ostream.
void Reset(void)
Reset reference object.
uint8_t Uint1
1-byte (8-bit) unsigned integer
int32_t Int4
4-byte (32-bit) signed integer
uint32_t Uint4
4-byte (32-bit) unsigned integer
int64_t Int8
8-byte (64-bit) signed integer
uint64_t Uint8
8-byte (64-bit) unsigned integer
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
COStreamBuffer(CNcbiOstream &out, bool deleteOut=false)
void ResetBufferLock(size_t pos)
virtual bool IsMultiPart(void) const
virtual CRef< CByteSource > GetSource(void)=0
Get CByteSource implementation.
void GetChars(char *buffer, size_t count)
const CRef< CSubSourceCollector > & GetParentCollector(void) const
char * DoReserve(size_t reserve=0)
bool TryToFillBuffer(void)
bool TrySetCurrentPos(const char *pos)
void PutEolAtWordEnd(size_t lineLength)
void Open(CByteSourceReader &reader)
const char * m_CurrentPos
size_t PeekFindChar(char c, size_t limit)
void SetStreamOffset(CNcbiStreampos pos)
void StartSubSource(void)
void SetStreamPos(CNcbiStreampos pos)
virtual void Seekg(CNcbiStreampos pos)
virtual void AddChunk(const char *buffer, size_t bufferLength)
Add data to the sub-source.
virtual size_t GetNextPart(char **, size_t)
CRef< CSubSourceCollector > m_Collector
void Write(const char *data, size_t dataLength)
void SkipEndOfLine(char lastChar)
void SetCanceledCallback(const ICanceled *callback)
size_t SetBufferLock(size_t size)
CRef< CByteSourceReader > m_Input
CConstIRef< ICanceled > m_CanceledCallback
void FlushBuffer(bool fullBuffer=true)
const char * m_CollectPos
char FillBufferNoEOF(const char *pos)
const char * FillBuffer(const char *pos, bool noEOF=false)
void NumberOverflow(void)
virtual bool Pushback(const char *data, size_t size)
void SetCanceledCallback(const ICanceled *callback)
CRef< CByteSource > EndSubSource(void)
CConstIRef< ICanceled > m_CanceledCallback
const char * m_DataEndPos
size_t ReadLine(char *buff, size_t size)
virtual CRef< CSubSourceCollector > SubSource(size_t prepend, CRef< CSubSourceCollector > parent)
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
IO_PREFIX::streampos CNcbiStreampos
Portable alias for streampos.
unsigned int
A callback function used to compare two keys in a database.
Definition of all error codes used in util (xutil.lib).
where boath are integers</td > n< td ></td > n</tr > n< tr > n< td > tse</td > n< td > optional</td > n< td > String</td > n< td class=\"description\"> TSE option controls what blob is smart and slim</td> n<td> orig</td> n</tr> n<tr> n<td> last_modified</td> n<td> optional</td> n<td> Integer</td> n<td class=\"description\"> The blob last modification If provided then the exact match will be requested with n the Cassandra storage corresponding field value</td> n<td> Positive integer Not provided means that the most recent match will be selected</td> n<td></td> n</tr> n<tr> n<td> use_cache</td> n<td> optional</td> n<td> String</td> n<td class=\"description\"> The option controls if the Cassandra LMDB cache and or database should be used It n affects the seq id resolution step and the blob properties lookup step The following n options are available
static const CS_INT unused
const struct ncbi::grid::netcache::search::fields::SIZE size
const CharType(& source)[N]
NCBI C++ stream class wrappers for triggering between "new" and "old" C++ stream libraries.
@ eCanceled
Request canceled.
#define PRINT_INT8_CHUNK_SIZE
static size_t BiggerBufferSize(size_t size) THROWS1_NONE
static const size_t KInitialBufferSize
IOS_BASE::iostate m_State
~STemporarilyClearStreamState()
STemporarilyClearStreamState(ios &stream)