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