Update of /cvsroot/cpptool/CppParser/examples/parser
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7626/parser
Added Files:
functor3.h
Log Message:
-- extensions for grammar key-words ":declareSymbol", ":enterScope" and ":leaveScope"
... the new way of symboltable building
--- NEW FILE: functor3.h ---
/**
* additional definitions for making and binding functions with 3 parameters
*
*/
#ifndef __FUNCTOR3__
#define __FUNCTOR3__
template <class ReturnType, class Arg1Type, class Arg2Type, class Arg3Type>
class Functor3Base
{
public:
typedef ReturnType result_type;
virtual ~Functor3Base()
{
}
virtual ReturnType operator()( Arg1Type arg1,Arg2Type arg2,Arg3Type arg3 ) = 0;
};
template <class FunctorType, class Arg1Type, class Arg2Type, class Arg3Type>
class Functor3Impl: public Functor3Base<void,Arg1Type,Arg2Type,Arg3Type >
{
private:
FunctorType functor_;
public:
typedef Arg1Type first_argument_type;
typedef Arg2Type second_argument_type;
typedef Arg3Type third_argument_type;
typedef void result_type;
Functor3Impl( FunctorType functor )
: functor_( functor )
{
}
void operator()(Arg1Type arg1, Arg2Type arg2, Arg3Type arg3)
{
functor_(arg1, arg2, arg3);
}
};
template <class Arg1Type, class Arg2Type, class Arg3Type>
class Functor3
{
public:
typedef Arg1Type first_argument_type;
typedef Arg2Type second_argument_type;
typedef Arg3Type third_argument_type;
typedef void result_type;
explicit Functor3( Functor3Base<void, Arg1Type, Arg2Type, Arg3Type> *impl = 0 )
: impl_( impl )
{
}
void operator()(Arg1Type arg1, Arg2Type arg2, Arg3Type arg3)
{
(*impl_)(arg1, arg2, arg3);
}
operator bool() const
{
return impl_.get() != 0;
}
bool operator !() const
{
return impl_.get() == 0;
}
private:
CPPUT_DEDUCED_TYPENAME CppUT::SmartPtr< Functor3Base<void, Arg1Type, Arg2Type, Arg3Type> > impl_;
};
template<class ReturnType, class FunctorType, class BindArg2Type, class BindArg3Type>
class Bind3
{
public:
typedef CPPUT_DEDUCED_TYPENAME FunctorType::first_argument_type first_argument_type;
typedef void result_type;
Bind3( FunctorType functor, BindArg2Type arg2, BindArg3Type arg3 )
: functor_( functor )
, arg2_( arg2 )
, arg3_( arg3 )
{
}
void operator()(first_argument_type arg1)
{
functor_(arg1, arg2_, arg3_);
}
private:
FunctorType functor_;
BindArg2Type arg2_;
BindArg3Type arg3_;
};
template <class Arg1Type, class Arg2Type, class Arg3Type>
inline Functor3<Arg1Type, Arg2Type, Arg3Type>
makeCFn3( void (*function)(Arg1Type arg1, Arg2Type arg2, Arg3Type arg3) )
{
typedef void (*FunctionType)(Arg1Type arg1, Arg2Type arg2, Arg3Type arg3);
return Functor3<Arg1Type, Arg2Type, Arg3Type>(
new Functor3Impl<FunctionType, Arg1Type, Arg2Type, Arg3Type>( function ) );
}
template<class FunctorType, class Arg2Type, class Arg3Type>
CppUT::Functor1<CPPUT_DEDUCED_TYPENAME FunctorType::first_argument_type>
bind3( FunctorType functor, Arg2Type arg2, Arg3Type arg3 )
{
return CppUT::makeFn1(
Bind3<CPPUT_DEDUCED_TYPENAME FunctorType::result_type, FunctorType, Arg2Type, Arg3Type>(
functor, arg2, arg3 ) );
}
#endif
|