include/corelib/ncbistre.hpp File Reference


Detailed Description

NCBI C++ stream class wrappers for triggering between "new" and "old" C++ stream libraries.

Definition in file ncbistre.hpp.

#include <corelib/ncbistl.hpp>
#include <corelib/ncbitype.h>
#include <string>

Include dependency graph for ncbistre.hpp:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  CNcbiOstrstreamToString
class  CUpcaseStringConverter
class  CUpcaseCharPtrConverter
class  CLocaseStringConverter
class  CLocaseCharPtrConverter
class  CPrintableStringConverter
class  CPrintableCharPtrConverter

Defines

#define NCBI_USE_OLD_IOSTREAM
 Determine which iostream library to use, include appropriate headers, and define specific preprocessor variables.
#define SEEKOFF   PUBSEEKOFF
#define NcbiCin   IO_PREFIX::cin
#define NcbiCout   IO_PREFIX::cout
#define NcbiCerr   IO_PREFIX::cerr
#define NcbiClog   IO_PREFIX::clog
#define NcbiEndl   IO_PREFIX::endl
#define NcbiEnds   IO_PREFIX::ends
#define NcbiFlush   IO_PREFIX::flush
#define NcbiDec   IO_PREFIX::dec
#define NcbiHex   IO_PREFIX::hex
#define NcbiOct   IO_PREFIX::oct
#define NcbiWs   IO_PREFIX::ws
#define NcbiSetbase   IO_PREFIX::setbase
#define NcbiResetiosflags   IO_PREFIX::resetiosflags
#define NcbiSetiosflags   IO_PREFIX::setiosflags
#define NcbiSetfill   IO_PREFIX::setfill
#define NcbiSetprecision   IO_PREFIX::setprecision
#define NcbiSetw   IO_PREFIX::setw
#define NcbiGoodbit   IOS_PREFIX::goodbit
#define NcbiEofbit   IOS_PREFIX::eofbit
#define NcbiFailbit   IOS_PREFIX::failbit
#define NcbiBadbit   IOS_PREFIX::badbit
#define NcbiHardfail   IOS_PREFIX::hardfail
#define CT_INT_TYPE   NCBI_NS_STD::char_traits<char>::int_type
#define CT_CHAR_TYPE   NCBI_NS_STD::char_traits<char>::char_type
#define CT_POS_TYPE   NCBI_NS_STD::char_traits<char>::pos_type
#define CT_OFF_TYPE   NCBI_NS_STD::char_traits<char>::off_type
#define CT_EOF   NCBI_NS_STD::char_traits<char>::eof()
#define CT_NOT_EOF   NCBI_NS_STD::char_traits<char>::not_eof
#define CT_TO_INT_TYPE   NCBI_NS_STD::char_traits<char>::to_int_type
#define CT_TO_CHAR_TYPE   NCBI_NS_STD::char_traits<char>::to_char_type
#define CT_EQ_INT_TYPE   NCBI_NS_STD::char_traits<char>::eq_int_type

Typedefs

typedef IO_PREFIX::streampos CNcbiStreampos
 Portable alias for streampos.
typedef IO_PREFIX::streamoff CNcbiStreamoff
 Portable alias for streamoff.
typedef IO_PREFIX::ios CNcbiIos
 Portable alias for ios.
typedef IO_PREFIX::streambuf CNcbiStreambuf
 Portable alias for streambuf.
typedef IO_PREFIX::istream CNcbiIstream
 Portable alias for istream.
typedef IO_PREFIX::ostream CNcbiOstream
 Portable alias for ostream.
typedef IO_PREFIX::iostream CNcbiIostream
 Portable alias for iostream.
typedef IO_PREFIX::strstreambuf CNcbiStrstreambuf
 Portable alias for strstreambuf.
typedef IO_PREFIX::istrstream CNcbiIstrstream
 Portable alias for istrstream.
typedef IO_PREFIX::ostrstream CNcbiOstrstream
 Portable alias for ostrstream.
typedef IO_PREFIX::strstream CNcbiStrstream
 Portable alias for strstream.
typedef IO_PREFIX::filebuf CNcbiFilebuf
 Portable alias for filebuf.
typedef IO_PREFIX::ifstream CNcbiIfstream
 Portable alias for ifstream.
