Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:01:53

0001 /*=============================================================================
0002     Copyright (c) 1998-2003 Joel de Guzman
0003     http://spirit.sourceforge.net/
0004 
0005   Distributed under the Boost Software License, Version 1.0. (See accompanying
0006   file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 =============================================================================*/
0008 #if !defined(BOOST_SPIRIT_COMPOSITE_HPP)
0009 #define BOOST_SPIRIT_COMPOSITE_HPP
0010 
0011 ///////////////////////////////////////////////////////////////////////////////
0012 #include <boost/compressed_pair.hpp>
0013 #include <boost/spirit/home/classic/namespace.hpp>
0014 
0015 ///////////////////////////////////////////////////////////////////////////////
0016 namespace boost { namespace spirit {
0017 
0018 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
0019 
0020 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
0021 #pragma warning(push)
0022 #pragma warning(disable:4512) //assignment operator could not be generated
0023 #endif
0024 
0025     ///////////////////////////////////////////////////////////////////////////
0026     //
0027     //  unary class.
0028     //
0029     //      Composite class composed of a single subject. This template class
0030     //      is parameterized by the subject type S and a base class to
0031     //      inherit from, BaseT. The unary class is meant to be a base class
0032     //      to inherit from. The inheritance structure, given the BaseT
0033     //      template parameter places the unary class in the middle of a
0034     //      linear, single parent hierarchy. For instance, given a class S
0035     //      and a base class B, a class D can derive from unary:
0036     //
0037     //          struct D : public unary<S, B> {...};
0038     //
0039     //      The inheritance structure is thus:
0040     //
0041     //            B
0042     //            |
0043     //          unary (has S)
0044     //            |
0045     //            D
0046     //
0047     //      The subject can be accessed from the derived class D as:
0048     //      this->subject();
0049     //
0050     //      Typically, the subject S is specified as typename S::embed_t.
0051     //      embed_t specifies how the subject is embedded in the composite
0052     //      (See parser.hpp for details).
0053     //
0054     ///////////////////////////////////////////////////////////////////////////
0055     template <typename S, typename BaseT>
0056     class unary : public BaseT
0057     {
0058     public:
0059 
0060         typedef BaseT                                           base_t;
0061         typedef typename boost::call_traits<S>::param_type      param_t;
0062         typedef typename boost::call_traits<S>::const_reference return_t;
0063         typedef S                                               subject_t;
0064         typedef typename S::embed_t                             subject_embed_t;
0065 
0066         unary(param_t subj_)
0067         : base_t(), subj(subj_) {}
0068 
0069         unary(BaseT const& base, param_t subj_)
0070         : base_t(base), subj(subj_) {}
0071 
0072         return_t
0073         subject() const
0074         { return subj; }
0075 
0076     private:
0077 
0078         subject_embed_t subj;
0079     };
0080 
0081     ///////////////////////////////////////////////////////////////////////////
0082     //
0083     //  binary class.
0084     //
0085     //      Composite class composed of a pair (left and right). This
0086     //      template class is parameterized by the left and right subject
0087     //      types A and B and a base class to inherit from, BaseT. The binary
0088     //      class is meant to be a base class to inherit from. The
0089     //      inheritance structure, given the BaseT template parameter places
0090     //      the binary class in the middle of a linear, single parent
0091     //      hierarchy. For instance, given classes X and Y and a base class
0092     //      B, a class D can derive from binary:
0093     //
0094     //          struct D : public binary<X, Y, B> {...};
0095     //
0096     //      The inheritance structure is thus:
0097     //
0098     //            B
0099     //            |
0100     //          binary (has X and Y)
0101     //            |
0102     //            D
0103     //
0104     //      The left and right subjects can be accessed from the derived
0105     //      class D as: this->left(); and this->right();
0106     //
0107     //      Typically, the pairs X and Y are specified as typename X::embed_t
0108     //      and typename Y::embed_t. embed_t specifies how the subject is
0109     //      embedded in the composite (See parser.hpp for details).
0110     //
0111     ///////////////////////////////////////////////////////////////////////////////
0112     template <typename A, typename B, typename BaseT>
0113     class binary : public BaseT
0114     {
0115     public:
0116 
0117         typedef BaseT                                           base_t;
0118         typedef typename boost::call_traits<A>::param_type      left_param_t;
0119         typedef typename boost::call_traits<A>::const_reference left_return_t;
0120         typedef typename boost::call_traits<B>::param_type      right_param_t;
0121         typedef typename boost::call_traits<B>::const_reference right_return_t;
0122         typedef A                                               left_t;
0123         typedef typename A::embed_t                             left_embed_t;
0124         typedef B                                               right_t;
0125         typedef typename B::embed_t                             right_embed_t;
0126 
0127         binary(left_param_t a, right_param_t b)
0128         : base_t(), subj(a, b) {}
0129 
0130         left_return_t
0131         left() const
0132         { return subj.first(); }
0133 
0134         right_return_t
0135         right() const
0136         { return subj.second(); }
0137 
0138     private:
0139 
0140         boost::compressed_pair<left_embed_t, right_embed_t> subj;
0141     };
0142 
0143 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
0144 #pragma warning(pop)
0145 #endif
0146 
0147 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
0148 
0149 }} // namespace BOOST_SPIRIT_CLASSIC_NS
0150 
0151 #endif