source: NonGTP/Boost/boost/spirit/phoenix/special_ops.hpp @ 857

Revision 857, 11.2 KB checked in by igarcia, 19 years ago (diff)
Line 
1/*=============================================================================
2    Phoenix V1.2.1
3    Copyright (c) 2001-2002 Joel de Guzman
4
5    Use, modification and distribution is subject to the Boost Software
6    License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7    http://www.boost.org/LICENSE_1_0.txt)
8==============================================================================*/
9#ifndef PHOENIX_SPECIAL_OPS_HPP
10#define PHOENIX_SPECIAL_OPS_HPP
11
12#include <boost/config.hpp>
13#ifdef BOOST_NO_STRINGSTREAM
14#include <strstream>
15#define PHOENIX_SSTREAM strstream
16#else
17#include <sstream>
18#define PHOENIX_SSTREAM stringstream
19#endif
20
21///////////////////////////////////////////////////////////////////////////////
22#include <boost/spirit/phoenix/operators.hpp>
23#include <iosfwd>
24
25///////////////////////////////////////////////////////////////////////////////
26#if defined(_STLPORT_VERSION) && defined(__STL_USE_OWN_NAMESPACE)
27#define PHOENIX_STD _STLP_STD
28#define PHOENIX_NO_STD_NAMESPACE
29#else
30#define PHOENIX_STD std
31#endif
32
33///////////////////////////////////////////////////////////////////////////////
34//#if !defined(PHOENIX_NO_STD_NAMESPACE)
35namespace PHOENIX_STD
36{
37//#endif
38
39    template<typename T> class complex;
40
41//#if !defined(PHOENIX_NO_STD_NAMESPACE)
42}
43//#endif
44
45///////////////////////////////////////////////////////////////////////////////
46namespace phoenix
47{
48
49///////////////////////////////////////////////////////////////////////////////
50//
51//  The following specializations take into account the C++ standard
52//  library components. There are a couple of issues that have to be
53//  dealt with to enable lazy operator overloads for the standard
54//  library classes.
55//
56//      *iostream (e.g. cout, cin, strstream/ stringstream) uses non-
57//      canonical shift operator overloads where the lhs is taken in
58//      by reference.
59//
60//      *I/O manipulators overloads for the RHS of the << and >>
61//      operators.
62//
63//      *STL iterators can be objects that conform to pointer semantics.
64//      Some operators need to be specialized for these.
65//
66//      *std::complex is given a rank (see rank class in operators.hpp)
67//
68///////////////////////////////////////////////////////////////////////////////
69
70///////////////////////////////////////////////////////////////////////////////
71//
72//  specialization for rank<std::complex>
73//
74///////////////////////////////////////////////////////////////////////////////
75template <typename T> struct rank<PHOENIX_STD::complex<T> >
76{ static int const value = 170 + rank<T>::value; };
77
78///////////////////////////////////////////////////////////////////////////////
79//
80//  specializations for std::istream
81//
82///////////////////////////////////////////////////////////////////////////////
83#if defined(__GNUC__) && (__GNUC__ < 3)
84    #if defined(_STLPORT_VERSION)
85        #define PHOENIX_ISTREAM _IO_istream_withassign
86    #else
87        #define PHOENIX_ISTREAM PHOENIX_STD::_IO_istream_withassign
88    #endif
89#else
90//    #if (defined(__ICL) && defined(_STLPORT_VERSION))
91//        #define PHOENIX_ISTREAM istream_withassign
92//    #else
93        #define PHOENIX_ISTREAM PHOENIX_STD::istream
94//    #endif
95#endif
96
97//////////////////////////////////
98#if defined(__GNUC__) && (__GNUC__ < 3)
99//    || (defined(__ICL) && defined(_STLPORT_VERSION))
100template <typename T1>
101struct binary_operator<shift_r_op, PHOENIX_ISTREAM, T1>
102{
103    typedef PHOENIX_STD::istream& result_type;
104    static result_type eval(PHOENIX_STD::istream& out, T1& rhs)
105    { return out >> rhs; }
106};
107#endif
108
109//////////////////////////////////
110template <typename T1>
111struct binary_operator<shift_r_op, PHOENIX_STD::istream, T1>
112{
113    typedef PHOENIX_STD::istream& result_type;
114    static result_type eval(PHOENIX_STD::istream& out, T1& rhs)
115    { return out >> rhs; }
116};
117
118//////////////////////////////////
119template <typename BaseT>
120inline typename impl::make_binary3
121    <shift_r_op, variable<PHOENIX_ISTREAM>, BaseT>::type
122operator>>(PHOENIX_ISTREAM& _0, actor<BaseT> const& _1)
123{
124    return impl::make_binary3
125    <shift_r_op, variable<PHOENIX_ISTREAM>, BaseT>
126    ::construct(var(_0), _1);
127}
128
129#undef PHOENIX_ISTREAM
130///////////////////////////////////////////////////////////////////////////////
131//
132//  specializations for std::ostream
133//
134///////////////////////////////////////////////////////////////////////////////
135#if defined(__GNUC__) && (__GNUC__ < 3)
136    #if defined(_STLPORT_VERSION)
137        #define PHOENIX_OSTREAM _IO_ostream_withassign
138    #else
139        #define PHOENIX_OSTREAM PHOENIX_STD::_IO_ostream_withassign
140    #endif
141#else
142//    #if (defined(__ICL) && defined(_STLPORT_VERSION))
143//        #define PHOENIX_OSTREAM ostream_withassign
144//    #else
145        #define PHOENIX_OSTREAM PHOENIX_STD::ostream
146//    #endif
147#endif
148
149//////////////////////////////////
150#if defined(__GNUC__) && (__GNUC__ < 3)
151//    || (defined(__ICL) && defined(_STLPORT_VERSION))
152template <typename T1>
153struct binary_operator<shift_l_op, PHOENIX_OSTREAM, T1>
154{
155    typedef PHOENIX_STD::ostream& result_type;
156    static result_type eval(PHOENIX_STD::ostream& out, T1 const& rhs)
157    { return out << rhs; }
158};
159#endif
160
161//////////////////////////////////
162template <typename T1>
163struct binary_operator<shift_l_op, PHOENIX_STD::ostream, T1>
164{
165    typedef PHOENIX_STD::ostream& result_type;
166    static result_type eval(PHOENIX_STD::ostream& out, T1 const& rhs)
167    { return out << rhs; }
168};
169
170//////////////////////////////////
171template <typename BaseT>
172inline typename impl::make_binary3
173    <shift_l_op, variable<PHOENIX_OSTREAM>, BaseT>::type
174operator<<(PHOENIX_OSTREAM& _0, actor<BaseT> const& _1)
175{
176    return impl::make_binary3
177    <shift_l_op, variable<PHOENIX_OSTREAM>, BaseT>
178    ::construct(var(_0), _1);
179}
180
181#undef PHOENIX_OSTREAM
182
183///////////////////////////////////////////////////////////////////////////////
184//
185//  specializations for std::strstream / stringstream
186//
187///////////////////////////////////////////////////////////////////////////////
188template <typename T1>
189struct binary_operator<shift_r_op, PHOENIX_STD::PHOENIX_SSTREAM, T1>
190{
191    typedef PHOENIX_STD::istream& result_type;
192    static result_type eval(PHOENIX_STD::istream& out, T1& rhs)
193    { return out >> rhs; }
194};
195
196//////////////////////////////////
197template <typename BaseT>
198inline typename impl::make_binary3
199    <shift_r_op, variable<PHOENIX_STD::PHOENIX_SSTREAM>, BaseT>::type
200operator>>(PHOENIX_STD::PHOENIX_SSTREAM& _0, actor<BaseT> const& _1)
201{
202    return impl::make_binary3
203    <shift_r_op, variable<PHOENIX_STD::PHOENIX_SSTREAM>, BaseT>
204    ::construct(var(_0), _1);
205}
206
207//////////////////////////////////
208template <typename T1>
209struct binary_operator<shift_l_op, PHOENIX_STD::PHOENIX_SSTREAM, T1>
210{
211    typedef PHOENIX_STD::ostream& result_type;
212    static result_type eval(PHOENIX_STD::ostream& out, T1 const& rhs)
213    { return out << rhs; }
214};
215
216//////////////////////////////////
217template <typename BaseT>
218inline typename impl::make_binary3
219    <shift_l_op, variable<PHOENIX_STD::PHOENIX_SSTREAM>, BaseT>::type
220operator<<(PHOENIX_STD::PHOENIX_SSTREAM& _0, actor<BaseT> const& _1)
221{
222    return impl::make_binary3
223    <shift_l_op, variable<PHOENIX_STD::PHOENIX_SSTREAM>, BaseT>
224    ::construct(var(_0), _1);
225}
226
227///////////////////////////////////////////////////////////////////////////////
228//
229//      I/O manipulator specializations
230//
231///////////////////////////////////////////////////////////////////////////////
232#if (!defined(__GNUC__) || (__GNUC__ > 2))
233//    && !(defined(__ICL) && defined(_STLPORT_VERSION))
234
235typedef PHOENIX_STD::ios_base&  (*iomanip_t)(PHOENIX_STD::ios_base&);
236typedef PHOENIX_STD::istream&   (*imanip_t)(PHOENIX_STD::istream&);
237typedef PHOENIX_STD::ostream&   (*omanip_t)(PHOENIX_STD::ostream&);
238
239#if defined(__BORLANDC__)
240
241///////////////////////////////////////////////////////////////////////////////
242//
243//      Borland does not like i/o manipulators functions such as endl to
244//      be the rhs of a lazy << operator (Borland incorrectly reports
245//      ambiguity). To get around the problem, we provide function
246//      pointer versions of the same name with a single trailing
247//      underscore.
248//
249//      You can use the same trick for other i/o manipulators.
250//      Alternatively, you can prefix the manipulator with a '&'
251//      operator. Example:
252//
253//          cout << arg1 << &endl
254//
255///////////////////////////////////////////////////////////////////////////////
256
257imanip_t    ws_     = &PHOENIX_STD::ws;
258iomanip_t   dec_    = &PHOENIX_STD::dec;
259iomanip_t   hex_    = &PHOENIX_STD::hex;
260iomanip_t   oct_    = &PHOENIX_STD::oct;
261omanip_t    endl_   = &PHOENIX_STD::endl;
262omanip_t    ends_   = &PHOENIX_STD::ends;
263omanip_t    flush_  = &PHOENIX_STD::flush;
264
265#else // __BORLANDC__
266
267///////////////////////////////////////////////////////////////////////////////
268//
269//      The following are overloads for I/O manipulators.
270//
271///////////////////////////////////////////////////////////////////////////////
272template <typename BaseT>
273inline typename impl::make_binary1<shift_l_op, BaseT, imanip_t>::type
274operator>>(actor<BaseT> const& _0, imanip_t _1)
275{
276    return impl::make_binary1<shift_l_op, BaseT, imanip_t>::construct(_0, _1);
277}
278
279//////////////////////////////////
280template <typename BaseT>
281inline typename impl::make_binary1<shift_l_op, BaseT, iomanip_t>::type
282operator>>(actor<BaseT> const& _0, iomanip_t _1)
283{
284    return impl::make_binary1<shift_l_op, BaseT, iomanip_t>::construct(_0, _1);
285}
286
287//////////////////////////////////
288template <typename BaseT>
289inline typename impl::make_binary1<shift_l_op, BaseT, omanip_t>::type
290operator<<(actor<BaseT> const& _0, omanip_t _1)
291{
292    return impl::make_binary1<shift_l_op, BaseT, omanip_t>::construct(_0, _1);
293}
294
295//////////////////////////////////
296template <typename BaseT>
297inline typename impl::make_binary1<shift_l_op, BaseT, iomanip_t>::type
298operator<<(actor<BaseT> const& _0, iomanip_t _1)
299{
300    return impl::make_binary1<shift_l_op, BaseT, iomanip_t>::construct(_0, _1);
301}
302
303#endif // __BORLANDC__
304#endif // !defined(__GNUC__) || (__GNUC__ > 2)
305
306///////////////////////////////////////////////////////////////////////////////
307//
308//  specializations for stl iterators and containers
309//
310///////////////////////////////////////////////////////////////////////////////
311template <typename T>
312struct unary_operator<dereference_op, T>
313{
314    typedef typename T::reference result_type;
315    static result_type eval(T const& iter)
316    { return *iter; }
317};
318
319//////////////////////////////////
320template <typename T0, typename T1>
321struct binary_operator<index_op, T0, T1>
322{
323    typedef typename T0::reference result_type;
324    static result_type eval(T0& container, T1 const& index)
325    { return container[index]; }
326};
327
328//////////////////////////////////
329template <typename T0, typename T1>
330struct binary_operator<index_op, T0 const, T1>
331{
332    typedef typename T0::const_reference result_type;
333    static result_type eval(T0 const& container, T1 const& index)
334    { return container[index]; }
335};
336
337///////////////////////////////////////////////////////////////////////////////
338}   //  namespace phoenix
339
340#undef PHOENIX_SSTREAM
341#undef PHOENIX_STD
342#endif
Note: See TracBrowser for help on using the repository browser.