1 #ifndef CORELIB___NCBISTRE__HPP
2 #define CORELIB___NCBISTRE__HPP
45 #if !defined(HAVE_IOSTREAM) && !defined(NCBI_USE_OLD_IOSTREAM)
46 # define NCBI_USE_OLD_IOSTREAM
49 #if defined(HAVE_IOSTREAM_H) && defined(NCBI_USE_OLD_IOSTREAM)
50 # include <iostream.h>
52 # if defined(HAVE_STRSTREA_H)
53 # include <strstrea.h>
55 # include <strstream.h>
59 # define IOS_BASE ::ios
60 # define IOS_PREFIX ::ios
62 # define PUBSEEKPOS seekpos
63 # define PUBSEEKOFF seekoff
65 #elif defined(HAVE_IOSTREAM)
66 # if defined(NCBI_USE_OLD_IOSTREAM)
67 # undef NCBI_USE_OLD_IOSTREAM
69 # if defined(NCBI_COMPILER_GCC) || \
70 (defined(NCBI_COMPILER_ANY_CLANG) && defined(__GLIBCXX__))
72 # define _CPP_BACKWARD_BACKWARD_WARNING_H 1
73 # define _BACKWARD_BACKWARD_WARNING_H 1
77 # if defined(NCBI_COMPILER_ICC) && defined(__GNUC__) && !defined(__INTEL_CXXLIB_ICC)
78 # define _BACKWARD_BACKWARD_WARNING_H 1
79 # include <backward/strstream>
84 #define NCBI_SHUN_OSTRSTREAM 1
89 # define IO_PREFIX NCBI_NS_STD
90 # define IOS_BASE IO_PREFIX::ios_base
91 # define IOS_PREFIX IO_PREFIX::ios
95 # define PUBSETBUF setbuf
96 # define PUBSEEKOFF seekoff
97 # define PUBSEEKPOS seekpos
99 # define PUBSYNC pubsync
100 # define PUBSETBUF pubsetbuf
101 # define PUBSEEKOFF pubseekoff
102 # define PUBSEEKPOS pubseekpos
105 # ifdef _LIBCPP_VERSION
106 # define NCBI_SHUN_OSTRSTREAM 1
111 # error "Neither <iostream> nor <iostream.h> can be found!"
115 #define SEEKOFF PUBSEEKOFF
120 #define HTTP_EOL "\r\n"
155 #ifndef NCBI_SHUN_OSTRSTREAM
168 # define NCBI_STRSTREAM_INIT(p, l) (p), (l)
183 [[deprecated(
"(char*) constructor is deprecated, WILL BE REMOVED SOON")]]
187 #if !defined(NCBI_COMPILER_MSVC) || (NCBI_COMPILER_VERSION > 1916)
192 [[deprecated(
"(char*, Tinteger) constructor is deprecated, WILL BE REMOVED SOON")]]
202 [[deprecated(
"(char*, streamsize) constructor is deprecated, WILL BE REMOVED SOON")]]
206 [[deprecated(
"(char*, size_t) constructor is deprecated, WILL BE REMOVED SOON")]]
210 [[deprecated(
"(char*, int) constructor is deprecated, WILL BE REMOVED SOON")]]
233 _Mybase::operator=(std::move(_Right));
239 template<
typename _Base, IOS_BASE::openmode _DefMode>
252 #if !defined(NCBI_COMPILER_MSVC) || (NCBI_COMPILER_VERSION > 1916)
257 [[deprecated(
"(char*, Tinteger, ios::openmode) constructor is deprecated, WILL BE REMOVED SOON")]]
259 :
_Mybase(_Ptr, _Count, _Mode) {
262 [[deprecated(
"(char*, streamsize, ios::openmode) constructor is deprecated, WILL BE REMOVED SOON")]]
264 :
_Mybase(_Ptr, _Count, _Mode) {
266 [[deprecated(
"(char*, size_t, ios::openmode) constructor is deprecated, WILL BE REMOVED SOON")]]
268 :
_Mybase(_Ptr, _Count, _Mode) {
270 [[deprecated(
"(char*, int, ios::openmode) constructor is deprecated, WILL BE REMOVED SOON")]]
272 :
_Mybase(_Ptr, _Count, _Mode) {
281 _Mybase::operator=(std::move(_Right));
288 #if defined(NCBI_COMPILER_MSVC)
300 # define NCBI_STRSTREAM_INIT(p, l) string(p, l)
302 # define NCBI_STRSTREAM_INIT(p, l) (p), (l)
303 template<
typename _Base, IOS_BASE::openmode _DefMode>
307 typedef _Base _Mybase;
312 : _Mybase(_Str, _Mode) {
315 #if !defined(NCBI_COMPILER_MSVC) || (NCBI_COMPILER_VERSION > 1916)
321 [[deprecated(
"(const char*, Tinteger, ios::openmode) constructor is deprecated, use string argument instead")]]
322 CNcbistrstream_Base(
const char *_Ptr, TInteger _Count, IOS_BASE::openmode _Mode = _DefMode)
323 : _Mybase(
string(_Ptr, _Count), _Mode) {
327 CNcbistrstream_Base(
const char *_Ptr, TInteger _Count, IOS_BASE::openmode _Mode = _DefMode) =
delete;
330 [[deprecated(
"(const char*, streamsize, ios::openmode) constructor is deprecated, use string argument instead")]]
332 : _Mybase(
string(s,
n), _Mode) {
334 [[deprecated(
"(const char*, size_t, ios::openmode) constructor is deprecated, use string argument instead")]]
336 : _Mybase(
string(s,
n), _Mode) {
338 [[deprecated(
"(const char*, int, ios::openmode) constructor is deprecated, use string argument instead")]]
340 : _Mybase(
string(s,
n), _Mode) {
344 template<
typename TInteger>
346 template<
typename TInteger>
351 : _Mybase(std::move(_Right)) {
354 _Mybase::operator=(std::move(_Right));
362 #if defined(NCBI_COMPILER_MSVC) && (!defined(NCBI_DLL_BUILD) || defined(NCBI_CORE_EXPORTS))
376 #if defined(NCBI_OS_MSWIN) && defined(_UNICODE)
380 wstring ncbi_Utf8ToWstring(
const char *utf8);
388 const char *_Filename,
390 int _Prot = (
int)IOS_BASE::_Openprot
391 ) : IO_PREFIX::ifstream(
392 ncbi_Utf8ToWstring(_Filename).c_str(), _Mode, _Prot) {
395 const string& _Filename,
397 int _Prot = (
int)IOS_BASE::_Openprot
401 const wchar_t *_Filename,
403 int _Prot = (
int)IOS_BASE::_Openprot
404 ) : IO_PREFIX::ifstream(_Filename,_Mode,_Prot) {
407 const wstring& _Filename,
409 int _Prot = (
int)IOS_BASE::_Openprot
414 const char *_Filename,
416 int _Prot = (
int)IOS_BASE::_Openprot) {
417 IO_PREFIX::ifstream::open(
418 ncbi_Utf8ToWstring(_Filename).c_str(), _Mode, _Prot);
421 const string& _Filename,
423 int _Prot = (
int)IOS_BASE::_Openprot) {
424 CNcbiIfstream::open(_Filename.c_str(), _Mode, _Prot);
426 void open(
const wchar_t *_Filename,
428 int _Prot = (
int)ios_base::_Openprot) {
429 IO_PREFIX::ifstream::open(_Filename,_Mode,_Prot);
431 void open(
const wstring& _Filename,
433 int _Prot = (
int)ios_base::_Openprot) {
434 CNcbiIfstream::open(_Filename.c_str(), _Mode, _Prot);
442 #if defined(NCBI_OS_MSWIN) && defined(_UNICODE)
449 const char *_Filename,
451 int _Prot = (
int)IOS_BASE::_Openprot
452 ) : IO_PREFIX::ofstream(
453 ncbi_Utf8ToWstring(_Filename).c_str(), _Mode, _Prot) {
456 const string& _Filename,
458 int _Prot = (
int)IOS_BASE::_Openprot
462 const wchar_t *_Filename,
464 int _Prot = (
int)IOS_BASE::_Openprot
465 ) : IO_PREFIX::ofstream(_Filename,_Mode,_Prot) {
468 const wstring& _Filename,
470 int _Prot = (
int)IOS_BASE::_Openprot
475 const char *_Filename,
477 int _Prot = (
int)IOS_BASE::_Openprot) {
478 IO_PREFIX::ofstream::open(
479 ncbi_Utf8ToWstring(_Filename).c_str(), _Mode, _Prot);
482 const string& _Filename,
484 int _Prot = (
int)IOS_BASE::_Openprot) {
485 CNcbiOfstream::open(_Filename.c_str(), _Mode, _Prot);
487 void open(
const wchar_t *_Filename,
489 int _Prot = (
int)IOS_BASE::_Openprot) {
490 IO_PREFIX::ofstream::open(_Filename,_Mode,_Prot);
492 void open(
const wstring& _Filename,
494 int _Prot = (
int)IOS_BASE::_Openprot) {
495 CNcbiOfstream::open(_Filename.c_str(), _Mode, _Prot);
503 #if defined(NCBI_OS_MSWIN) && defined(_UNICODE)
510 const char *_Filename,
512 int _Prot = (
int)IOS_BASE::_Openprot
513 ) : IO_PREFIX::fstream(
514 ncbi_Utf8ToWstring(_Filename).c_str(), _Mode, _Prot) {
517 const wchar_t *_Filename,
519 int _Prot = (
int)IOS_BASE::_Openprot
520 ) : IO_PREFIX::fstream(_Filename,_Mode,_Prot) {
524 const char *_Filename,
526 int _Prot = (
int)IOS_BASE::_Openprot) {
527 IO_PREFIX::fstream::open(
528 ncbi_Utf8ToWstring(_Filename).c_str(), _Mode, _Prot);
530 void open(
const wchar_t *_Filename,
532 int _Prot = (
int)ios_base::_Openprot) {
533 IO_PREFIX::fstream::open(_Filename,_Mode,_Prot);
542 #define NcbiCin IO_PREFIX::cin
543 #define NcbiCout IO_PREFIX::cout
544 #define NcbiCerr IO_PREFIX::cerr
545 #define NcbiClog IO_PREFIX::clog
548 #define NcbiEndl IO_PREFIX::endl
549 #define NcbiEnds IO_PREFIX::ends
550 #define NcbiFlush IO_PREFIX::flush
552 #define NcbiDec IO_PREFIX::dec
553 #define NcbiHex IO_PREFIX::hex
554 #define NcbiOct IO_PREFIX::oct
555 #define NcbiWs IO_PREFIX::ws
557 #define NcbiFixed IO_PREFIX::fixed
558 #define NcbiScientific IO_PREFIX::scientific
560 #define NcbiSetbase IO_PREFIX::setbase
561 #define NcbiResetiosflags IO_PREFIX::resetiosflags
562 #define NcbiSetiosflags IO_PREFIX::setiosflags
563 #define NcbiSetfill IO_PREFIX::setfill
564 #define NcbiSetprecision IO_PREFIX::setprecision
565 #define NcbiSetw IO_PREFIX::setw
568 #define NcbiGoodbit IOS_PREFIX::goodbit
569 #define NcbiEofbit IOS_PREFIX::eofbit
570 #define NcbiFailbit IOS_PREFIX::failbit
571 #define NcbiBadbit IOS_PREFIX::badbit
572 #define NcbiHardfail IOS_PREFIX::hardfail
577 extern const char*
Endl(
void);
591 const string& delims,
654 string::size_type
count);
728 # define CT_INT_TYPE NCBI_NS_STD::char_traits<char>::int_type
729 # define CT_CHAR_TYPE NCBI_NS_STD::char_traits<char>::char_type
730 # define CT_POS_TYPE NCBI_NS_STD::char_traits<char>::pos_type
731 # define CT_OFF_TYPE NCBI_NS_STD::char_traits<char>::off_type
732 # define CT_EOF NCBI_NS_STD::char_traits<char>::eof()
733 # define CT_NOT_EOF NCBI_NS_STD::char_traits<char>::not_eof
734 # define CT_TO_INT_TYPE NCBI_NS_STD::char_traits<char>::to_int_type
735 # define CT_TO_CHAR_TYPE NCBI_NS_STD::char_traits<char>::to_char_type
736 # define CT_EQ_INT_TYPE NCBI_NS_STD::char_traits<char>::eq_int_type
739 #ifdef NCBI_COMPILER_MIPSPRO
745 void MIPSPRO_ReadsomeBegin(
void)
747 if (!m_MIPSPRO_ReadsomeGptrSetLevel++)
748 m_MIPSPRO_ReadsomeGptr = gptr();
750 void MIPSPRO_ReadsomeEnd (
void)
752 --m_MIPSPRO_ReadsomeGptrSetLevel;
755 CMIPSPRO_ReadsomeTolerantStreambuf() : m_MIPSPRO_ReadsomeGptrSetLevel(0) {}
758 unsigned int m_MIPSPRO_ReadsomeGptrSetLevel;
810 operator string(
void)
const;
823 #ifdef NCBI_SHUN_OSTRSTREAM
919 return static_cast<char>(
toupper((
unsigned char) c));
937 return static_cast<char>(
tolower((
unsigned char) c));
1087 : m_EncodingForm(encodingForm) {
1091 return m_EncodingForm;
1094 m_EncodingForm = encodingForm;
1118 #include <corelib/ncbi_base64.h>
1127 #if defined(NCBI_USE_OLD_IOSTREAM)
Byte Order Mark helper class to use in serialization.
Utility class for automatic conversion of strings to all lowercase letters.
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Utility class for automatic conversion of strings (that may contain non-graphical characters) to a sa...
Utility class for automatic conversion of strings to all uppercase letters.
std::ofstream out("events_result.xml")
main entry point for tests
static const char * str(char *buf, int n)
int64_t Int8
8-byte (64-bit) signed integer
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
void NcbiStreamCopyThrow(CNcbiOstream &os, CNcbiIstream &is)
Same as NcbiStreamCopy() but throws an CCoreException when copy fails.
CNcbiIstrstream(const char *_Ptr)
CNcbiIstream & NcbiGetlineEOL(CNcbiIstream &is, string &str, string::size_type *count=NULL)
Read from "is" to "str" the next line (taking into account platform specifics of End-of-Line)
Int8 NcbiStreamposToInt8(NCBI_NS_STD::char_traits< char >::pos_type stream_pos)
Convert stream position to 64-bit int.
void NcbiStreamCopyHead(CNcbiOstream &os, CNcbiIstream &is, string::size_type count)
Similar to NcbiStreamCopyThrow() but copies (and consumes) only the specified number of bytes (and by...
IO_PREFIX::ofstream CNcbiOfstream
Portable alias for ofstream.
bool IsOssEmpty(CNcbiOstrstream &oss)
EEncodingForm
Helper functions to read plain-text data streams.
CNcbiOstream & operator<<(CNcbiOstream &out, const CNcbiOstrstreamToString &s)
string Printable(char c)
Convert one single character to a "printable" form.
EEncodingForm GetTextEncodingForm(CNcbiIstream &input, EBOMDiscard discard_bom)
Detect if the stream has BOM.
CNcbiIstream & NcbiGetline(CNcbiIstream &is, string &str, char delim, string::size_type *count=NULL)
Read from "is" to "str" up to the delimiter symbol "delim" (or EOF)
CPrintableCharPtrConverter(const char *s)
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
CNcbiIstrstream(char *_Ptr)
IO_PREFIX::istrstream _Mybase
IO_PREFIX::iostream CNcbiIostream
Portable alias for iostream.
CByteOrderMark(EEncodingForm encodingForm)
EBOMDiscard
Whether to discard BOM or to keep it in the input stream.
bool NcbiStreamCompare(CNcbiIstream &is1, CNcbiIstream &is2)
Compare stream contents in binary form.
Int8 GetOssSize(CNcbiOstrstream &oss)
CNcbiIstream & operator>>(CNcbiIstream &str, CByteOrderMark &bom)
Read Byte Order Mark, if present, from input stream.
const char * Endl(void)
Platform-specific EndOfLine.
typename std::enable_if< std::is_integral< T >::value > enable_if_integral
CNcbiOstrstreamToString(CNcbiOstrstream &out)
CNcbistrstream_Base< IO_PREFIX::strstream, IOS_BASE::in|IOS_BASE::out > CNcbiStrstream
CNcbistrstream_Base< IO_PREFIX::ostrstream, IOS_BASE::out > CNcbiOstrstream
ECompareTextMode
Mode to compare streams in text form.
CNcbistrstream_Base(char *_Ptr, TInteger _Count, IOS_BASE::openmode _Mode=_DefMode)
CNcbistrstream_Base(void)
CUpcaseStringConverter(const string &s)
CLocaseStringConverter(const string &s)
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
CNcbiIstrstream(const string &_Str)
CNcbiIstrstream(const char *_Ptr, TInteger _Count)
IO_PREFIX::ios CNcbiIos
Portable alias for ios.
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 m_EncodingForm
IO_PREFIX::streamoff CNcbiStreamoff
Portable alias for streamoff.
CNcbiOstrstreamToString(const CNcbiOstrstreamToString &)
void SetEncodingForm(EEncodingForm encodingForm)
CLocaseCharPtrConverter(const char *s)
CUpcaseCharPtrConverter(const char *s)
CNcbiIstrstream(char *_Ptr, TInteger _Count)
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
NCBI_NS_STD::char_traits< char >::pos_type NcbiInt8ToStreampos(Int8 pos)
Convert plain numeric stream position (offset) into stream position usable with STL stream library.
typename std::enable_if< std::is_integral< T >::value > enable_if_integral
bool NcbiStreamCopy(CNcbiOstream &os, CNcbiIstream &is)
Copy the entire contents of stream "is" to stream "os".
IO_PREFIX::streambuf CNcbiStreambuf
Portable alias for streambuf.
IO_PREFIX::streampos CNcbiStreampos
Portable alias for streampos.
EReadUnknownNoBOM
How to read the text if the encoding form is not known (i.e.
IO_PREFIX::filebuf CNcbiFilebuf
Portable alias for filebuf.
IO_PREFIX::fstream CNcbiFstream
Portable alias for fstream.
bool NcbiStreamCompareText(CNcbiIstream &is1, CNcbiIstream &is2, ECompareTextMode mode, size_t buf_size=0)
Compare stream contents in text form.
size_t NcbiStreamToString(string *s, CNcbiIstream &is, size_t pos=0)
Input the entire contents of an istream into a string (NULL causes drain).
CPrintableStringConverter(const string &s)
EEncodingForm GetEncodingForm(void) const
@ eEncodingForm_Utf16Foreign
Stream has UTF16 BOM. Byte order is nonnative for this OS.
@ eEncodingForm_Utf8
Stream has UTF8 BOM.
@ eEncodingForm_ISO8859_1
Stream has no BOM.
@ eEncodingForm_Windows_1252
Stream has no BOM.
@ eEncodingForm_Unknown
Stream has no BOM.
@ eEncodingForm_Utf16Native
Stream has UTF16 BOM. Byte order is native for this OS.
@ eBOM_Keep
Push the read BOM bytes back into the input stream.
@ eBOM_Discard
Discard the read BOM bytes.
@ eCompareText_IgnoreEol
Skip end-of-line characters ('\r' and ' ')
@ eCompareText_IgnoreWhiteSpace
@ eNoBOM_GuessEncoding
Try to guess the text's encoding form.
@ eNoBOM_RawRead
Read the text "as is" (raw octal data).
#define NCBI_XNCBI_EXPORT
unsigned int
A callback function used to compare two keys in a database.
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
Catch attempts to call ctype functions with bad types.
std::istream & in(std::istream &in_, double &x_)