typedef IO_PREFIX::ofstream CNcbiOfstream
 Portable alias for ofstream.
typedef IO_PREFIX::fstream CNcbiFstream
 Portable alias for fstream.

Enumerations

enum  EEncodingForm {
  eEncodingForm_Unknown, eEncodingForm_ISO8859_1, eEncodingForm_Windows_1252, eEncodingForm_Utf8,
  eEncodingForm_Utf16Native, eEncodingForm_Utf16Foreign
}
 Helper functions to read plain-text data streams. More...
enum  EReadUnknownNoBOM { eNoBOM_RawRead, eNoBOM_GuessEncoding }
 How to read the text if the encoding form is not known (i.e. More...
enum  EBOMDiscard { eBOM_Discard, eBOM_Keep }
 Whether to discard BOM or to keep it in the input stream. More...

Functions

const char * Endl (void)
 Platform-specific EndOfLine.
CNcbiIstreamNcbiGetline (CNcbiIstream &is, string &str, char delim)
 Read from "is" to "str" up to the delimiter symbol "delim" (or EOF).
CNcbiIstreamNcbiGetline (CNcbiIstream &is, string &str, const string &delims)
 Read from "is" to "str" up to any symbol contained within "delims" (or EOF).
CNcbiIstreamNcbiGetlineEOL (CNcbiIstream &is, string &str)
 Read from "is" to "str" the next line (taking into account platform specifics of End-of-Line).
bool NcbiStreamCopy (CNcbiOstream &os, CNcbiIstream &is)
 Copy entire contents of stream "is" into "os".
Int8 NcbiStreamposToInt8 (NCBI_NS_STD::char_traits< char >::pos_type stream_pos)
 Convert stream position to 64-bit int.
NCBI_NS_STD::char_traits<
char >::pos_type 
NcbiInt8ToStreampos (Int8 pos)
 Convert plain numeric stream postion into stream position in terms of streams library.
char Upcase (char c)
CUpcaseStringConverter Upcase (const string &s)
CUpcaseCharPtrConverter Upcase (const char *s)
char Locase (char c)
CLocaseStringConverter Locase (const string &s)
CLocaseCharPtrConverter Locase (const char *s)
string Printable (char c)
CPrintableStringConverter Printable (const string &s)
CPrintableCharPtrConverter Printable (const char *s)
CNcbiOstreamoperator<< (CNcbiOstream &out, CUpcaseStringConverter s)
CNcbiOstreamoperator<< (CNcbiOstream &out, CUpcaseCharPtrConverter s)
CNcbiOstreamoperator<< (CNcbiOstream &out, CLocaseStringConverter s)
CNcbiOstreamoperator<< (CNcbiOstream &out, CLocaseCharPtrConverter s)
CNcbiOstreamoperator<< (CNcbiOstream &out, CPrintableStringConverter s)
CNcbiOstreamoperator<< (CNcbiOstream &out, CPrintableCharPtrConverter s)
EEncodingForm ReadIntoUtf8 (CNcbiIstream &input, CStringUTF8 *result, EEncodingForm encoding_form=eEncodingForm_Unknown, EReadUnknownNoBOM what_if_no_bom=eNoBOM_GuessEncoding)
 Read all input data from stream and try convert it into UTF8 string.
EEncodingForm GetTextEncodingForm (CNcbiIstream &input, EBOMDiscard discard_bom)
 Detect if the stream has BOM.
void BASE64_Encode (const void *src_buf, size_t src_size, size_t *src_read, void *dst_buf, size_t dst_size, size_t *dst_written, size_t *line_len)
 BASE64-encode up to "src_size" symbols(bytes) from buffer "src_buf".
int BASE64_Decode (const void *src_buf, size_t src_size, size_t *src_read, void *dst_buf, size_t dst_size, size_t *dst_written)
 BASE64-decode up to "src_size" symbols(bytes) from buffer "src_buf".
END_NCBI_SCOPE NCBI_NS_NCBI::CNcbiOstreamoperator<< (NCBI_NS_NCBI::CNcbiOstream &os, const NCBI_NS_STD::string &str)
NCBI_NS_NCBI::CNcbiIstreamoperator>> (NCBI_NS_NCBI::CNcbiIstream &is, NCBI_NS_STD::string &str)


Define Documentation

#define NCBI_USE_OLD_IOSTREAM
 

Determine which iostream library to use, include appropriate headers, and define specific preprocessor variables.

The default is the new(template-based, std::) one.

Definition at line 48 of file ncbistre.hpp.

#define SEEKOFF   PUBSEEKOFF
 

Definition at line 116 of file ncbistre.hpp.


Enumeration Type Documentation

enum EBOMDiscard
 

Whether to discard BOM or to keep it in the input stream.

See also:
GetTextEncodingForm
Enumerator:
eBOM_Discard  Discard the read BOM bytes.
eBOM_Keep  Push the read BOM bytes back into the input stream.

Definition at line 666 of file ncbistre.hpp.

enum EEncodingForm
 

Helper functions to read plain-text data streams.

It understands Byte Order Mark (BOM) and converts the input if needed.

See clause 13.6 in http://www.unicode.org/unicode/uni2book/ch13.pdf and also http://unicode.org/faq/utf_bom.html#BOM

See also:
ReadIntoUtf8, GetTextEncodingForm
Enumerator:
eEncodingForm_Unknown  Stream has no BOM.
eEncodingForm_ISO8859_1  Stream has no BOM.
eEncodingForm_Windows_1252  Stream has no BOM.
eEncodingForm_Utf8  Stream has UTF8 BOM.
eEncodingForm_Utf16Native  Stream has UTF16 BOM. Byte order is native for this OS.
eEncodingForm_Utf16Foreign  Stream has UTF16 BOM. Byte order is nonnative for this OS.

Definition at line 603 of file ncbistre.hpp.

enum EReadUnknownNoBOM
 

How to read the text if the encoding form is not known (i.e.

passed "eEncodingForm_Unknown" and the stream does not have BOM too)

See also:
ReadIntoUtf8
Enumerator:
eNoBOM_RawRead  Read the text "as is" (raw octal data).

The read data can then be accessed using the regular std::string API (rather than the CStringUTF8 one).

eNoBOM_GuessEncoding  Try to guess the text's encoding form.

Note:
In this case the encoding is a guesswork, which is not necessarily correct. If the guess is wrong then the data may be distorted on read. Use CStringUTF8::IsValid() to verify that guess. If it does not verify, then the read data can be accessed using the regular std::string API (rather than the CStringUTF8 one).

Definition at line 623 of file ncbistre.hpp.


Function Documentation

int BASE64_Decode const void *  src_buf,
size_t  src_size,
size_t *  src_read,
void *  dst_buf,
size_t  dst_size,
size_t *  dst_written
 

BASE64-decode up to "src_size" symbols(bytes) from buffer "src_buf".

Write the decoded data to buffer "dst_buf", but no more than "dst_size" bytes. Assign "*src_read" to the # of bytes successfully decoded from "src_buf". Assign "*dst_written" to the # of bytes written to buffer "dst_buf". Return FALSE (0) only if cannot decode anything. Destination buffer size, as a worst case, equal to the source size will accomodate the entire input. As a rule, each 4 bytes of source (line breaks skipped) are converted into 3 bytes on output.

Definition at line 640 of file ncbistre.cpp.

Referenced by CObjectIStreamXml::ReadBytes(), CNetScheduleKeys< TBVector >::x_Add(), and CNetScheduleHandler::x_DeserializeBitVector().

void BASE64_Encode const void *  src_buf,
size_t  src_size,
size_t *  src_read,
void *  dst_buf,
size_t  dst_size,
size_t *  dst_written,
size_t *  line_len
 

BASE64-encode up to "src_size" symbols(bytes) from buffer "src_buf".

Write the encoded data to buffer "dst_buf", but no more than "dst_size" bytes. Assign "*src_read" to the # of bytes successfully encoded from "src_buf". Assign "*dst_written" to the # of bytes written to buffer "dst_buf". Resulting lines will not exceed "*line_len" (or the standard default if "line_len" is NULL) bytes; *line_len == 0 disables line breaks. To estimate required destination buffer size, you can take into account that BASE64 coding converts every 3 bytes of source into 4 bytes on destination, not including the line breaks ('
').

Definition at line 568 of file ncbistre.cpp.

References _ASSERT, bits, and len.

Referenced by CObjectOStreamXml::WriteBase64Bytes(), and CNetScheduleHandler::x_SerializeBitVector().

EEncodingForm GetTextEncodingForm CNcbiIstream input,
EBOMDiscard  discard_bom
 

Detect if the stream has BOM.

Parameters:
input Input stream
discard_bom Whether to discard the read BOM bytes or to push them back to the stream
NOTE: If the function needs to push back more than one char then it uses CStreamUtils::Pushback().
See also:
CStreamUtils::Pushback()

Definition at line 516 of file ncbistre.cpp.

References eEncodingForm_Unknown, eEncodingForm_Utf16Foreign, eEncodingForm_Utf16Native, and eEncodingForm_Utf8.

CLocaseCharPtrConverter Locase const char *  s  )  [inline]
 

