📄 ncbistre.hpp
字号:
// "char_traits" may not be defined(e.g. EGCS egcs-2.91.66)#if defined(HAVE_NO_CHAR_TRAITS)# define CT_INT_TYPE int# define CT_CHAR_TYPE char# define CT_POS_TYPE CNcbiStreampos# define CT_OFF_TYPE CNcbiStreamoff# define CT_EOF EOFinline CT_INT_TYPE ct_not_eof(CT_INT_TYPE i) { return i == CT_EOF ? 0 : i;}# define CT_NOT_EOF ct_not_eofinline CT_INT_TYPE ct_to_int_type(CT_CHAR_TYPE c) { return (unsigned char)c;}# define CT_TO_INT_TYPE ct_to_int_typeinline CT_CHAR_TYPE ct_to_char_type(CT_INT_TYPE i) { return (unsigned char)i;}# define CT_TO_CHAR_TYPE ct_to_char_typeinline bool ct_eq_int_type(CT_INT_TYPE i1, CT_INT_TYPE i2) { return i1 == i2;}# define CT_EQ_INT_TYPE ct_eq_int_type#else /* HAVE_NO_CHAR_TRAITS */# 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#endif /* HAVE_NO_CHAR_TRAITS */// CNcbiOstrstreamToString class helps to convert CNcbiOstream buffer to string// Sample usage:/*string GetString(void){ CNcbiOstrstream buffer; buffer << "some text"; return CNcbiOstrstreamToString(buffer);}*/// Note: there is no requirements to put '\0' char at the end of bufferclass NCBI_XNCBI_EXPORT CNcbiOstrstreamToString{ CNcbiOstrstreamToString(const CNcbiOstrstreamToString&); CNcbiOstrstreamToString& operator= (const CNcbiOstrstreamToString&);public: CNcbiOstrstreamToString(CNcbiOstrstream& out) : m_Out(out) { } operator string(void) const;private: CNcbiOstrstream& m_Out;};// utility class for automatic conversion of strings to uppercase letters// sample usage:// out << "Original: \"" << str << "\"\n";// out << "Uppercase: \"" << Upcase(str) << "\"\n";// utility class for automatic conversion of strings to lowercase letters// sample usage:// out << "Original: \"" << str << "\"\n";// out << "Lowercase: \"" << Locase(str) << "\"\n";class NCBI_XNCBI_EXPORT CUpcaseStringConverter{public: CUpcaseStringConverter(const string& s) : m_String(s) { } const string& m_String;};class NCBI_XNCBI_EXPORT CUpcaseCharPtrConverter{public: CUpcaseCharPtrConverter(const char* s) : m_String(s) { } const char* m_String;};class NCBI_XNCBI_EXPORT CLocaseStringConverter{public: CLocaseStringConverter(const string& s) : m_String(s) { } const string& m_String;};class NCBI_XNCBI_EXPORT CLocaseCharPtrConverter{public: CLocaseCharPtrConverter(const char* s) : m_String(s) { } const char* m_String;};class NCBI_XNCBI_EXPORT CPrintableStringConverter{public: CPrintableStringConverter(const string& s) : m_String(s) { } const string& m_String;};class NCBI_XNCBI_EXPORT CPrintableCharPtrConverter{public: CPrintableCharPtrConverter(const char* s) : m_String(s) { } const char* m_String;};/* @} */inlinechar Upcase(char c){ return static_cast<char>(toupper(c));}inlineCUpcaseStringConverter Upcase(const string& s){ return CUpcaseStringConverter(s);}inlineCUpcaseCharPtrConverter Upcase(const char* s){ return CUpcaseCharPtrConverter(s);}inlinechar Locase(char c){ return static_cast<char>(tolower(c));}inlineCLocaseStringConverter Locase(const string& s){ return CLocaseStringConverter(s);}inlineCLocaseCharPtrConverter Locase(const char* s){ return CLocaseCharPtrConverter(s);}extern string Printable(char c);inlineCPrintableStringConverter Printable(const string& s){ return CPrintableStringConverter(s);}inlineCPrintableCharPtrConverter Printable(const char* s){ return CPrintableCharPtrConverter(s);}NCBI_XNCBI_EXPORTCNcbiOstream& operator<<(CNcbiOstream& out, CUpcaseStringConverter s);NCBI_XNCBI_EXPORTCNcbiOstream& operator<<(CNcbiOstream& out, CUpcaseCharPtrConverter s);NCBI_XNCBI_EXPORTCNcbiOstream& operator<<(CNcbiOstream& out, CLocaseStringConverter s);NCBI_XNCBI_EXPORTCNcbiOstream& operator<<(CNcbiOstream& out, CLocaseCharPtrConverter s);NCBI_XNCBI_EXPORTCNcbiOstream& operator<<(CNcbiOstream& out, CPrintableStringConverter s);NCBI_XNCBI_EXPORTCNcbiOstream& operator<<(CNcbiOstream& out, CPrintableCharPtrConverter s);#ifdef NCBI_OS_MSWINNCBI_XNCBI_EXPORTCNcbiOstream& operator<<(CNcbiOstream& out, __int64 val);#endifEND_NCBI_SCOPE// Provide formatted I/O of standard C++ "string" by "old-fashioned" IOSTREAMs// NOTE: these must have been inside the _NCBI_SCOPE and without the// "ncbi::" and "std::" prefixes, but there is some bug in SunPro 5.0...#if defined(NCBI_USE_OLD_IOSTREAM)extern NCBI_NS_NCBI::CNcbiOstream& operator<<(NCBI_NS_NCBI::CNcbiOstream& os, const NCBI_NS_STD::string& str);extern NCBI_NS_NCBI::CNcbiIstream& operator>>(NCBI_NS_NCBI::CNcbiIstream& is, NCBI_NS_STD::string& str);#endif/* * =========================================================================== * $Log: ncbistre.hpp,v $ * Revision 1000.4 2004/06/01 19:08:14 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.40 * * Revision 1.40 2004/04/26 14:45:08 ucko * Continue to suppress warnings about strstream in GCC 3.4.0, which uses * a slightly different include guard. * * Revision 1.39 2003/11/26 15:21:08 lavr * Do ad-hoc fstream fix conditionally for MSVC 6 only * * Revision 1.38 2003/11/18 11:57:46 siyan * Changed so @addtogroup does not cross namespace boundary * * Revision 1.37 2003/11/05 13:41:14 lavr * Enforce direction in CNcbiIfstream and CNcbiOfstream for MSVC * * Revision 1.36 2003/10/20 15:27:17 lavr * Implementations of CNcbiFstreams that forcedly turn on stream * buffering in MSVC (caution: very kludgy and ad hoc solution) * * Revision 1.35 2003/08/24 14:32:43 siyan * Added CORELIB___ prefix to the inclusion macros. * * Revision 1.34 2003/08/24 02:18:40 siyan * Documentation changes. * * Revision 1.33 2003/08/19 15:41:30 dicuccio * Added conditionally compiled prototype for operator<<(ostream&, __int64) * * Revision 1.32 2003/04/01 19:18:29 siyan * Added doxygen support * * Revision 1.31 2002/12/18 22:53:21 dicuccio * Added export specifier for building DLLs in windows. Added global list of * all such specifiers in mswin_exports.hpp, included through ncbistl.hpp * * Revision 1.30 2002/10/17 22:06:37 vakatov * + Endl() -- platform-specific EndOfLine * * Revision 1.29 2002/08/16 17:53:54 lavr * PUBSYNC, PUBSEEK* macros; SEEKOFF obsoleted; some formatting done * * Revision 1.28 2002/08/01 18:42:48 ivanov * + NcbiGetlineEOL() -- moved from ncbireg and renamed * * Revision 1.27 2002/05/22 17:58:20 ucko * Suppress GCC 3.1 warnings about <strstream>. * * Revision 1.26 2002/04/11 20:39:19 ivanov * CVS log moved to end of the file * * Revision 1.25 2001/08/15 20:53:00 juran * Heed warnings. * * Revision 1.24 2001/05/17 14:54:27 lavr * Typos corrected * * Revision 1.23 2001/03/26 20:26:57 vakatov * Added "Printable" symbol conversions (by A.Grichenko) * * Revision 1.22 2001/03/26 18:35:38 lavr * CT_* macros aligned in a pretty way * * Revision 1.21 2001/03/24 00:32:59 lavr * Macros added: CT_TO_INT_TYPE, CT_TO_CHAR_TYPE, CT_EQ_INT_TYPE * * Revision 1.20 2000/12/15 15:36:30 vasilche * Added header corelib/ncbistr.hpp for all string utility functions. * Optimized string utility functions. * Added assignment operator to CRef<> and CConstRef<>. * Add Upcase() and Locase() methods for automatic conversion. * * Revision 1.19 2000/12/12 14:39:46 vasilche * Added class Locase for printing strings to ostream with automatic conversion * * Revision 1.18 2000/12/12 14:20:14 vasilche * Added operator bool to CArgValue. * Added standard typedef element_type to CRef<> and CConstRef<>. * Macro iterate() now calls method end() only once and uses temporary variable * Various NStr::Compare() methods made faster. * Added class Upcase for printing strings to ostream with automatic conversion * * Revision 1.17 1999/12/28 18:55:25 vasilche * Reduced size of compiled object files: * 1. avoid inline or implicit virtual methods (especially destructors). * 2. avoid std::string's methods usage in inline methods. * 3. avoid string literals ("xxx") in inline methods. * * Revision 1.16 1999/11/09 20:57:03 vasilche * Fixed exception with conversion empty strstream to string. * * Revision 1.15 1999/10/21 15:44:18 vasilche * Added helper class CNcbiOstreamToString to convert CNcbiOstrstream buffer * to string. * * Revision 1.14 1999/06/08 21:34:35 vakatov * #HAVE_NO_CHAR_TRAITS:: handle the case of missing "std::char_traits::" * * Revision 1.13 1999/05/10 14:26:07 vakatov * Fixes to compile and link with the "egcs" C++ compiler under Linux * * Revision 1.12 1999/05/06 23:02:38 vakatov * Use the new(template-based, std::) stream library by default * * Revision 1.11 1998/12/28 17:56:29 vakatov * New CVS and development tree structure for the NCBI C++ projects * * Revision 1.10 1998/12/03 18:56:12 vakatov * minor fixes * * Revision 1.9 1998/12/03 16:38:32 vakatov * Added aux. function "Getline()" to read from "istream" to a "string" * Adopted standard I/O "string" <--> "istream" for old-fashioned streams * * Revision 1.8 1998/11/26 00:27:05 vakatov * Added <iomanip[.h]> and relevant #define's NcbiXXX * * Revision 1.7 1998/11/06 22:42:39 vakatov * Introduced BEGIN_, END_ and USING_ NCBI_SCOPE macros to put NCBI C++ * API to namespace "ncbi::" and to use it by default, respectively * Introduced THROWS_NONE and THROWS(x) macros for the exception * specifications * Other fixes and rearrangements throughout the most of "corelib" code * * ========================================================================== */#endif /* NCBISTRE__HPP */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -