Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

xst_translator.h

Go to the documentation of this file.
00001 
00002 // Common Text Transformation Library
00003 // Copyright (C) 1997-2006 by Igor Kholodov. 
00004 //
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the
00017 // Free Software Foundation, Inc.,
00018 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019 //
00020 // mailto:cttl@users.sourceforge.net
00021 // http://sourceforge.net/projects/cttl/
00023 
00033 // xst_translator.h
00034 
00035 #ifndef _XST_TRANSLATOR_H_INCLUDED_
00036 #define _XST_TRANSLATOR_H_INCLUDED_
00037 
00038 namespace cttl_impl {
00039 
00068 template< typename LambdaT, typename TranslatorT >
00069 struct xst_translator {
00070 
00071     // allow any lambda primitive to access translator implementation
00072     template< typename D > friend struct xst_lambda_wrap;
00073 
00074     // allow all other translators to access translator implementation
00075     template< typename D, typename T > friend struct xst_translator;
00076 
00077     enum {
00079         const_value_ = LambdaT::const_value_,
00080 
00082         depth_ = LambdaT::depth_,
00083 
00085         capacity_ = LambdaT::capacity_,
00086 
00088         primitive_id_ = primitive_id_translator
00089     };
00090 
00092     typedef LambdaT lambda_T;
00093 
00095     typedef TranslatorT translator_T;
00096 
00098     typedef typename LambdaT::value_T value_T;
00099 
00101     typedef typename LambdaT::dereferenced_value_T dereferenced_value_T;
00102 
00104     typedef xst_translator< LambdaT, TranslatorT > left_T;
00105 
00107     typedef xst_translator< LambdaT, TranslatorT > right_T;
00108 
00110     typedef xst_translator< LambdaT, TranslatorT > reference_T;
00111 
00113     xst_translator( LambdaT const& lambda_, TranslatorT const& translator_ )
00114     :
00115     m_lambda( lambda_ ),
00116     m_translator( translator_ )
00117     {
00118     }
00119 
00121     xst_translator( xst_translator< LambdaT, TranslatorT > const& other_ )
00122     :
00123     m_lambda( other_.m_lambda ),
00124     m_translator( other_.m_translator )
00125     {
00126     }
00127 
00129     reference_T make_reference() const
00130     {
00131         return *this;
00132     }
00133     
00135     template<
00136         int LocationT
00137     >
00138     dereferenced_value_T& dereferenced_value( xst_lambda_wrap< xst_const_scalar< LocationT > > subscript_ )
00139     {
00140         return m_lambda.dereferenced_value( subscript_ );
00141     }
00142 
00144     left_T& left_lambda()
00145     {
00146         return *this; //m_lambda; //DEBUG//.left_lambda();
00147     }
00148 
00150     left_T const& left_lambda() const
00151     {
00152         return *this; //m_lambda; //DEBUG//.left_lambda();
00153     }
00154 
00156     right_T& right_lambda()
00157     {
00158         return *this; //m_lambda; //DEBUG//.right_lambda();
00159     }
00160 
00162     right_T const& right_lambda() const
00163     {
00164         return *this; //m_lambda; //DEBUG//.right_lambda();
00165     }
00166 
00168     // lambda compound traversal algorithms
00170 
00172     template< typename FunctorT >
00173     void traverse_bottom_up( FunctorT& functor_ )
00174     {
00175         m_lambda.traverse_bottom_up( functor_ );
00176     }
00177     
00179     template< typename FunctorT >
00180     void traverse_top_down( FunctorT& functor_ )
00181     {
00182         m_lambda.traverse_top_down( functor_ );
00183     }
00184     
00186     template< typename FunctorT >
00187     void traverse_bottom_up( FunctorT& functor_ ) const
00188     {
00189         m_lambda.traverse_bottom_up( functor_ );
00190     }
00191     
00193     template< typename FunctorT >
00194     void traverse_top_down( FunctorT& functor_ ) const
00195     {
00196         m_lambda.traverse_top_down( functor_ );
00197     }
00198     
00200     template< typename FunctorT >
00201     void subscript_top_down( FunctorT& functor_ ) const
00202     {
00203         m_lambda.subscript_top_down( functor_ );
00204     }
00205 
00207     template< typename FunctorT >
00208     void subscript_bottom_up( FunctorT& functor_ ) const
00209     {
00210         m_lambda.subscript_bottom_up( functor_ );
00211     }
00212 
00214     // Lambda primitive stack interface support
00216 
00218     template< typename SubscriptLambdaT, typename InputValueT >
00219     void push( SubscriptLambdaT subscript_, InputValueT const& data_ )
00220     {
00221         m_lambda.push( subscript_, m_translator( data_ ) );
00222     }
00223 
00225     template< typename SubscriptLambdaT >
00226     void pop( SubscriptLambdaT subscript_ )
00227     {
00228         m_lambda.pop( subscript_ );
00229     }
00230 
00232     template< typename SubscriptLambdaT >
00233     value_T const& top( SubscriptLambdaT subscript_ ) const
00234     {
00235         return m_lambda.top( subscript_ );
00236     }
00237 
00239     template< typename SubscriptLambdaT >
00240     value_T& top( SubscriptLambdaT subscript_ )
00241     {
00242         return m_lambda.top( subscript_ );
00243     }
00244 
00246     template< typename SubscriptLambdaT >
00247     size_t size( SubscriptLambdaT subscript_ ) const
00248     {
00249         return m_lambda.size( subscript_ );
00250     }
00251 
00253     template< typename SubscriptLambdaT >
00254     std::stack< value_T >* stack_ptr( SubscriptLambdaT subscript_ )
00255     {
00256         return m_lambda.stack_ptr( subscript_ );
00257     }
00258 
00260     template< typename SubscriptLambdaT >
00261     std::stack< value_T > const* stack_ptr( SubscriptLambdaT subscript_ ) const
00262     {
00263         return m_lambda.stack_ptr( subscript_ );
00264     }
00265 
00266 #ifdef CTTL_LAMBDA_REFLECTION
00267 
00268     typedef xst_translator< typename LambdaT::reflection_T, TranslatorT > reflection_T;
00269 
00271     reflection_T reflection() const
00272     {
00273         return reflection_T( m_lambda.reflection() );
00274     }
00275 #endif // CTTL_LAMBDA_REFLECTION
00276 
00277 private:
00279     // Implementation
00281 
00283     LambdaT m_lambda;
00284 
00286     TranslatorT m_translator;
00287 
00289     // subscript traversal algorithms
00291 
00293     template< typename SubscriptLambdaT, typename FunctorT >
00294     void xsubscript_top_down_subtree_switch( SubscriptLambdaT subscript_, FunctorT& functor_ ) const
00295     {
00296         m_lambda.xsubscript_top_down_subtree_switch( subscript_, functor_ );
00297     }
00298 
00300     template< int LocationT, typename FunctorT >
00301     void xsubscript_top_down_descend( FunctorT& functor_ ) const
00302     {
00303         m_lambda.xsubscript_top_down_descend< LocationT >( functor_ );
00304     }
00305 
00307     template< int LocationT, typename SubscriptLambdaT, typename FunctorT >
00308     void xsubscript_top_down_subtree_descend( SubscriptLambdaT subscript_, FunctorT& functor_ ) const
00309     {
00310         m_lambda.xsubscript_top_down_subtree_descend< LocationT >( subscript_, functor_ );
00311     }
00312 
00314     // subscript bottom up traversal
00316 
00318     template< typename SubscriptLambdaT, typename FunctorT >
00319     void xsubscript_bottom_up_subtree_switch( SubscriptLambdaT subscript_, FunctorT& functor_ ) const
00320     {
00321         m_lambda.xsubscript_bottom_up_subtree_switch( subscript_, functor_ );
00322     }
00323 
00325     template< int LocationT, typename FunctorT >
00326     void xsubscript_bottom_up_descend( FunctorT& functor_ ) const
00327     {
00328         m_lambda.xsubscript_bottom_up_descend< LocationT >( functor_ );
00329     }
00330 
00332     template< int LocationT, typename SubscriptLambdaT, typename FunctorT >
00333     void xsubscript_bottom_up_subtree_descend( SubscriptLambdaT subscript_, FunctorT& functor_ ) const
00334     {
00335         m_lambda.xsubscript_bottom_up_subtree_descend< LocationT >( subscript_, functor_ );
00336     }
00337 
00338 
00340     // Lambda primitive stack interface support
00342 
00355     template< int LocationT, typename InputValueT >
00356     void xpush_at_location( InputValueT const& data_ )
00357     {
00358         m_lambda.xpush_at_location< LocationT >( m_translator( data_ ) );
00359     }
00360 
00362     template< int LocationT, typename InputValueT >
00363     void xpush_descend( InputValueT const& data_ )
00364     {
00365         m_lambda.xpush_descend< LocationT >( m_translator( data_ ) );
00366     }
00367 
00369     template< typename SubscriptLambdaT, typename InputValueT >
00370     void xpush_sub_split( SubscriptLambdaT subscript_, InputValueT const& data_ )
00371     {
00372         m_lambda.xpush_sub_split( subscript_, m_translator( data_ ) );
00373     }
00374 
00376     template< int LocationT, typename SubscriptLambdaT, typename InputValueT >
00377     void xpush_sub_descend( SubscriptLambdaT subscript_, InputValueT const& data_ )
00378     {
00379         m_lambda.xpush_sub_descend< LocationT >( subscript_, m_translator( data_ ) );
00380     }
00381 
00382 
00390     template< int LocationT >
00391     void xpop_at_location()
00392     {
00393         m_lambda.xpop_at_location< LocationT >();
00394     }
00395 
00397     template< int LocationT >
00398     void xpop_descend()
00399     {
00400         m_lambda.xpop_descend< LocationT >();
00401     }
00402 
00404     template< typename SubscriptLambdaT >
00405     void xpop_sub_split( SubscriptLambdaT subscript_ )
00406     {
00407         m_lambda.xpop_sub_split( subscript_ );
00408     }
00409 
00411     template< int LocationT, typename SubscriptLambdaT >
00412     void xpop_sub_descend( SubscriptLambdaT subscript_ )
00413     {
00414         m_lambda.xpop_sub_descend< LocationT >( subscript_ );
00415     }
00416 
00424     template< int LocationT >
00425     value_T const& xtop_at_location() const
00426     {
00427         return m_lambda.xtop_at_location< LocationT >();
00428     }
00429 
00431     template< int LocationT >
00432     value_T const& xtop_descend() const
00433     {
00434         return m_lambda.xtop_descend< LocationT >();
00435     }
00436 
00438     template< typename SubscriptLambdaT >
00439     value_T const& xtop_sub_split( SubscriptLambdaT subscript_ ) const
00440     {
00441         return m_lambda.xtop_sub_split( subscript_ );
00442     }
00443 
00445     template< int LocationT, typename SubscriptLambdaT >
00446     value_T const& xtop_sub_descend( SubscriptLambdaT subscript_ ) const
00447     {
00448         return m_lambda.xtop_sub_descend< LocationT >( subscript_ );
00449     }
00450 
00451 
00453     // mutable data access
00455 
00463     template< int LocationT >
00464     value_T& xtop_at_location()
00465     {
00466         return m_lambda.xtop_at_location< LocationT >();
00467     }
00468 
00469 
00471     template< int LocationT >
00472     value_T& xtop_descend()
00473     {
00474         return m_lambda.xtop_descend< LocationT >();
00475     }
00476 
00478     // subscript access to lambda primitive
00480 
00482     template< typename SubscriptLambdaT >
00483     value_T& xtop_sub_split( SubscriptLambdaT subscript_ )
00484     {
00485         return m_lambda.xtop_sub_split( subscript_ );
00486     }
00487 
00489     template< int LocationT, typename SubscriptLambdaT >
00490     value_T& xtop_sub_descend( SubscriptLambdaT subscript_ )
00491     {
00492         return m_lambda.xtop_sub_descend< LocationT >( subscript_ );
00493     }
00494 
00496     template< int LocationT >
00497     size_t xsize_at_location() const
00498     {
00499         return m_lambda.xsize_at_location< LocationT >();
00500     }
00501 
00503     template< int LocationT >
00504     size_t xsize_descend() const
00505     {
00506         return m_lambda.xsize_descend< LocationT >();
00507     }
00508 
00510     template< typename SubscriptLambdaT >
00511     size_t xsize_sub_split( SubscriptLambdaT subscript_ ) const
00512     {
00513         return m_lambda.xsize_sub_split( subscript_ );
00514     }
00515 
00517     template< int LocationT, typename SubscriptLambdaT >
00518     size_t xsize_sub_descend( SubscriptLambdaT subscript_ ) const
00519     {
00520         return m_lambda.xsize_sub_descend< LocationT >( subscript_ );
00521     }
00522 
00523 
00525     template< int LocationT >
00526     std::stack< value_T >* xstack_ptr_at_location()
00527     {
00528         return m_lambda.xstack_ptr_at_location< LocationT >();
00529     }
00530 
00532     template< int LocationT >
00533     std::stack< value_T >* xstack_ptr_descend()
00534     {
00535         return m_lambda.xstack_ptr_descend< LocationT >();
00536     }
00537 
00539     template< typename SubscriptLambdaT >
00540     std::stack< value_T >* xstack_ptr_sub_split( SubscriptLambdaT subscript_ )
00541     {
00542         return m_lambda.xstack_ptr_sub_split( subscript_ );
00543     }
00544 
00546     template< int LocationT, typename SubscriptLambdaT >
00547     std::stack< value_T >* xstack_ptr_sub_descend( SubscriptLambdaT subscript_ )
00548     {
00549         return m_lambda.xstack_ptr_sub_descend< LocationT >( subscript_ );
00550     }
00551 
00552 
00554     template< int LocationT >
00555     std::stack< value_T > const* xstack_ptr_at_location() const
00556     {
00557         return m_lambda.xstack_ptr_at_location< LocationT >();
00558     }
00559 
00561     template< int LocationT >
00562     std::stack< value_T > const* xstack_ptr_descend() const
00563     {
00564         return m_lambda.xstack_ptr_descend< LocationT >();
00565     }
00566 
00568     template< typename SubscriptLambdaT >
00569     std::stack< value_T > const* xstack_ptr_sub_split( SubscriptLambdaT subscript_ ) const
00570     {
00571         return m_lambda.xstack_ptr_sub_split( subscript_ );
00572     }
00573 
00575     template< int LocationT, typename SubscriptLambdaT >
00576     std::stack< value_T > const* xstack_ptr_sub_descend( SubscriptLambdaT subscript_ ) const
00577     {
00578         return m_lambda.xstack_ptr_sub_descend< LocationT >( subscript_ );
00579     }
00580 
00581 
00582 };  // xst_translator
00583 
00584 
00585 }   // namespace cttl_impl
00586 
00587 
00588 #endif //_XST_TRANSLATOR_H_INCLUDED_

Generated on Thu Nov 2 17:48:24 2006 for CTTL Lambda Expression by  doxygen 1.3.9.1