Update of /cvsroot/boost/boost/boost/xpressive/detail/core/matcher
In directory 
sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv13025/boost/xpressive/detail/core/matcher

Modified Files:
        action_matcher.hpp end_matcher.hpp 
Log Message:
more efficient actions

Index: action_matcher.hpp
===================================================================
RCS file: 
/cvsroot/boost/boost/boost/xpressive/detail/core/matcher/action_matcher.hpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- action_matcher.hpp  29 Mar 2007 22:19:38 -0000      1.14
+++ action_matcher.hpp  31 Mar 2007 00:55:48 -0000      1.15
@@ -34,30 +34,57 @@
     //
     struct action_context
     {
-        template<typename Expr, typename Tag = typename Expr::tag_type>
-        struct eval
-          : proto::default_eval<Expr, action_context>
+        explicit action_context(action_args_type *action_args)
+          : action_args_(action_args)
+        {}
+
+        action_args_type const &args() const
+        {
+            return *this->action_args_;
+        }
+
+        // eval_terminal
+        template<typename Expr, typename Arg = typename 
proto::result_of::arg<Expr>::type>
+        struct eval_terminal
+          : proto::default_eval<Expr, action_context const>
         {};
 
-        template<typename Expr>
-        struct eval<Expr, proto::tag::terminal>
+        template<typename Expr, typename Arg>
+        struct eval_terminal<Expr, reference_wrapper<Arg> >
         {
-            typedef
-                typename add_reference<
-                    typename unwrap_reference<
-                        typename remove_reference<
-                            typename proto::default_eval<Expr, 
action_context>::result_type
-                        >::type
-                    >::type
-                >::type
-            result_type;
+            typedef Arg &result_type;
+            result_type operator()(Expr &expr, action_context const &) const
+            {
+                return proto::arg(expr).get();
+            }
+        };
 
-            result_type operator()(Expr &expr, action_context &ctx) const
+        template<typename Expr, typename Type, typename Int>
+        struct eval_terminal<Expr, action_arg<Type, Int> >
+        {
+            typedef typename action_arg<Type, Int>::reference result_type;
+            result_type operator()(Expr &expr, action_context const &ctx) const
             {
-                return proto::default_eval<Expr, action_context>()(expr, ctx);
+                action_args_type::const_iterator where = 
ctx.args().find(&typeid(proto::arg(expr)));
+                if(where == ctx.args().end())
+                {
+                    throw regex_error(regex_constants::error_badarg, "An 
argument to an action was unspecified");
+                }
+                return proto::arg(expr).cast(where->second);
             }
         };
 
+        // eval
+        template<typename Expr, typename Tag = typename Expr::tag_type>
+        struct eval
+          : proto::default_eval<Expr, action_context const>
+        {};
+
+        template<typename Expr>
+        struct eval<Expr, proto::tag::terminal>
+          : eval_terminal<Expr>
+        {};
+
         template<typename Expr>
         struct eval<Expr, proto::tag::mem_ptr>
         {
@@ -75,7 +102,7 @@
                         typename 
fusion::result_of::pop_front<proto::children<right_type const> >::type const
                       , typename proto::result_of::left<Expr>::type
                     >::type const
-                  , proto::eval_fun<action_context>
+                  , proto::eval_fun<action_context const>
                 >
             evaluated_args;
 
@@ -83,17 +110,20 @@
                 typename fusion::result_of::invoke<function_type, 
evaluated_args>::type
             result_type;
 
-            result_type operator()(Expr &expr, action_context &ctx) const
+            result_type operator()(Expr &expr, action_context const &ctx) const
             {
                 return fusion::invoke<function_type>(
                     proto::arg(proto::arg_c<0>(proto::right(expr)))
                   , evaluated_args(
                         
fusion::push_front(fusion::pop_front(proto::children_of(proto::right(expr))), 
proto::left(expr))
-                      , proto::eval_fun<action_context>(ctx)
+                      , proto::eval_fun<action_context const>(ctx)
                     )
                 );
             }
         };
+
+    private:
+        action_args_type *action_args_;
     };
 
     
///////////////////////////////////////////////////////////////////////////////
@@ -109,9 +139,9 @@
         {
         }
 
-        virtual void execute() const
+        virtual void execute(action_args_type *action_args) const
         {
-            action_context ctx;
+            action_context const ctx(action_args);
             proto::eval(this->actor_, ctx);
         }
 
@@ -166,32 +196,24 @@
     };
 
     
///////////////////////////////////////////////////////////////////////////////
-    // action_arg_transform
+    // by_ref_transform
     //
     template<typename Grammar>
-    struct action_arg_transform
+    struct by_ref_transform
       : Grammar
     {
-        action_arg_transform();
+        by_ref_transform();
 
         template<typename Expr, typename State, typename Visitor>
         struct apply
-        {
-            typedef typename proto::result_of::arg<Expr>::type action_arg_type;
-            typedef typename action_arg_type::reference arg_type;
-            typedef typename proto::terminal<arg_type>::type type;
-        };
+          : proto::terminal<typename 
proto::result_of::arg<Expr>::const_reference>
+        {};
         
         template<typename Expr, typename State, typename Visitor>
         static typename apply<Expr, State, Visitor>::type
         call(Expr const &expr, State const &state, Visitor &)
         {
-            detail::action_args_type::iterator where = 
state.action_args_->find(&typeid(proto::arg(expr)));
-            if(where == state.action_args_->end())
-            {
-                throw regex_error(regex_constants::error_badarg, "An argument 
to an action was unspecified");
-            }
-            return proto::as_arg(proto::arg(expr).cast(where->second));
+            return apply<Expr, State, Visitor>::type::make(proto::arg(expr));
         }
     };
 
@@ -202,8 +224,7 @@
       : proto::or_<
             subreg_transform<proto::terminal<detail::any_matcher> >
           , mark_transform<proto::terminal<detail::mark_placeholder> >
-          , action_arg_transform<proto::terminal<action_arg<proto::_, 
proto::_> > >
-          , proto::terminal<proto::_>
+          , by_ref_transform<proto::terminal<proto::_> >
           , proto::nary_expr<proto::_, proto::vararg<BindActionArgs> >
         >
     {};

Index: end_matcher.hpp
===================================================================
RCS file: 
/cvsroot/boost/boost/boost/xpressive/detail/core/matcher/end_matcher.hpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- end_matcher.hpp     22 Mar 2007 17:37:16 -0000      1.3
+++ end_matcher.hpp     31 Mar 2007 00:55:48 -0000      1.4
@@ -67,7 +67,7 @@
             // Now execute any actions that have been queued
             for(actionable<BidiIter> const *actor = state.action_list_.next; 0 
!= actor; actor = actor->next)
             {
-                actor->execute();
+                actor->execute(state.action_args_);
             }
 
             return true;


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs

Reply via email to