workarounds_gcc-2_95.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // ----------------------------------------------------------------------------
  2. // workarounds for gcc < 3.0.
  3. // ----------------------------------------------------------------------------
  4. // Copyright Samuel Krempp 2003. Use, modification, and distribution are
  5. // subject to the Boost Software License, Version 1.0. (See accompanying
  6. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. // See http://www.boost.org/libs/format for library home page
  8. // ----------------------------------------------------------------------------
  9. // There's a lot to do, the stdlib shipped with gcc prior to 3.x
  10. // was terribly non-conforming.
  11. // . defines macros switches
  12. // . supplies template classes basic_foo<char,Tr> where gcc only supplies foo.
  13. // i.e :
  14. // - basic_ios<char, Tr> from ios
  15. // - basic_ostream<char, Tr> from ostream
  16. // - basic_srteambuf<char, Tr> from streambuf
  17. // these can be used transparently. (it obviously does not work for wchar_t)
  18. // . specialise CompatAlloc and CompatTraits to wrap gcc-2.95's
  19. // string_char_traits and std::alloc
  20. #if BOOST_WORKAROUND(__GNUC__, < 3) && !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION)
  21. // only for gcc-2.95's native stdlib
  22. #ifndef BOOST_FORMAT_WORKAROUNDS_GCC295_H
  23. #define BOOST_FORMAT_WORKAROUNDS_GCC295_H
  24. // SGI STL doesnt have <ostream> and others, so we need iostream.
  25. #include <iostream>
  26. #define BOOST_FORMAT_OSTREAM_DEFINED
  27. #include <streambuf.h>
  28. #define BOOST_FORMAT_STREAMBUF_DEFINED
  29. #define BOOST_NO_TEMPLATE_STD_STREAM
  30. #ifndef BOOST_IO_STD
  31. # define BOOST_IO_STD std::
  32. #endif
  33. // ***
  34. // gcc's simple classes turned into standard-like template classes :
  35. namespace std {
  36. // gcc has string_char_traits, it's incomplete.
  37. // we declare a std::char_traits, and specialize CompatTraits<..> on it
  38. // to do what is required
  39. template<class Ch>
  40. class char_traits; // no definition here, we will just use it as a tag.
  41. template <class Ch, class Tr>
  42. class basic_streambuf;
  43. template <class Tr>
  44. class basic_streambuf<char, Tr> : public streambuf {
  45. };
  46. template <class Ch, class Tr=::std::char_traits<Ch> >
  47. class basic_ios;
  48. template <class Tr>
  49. class basic_ios<char, Tr> : public ostream {
  50. public:
  51. basic_ios(streambuf * p) : ostream(p) {};
  52. char fill() const { return ios::fill(); } // gcc returns wchar..
  53. char fill(char c) { return ios::fill(c); } // gcc takes wchar..
  54. char widen(char c) { return c; }
  55. char narrow(char c, char def) { return c; }
  56. basic_ios& copyfmt(const ios& right) {
  57. fill(right.fill());
  58. flags(right.flags() );
  59. exceptions(right.exceptions());
  60. width(right.width());
  61. precision(right.precision());
  62. return *this;
  63. }
  64. };
  65. typedef ios ios_base;
  66. template <class Ch, class Tr>
  67. class basic_ostream;
  68. template <class Tr>
  69. class basic_ostream<char, Tr> : public basic_ios<char, Tr>
  70. {
  71. public:
  72. basic_ostream(streambuf * p) : basic_ios<char,Tr> (p) {}
  73. };
  74. } // namespace std
  75. namespace boost {
  76. namespace io {
  77. // ** CompatTraits gcc2.95 specialisations ----------------------------
  78. template<class Ch>
  79. class CompatTraits< ::std::string_char_traits<Ch> >
  80. : public ::std::string_char_traits<Ch>
  81. {
  82. public:
  83. typedef CompatTraits compatible_type;
  84. typedef Ch char_type;
  85. typedef int int_type;
  86. typedef ::std::streampos pos_type;
  87. typedef ::std::streamoff off_type;
  88. static char_type
  89. to_char_type(const int_type& meta) {
  90. return static_cast<char_type>(meta); }
  91. static int_type
  92. to_int_type(const char_type& ch) {
  93. return static_cast<int_type>(static_cast<unsigned char>(ch) );}
  94. static bool
  95. eq_int_type(const int_type& left, const int_type& right) {
  96. return left == right; }
  97. static int_type
  98. eof() {
  99. return static_cast<int_type>(EOF);
  100. }
  101. static int_type
  102. not_eof(const int_type& meta) {
  103. return (meta == eof()) ? 0 : meta;
  104. }
  105. };
  106. template<class Ch>
  107. class CompatTraits< ::std::char_traits<Ch> > {
  108. public:
  109. typedef CompatTraits< ::std::string_char_traits<Ch> > compatible_type;
  110. };
  111. // ** CompatAlloc gcc-2.95 specialisations ---------------------------
  112. template<>
  113. class CompatAlloc< ::std::alloc>
  114. {
  115. public:
  116. typedef ::std::allocator<char> compatible_type;
  117. };
  118. } // N.S. io
  119. } // N.S. boost
  120. #endif // include guard
  121. #endif // if workaround