Definition at line 545 of file ncbistre.hpp.

CLocaseStringConverter Locase const string &  s  )  [inline]
 

Definition at line 539 of file ncbistre.hpp.

char Locase char  c  )  [inline]
 

Definition at line 533 of file ncbistre.hpp.

END_NCBI_SCOPE NCBI_NS_NCBI::CNcbiOstream& operator<< NCBI_NS_NCBI::CNcbiOstream os,
const NCBI_NS_STD::string &  str
 

CNcbiOstream& operator<< CNcbiOstream out,
CPrintableCharPtrConverter  s
 

Definition at line 347 of file ncbistre.cpp.

CNcbiOstream& operator<< CNcbiOstream out,
CPrintableStringConverter  s
 

Definition at line 338 of file ncbistre.cpp.

CNcbiOstream& operator<< CNcbiOstream out,
CLocaseCharPtrConverter  s
 

Definition at line 269 of file ncbistre.cpp.

CNcbiOstream& operator<< CNcbiOstream out,
CLocaseStringConverter  s
 

Definition at line 251 of file ncbistre.cpp.

CNcbiOstream& operator<< CNcbiOstream out,
CUpcaseCharPtrConverter  s
 

Definition at line 260 of file ncbistre.cpp.

CNcbiOstream& operator<< CNcbiOstream out,
CUpcaseStringConverter  s
 

Definition at line 242 of file ncbistre.cpp.

NCBI_NS_NCBI::CNcbiIstream& operator>> NCBI_NS_NCBI::CNcbiIstream is,
NCBI_NS_STD::string &  str
 

CPrintableCharPtrConverter Printable const char *  s  )  [inline]
 

Definition at line 560 of file ncbistre.hpp.

CPrintableStringConverter Printable const string &  s  )  [inline]
 

Definition at line 554 of file ncbistre.hpp.

string Printable char  c  ) 
 

Definition at line 290 of file ncbistre.cpp.

EEncodingForm ReadIntoUtf8 CNcbiIstream input,
CStringUTF8 result,
EEncodingForm  encoding_form = eEncodingForm_Unknown,
EReadUnknownNoBOM  what_if_no_bom = eNoBOM_GuessEncoding
 

Read all input data from stream and try convert it into UTF8 string.

Parameters:
input Input text stream
result UTF8 string (but it can be a raw octet string if the encoding is unknown)
what_if_no_bom What to do if the 'encoding_form' is passed "eEncodingForm_Unknown" and the BOM is not detected in the stream
Returns:
The encoding as detected based on the BOM ("eEncodingForm_Unknown" if there was no BOM).

Definition at line 392 of file ncbistre.cpp.

References eEncodingForm_Unknown.

Referenced by CCgiEntry::GetValueAsUTF8().

CUpcaseCharPtrConverter Upcase const char *  s  )  [inline]
 

Definition at line 527 of file ncbistre.hpp.

CUpcaseStringConverter Upcase const string &  s  )  [inline]
 

Definition at line 521 of file ncbistre.hpp.

char Upcase char  c  )  [inline]
 

Definition at line 515 of file ncbistre.hpp.


Generated on Sun Oct 12 06:58:19 2008 for NCBI C++ ToolKit by  doxygen 1.4.6
Modified on Sun Oct 12 18:15:51 2008 by modify_doxy.py rev. 117643