Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Examples

Y2NamespaceCPP.h File Reference

Helper classes/macros for accessing a C++-based namespace from YCP interpreter. More...

#include <string>
#include "ycp/YCPValue.h"
#include "ycp/YCode.h"
#include "ycp/YBlock.h"
#include "ycp/SymbolEntryPtr.h"
#include "ycp/y2log.h"

Go to the source code of this file.

Classes

class  Y2CPPFunctionCallBase
class  Y2CPPFunctionCall
class  Y2CPPFunction

Defines

#define Y2FUNCTIONCALL(namespace, name, signature, impl_class, impl_func)
 Macro to declare a class for calling a C++-based method without parameters.

#define Y2FUNCTIONCALL1(namespace, name, signature, param1type, impl_class, impl_func)
 Macro to declare a class for calling a C++-based method with a single parameter.

#define Y2FUNCTIONCALL2(namespace, name, signature, param1type, param2type, impl_class, impl_func)
 Macro to declare a class for calling a C++-based method with two parameters.

#define Y2FUNCTIONCALL3(namespace, name, signature, param1type, param2type, param3type, impl_class, impl_func)
 Macro to declare a class for calling a C++-based method with three parameters.

#define Y2FUNCTIONCALL4(namespace, name, signature, param1type, param2type, param3type, param4type, impl_class, impl_func)
 Macro to declare a class for calling a C++-based method with three parameters.

#define REGISTERFUNCTIONCALL(position, namespace, name)
 Registers a function without parameter in a namespace.

#define REGISTERFUNCTIONCALL1(position, namespace, name)
 Registers a function with a single parameter in a namespace.

#define REGISTERFUNCTIONCALL2(position, namespace, name)
 Registers a function with two parameters in a namespace.

#define REGISTERFUNCTIONCALL3(position, namespace, name)
 Registers a function with three parameters in a namespace.

#define REGISTERFUNCTIONCALL4(position, namespace, name)
 Registers a function with four parameters in a namespace.


Detailed Description

Helper classes/macros for accessing a C++-based namespace from YCP interpreter.

These macros and helper classes ease building a table of a functions to be avaiable to the rest of YaST.

Each function must be implemented using a class. The class declaration and all needed machinery are hidden in the Y2FUNCTIONCALL macros. Then, the macro must be registered at runtime using the corresponding REGISTERFUNCTIONCALL macro.


Define Documentation

#define REGISTERFUNCTIONCALL position,
namespace,
name   ) 
 

Value:

do {                                                            \
        Y2CPPFunction* mf = new Y2CPPFunction (                         \
            this,                                                       \
            #name,                                                      \
            new namespace##name##Function (this));                      \
        enterSymbol (mf->sentry (position), 0);                 \
    } while (0)
Registers a function without parameter in a namespace.

The function class must be already declared using the Y2FUNCTIONCALL macro. This macro registers the symbol in a table of globally visible symbols of the namespace.

Parameters:
position integer ID of the function in the namespace, must be unique
namespace the namespace, where the function should be registered
name the name of the function in the namespace

#define REGISTERFUNCTIONCALL1 position,
namespace,
name   ) 
 

Value:

do {                                                            \
        Y2CPPFunction* mf = new Y2CPPFunction (                         \
            this,                                                       \
            #name,                                                      \
            new namespace##name##Function1 (this));                     \
        enterSymbol (mf->sentry (position), 0);                 \
    } while (0)
Registers a function with a single parameter in a namespace.

The function class must be already declared using the Y2FUNCTIONCALL1 macro. This macro registers the symbol in a table of globally visible symbols of the namespace.

Parameters:
position integer ID of the function in the namespace, must be unique
namespace the namespace, where the function should be registered
name the name of the function in the namespace

#define REGISTERFUNCTIONCALL2 position,
namespace,
name   ) 
 

Value:

do {                                                            \
        Y2CPPFunction* mf = new Y2CPPFunction (                         \
            this,                                                       \
            #name,                                                      \
            new namespace##name##Function2 (this));                     \
        enterSymbol (mf->sentry (position), 0);                 \
    } while (0)
Registers a function with two parameters in a namespace.

The function class must be already declared using the Y2FUNCTIONCALL2 macro. This macro registers the symbol in a table of globally visible symbols of the namespace.

Parameters:
position integer ID of the function in the namespace, must be unique
namespace the namespace, where the function should be registered
name the name of the function in the namespace

#define REGISTERFUNCTIONCALL3 position,
namespace,
name   ) 
 

Value:

do {                                                            \
        Y2CPPFunction* mf = new Y2CPPFunction (                         \
            this,                                                       \
            #name,                                                      \
            new namespace##name##Function3 (this));                     \
        enterSymbol (mf->sentry (position), 0);                 \
    } while (0)
Registers a function with three parameters in a namespace.

The function class must be already declared using the Y2FUNCTIONCALL3 macro. This macro registers the symbol in a table of globally visible symbols of the namespace.

Parameters:
position integer ID of the function in the namespace, must be unique
namespace the namespace, where the function should be registered
name the name of the function in the namespace

#define REGISTERFUNCTIONCALL4 position,
namespace,
name   ) 
 

Value:

do {                                                            \
        Y2CPPFunction* mf = new Y2CPPFunction (                         \
            this,                                                       \
            #name,                                                      \
            new namespace##name##Function4 (this));                     \
        enterSymbol (mf->sentry (position), 0);                 \
    } while (0)
Registers a function with four parameters in a namespace.

The function class must be already declared using the Y2FUNCTIONCALL4 macro. This macro registers the symbol in a table of globally visible symbols of the namespace.

Parameters:
position integer ID of the function in the namespace, must be unique
namespace the namespace, where the function should be registered
name the name of the function in the namespace

#define Y2FUNCTIONCALL namespace,
name,
signature,
impl_class,
impl_func   ) 
 

Value:

class namespace##name##Function : public Y2CPPFunctionCall <impl_class> {       \
public:                                                 \
    namespace##name##Function(impl_class* instance) :   \
        Y2CPPFunctionCall <impl_class> (signature, instance)    \
    {}                                                  \
    virtual void registerParameters (YBlockPtr)         \
    {                                                   \
    }                                                   \
    virtual YCPValue evaluate (bool cse=false)          \
    {                                                   \
        if (cse) return YCPNull ();                     \
        return m_instance->impl_func ();                \
    }                                                   \
}
Macro to declare a class for calling a C++-based method without parameters.

The method impl_func must return a YCPValue.

Parameters:
namespace in which namespace should the method exist
name the name in the namespace, how should the method be known
signature textual representation of the method signature
impl_class C++ class implementing the method
impl_func method of the impl_class to be called
The following example will declare a class allowing to call string Pkg::YouGetDirectory(), which is implemented by a method YCPValue PkgModuleFunctions::YouGetDirectory ():

Y2FUNCTIONCALL (Pkg, YouGetDirectory, "string ()", PkgModuleFunctions, YouGetDirectory)

#define Y2FUNCTIONCALL1 namespace,
name,
signature,
param1type,
impl_class,
impl_func   ) 
 

Value:

class namespace##name##Function1 : public Y2CPPFunctionCall <impl_class> {      \
public:                                                 \
    namespace##name##Function1(impl_class* instance) :  \
        Y2CPPFunctionCall <impl_class> (signature, instance)    \
    {}                                                  \
    virtual void registerParameters (YBlockPtr decl)    \
    {                                                   \
        newParameter (decl, 1, Type::Const##param1type );       \
    }                                                   \
    virtual YCPValue evaluate (bool cse=false)          \
    {                                                   \
        if (cse) return YCPNull ();                     \
        YCPValue param1 = m_param1->value ();           \
        if (param1.isNull () || param1->isVoid ())      \
        {                                               \
            ycperror ("Passing 'nil' to %s::%s", #namespace, #name);    \
            return YCPNull ();                          \
        }                                               \
        return m_instance->impl_func (param1->as##param1type ());       \
    }                                                   \
}
Macro to declare a class for calling a C++-based method with a single parameter.

The method impl_func must return a YCPValue. The type of a parameter is prefixed with YCP to get a valid YCPValue-based class. As a consequence, the parameter type must start with the uppercase letter, for example List for YCPList.

Parameters:
namespace in which namespace should the method exist
name the name in the namespace, how should the method be known
signature textual representation of the method signature
param1type the type of the method parameter
impl_class C++ class implementing the method
impl_func method of the impl_class to be called
The following example will declare a class allowing to call boolean Pkg::IsAvailable(string tag), which is implemented by a method YCPValue PkgModuleFunctions::IsAvailable (const YCPString& tag):

Y2FUNCTIONCALL1 (Pkg, IsAvailable, "boolean (string)", PkgModuleFunctions, IsAvailable)

#define Y2FUNCTIONCALL2 namespace,
name,
signature,
param1type,
param2type,
impl_class,
impl_func   ) 
 

Value:

class namespace##name##Function2 : public Y2CPPFunctionCall <impl_class> {      \
public:                                                 \
    namespace##name##Function2(impl_class* instance) :  \
        Y2CPPFunctionCall <impl_class> (signature, instance)    \
    {}                                                  \
    virtual void registerParameters (YBlockPtr decl)    \
    {                                                   \
        newParameter (decl, 1, Type::Const##param1type );       \
        newParameter (decl, 2, Type::Const##param2type );       \
    }                                                   \
    virtual YCPValue evaluate (bool cse=false)          \
    {                                                   \
        if (cse) return YCPNull ();                     \
        YCPValue param1 = m_param1->value ();           \
        YCPValue param2 = m_param2->value ();           \
        if (param1.isNull () || param1->isVoid ())      \
        {                                               \
            ycperror ("Passing 'nil' to %s::%s", #namespace, #name);    \
            return YCPNull ();                          \
        }                                               \
        if (param2.isNull () || param2->isVoid ())      \
        {                                               \
            ycperror ("Passing 'nil' to %s::%s", #namespace, #name);    \
            return YCPNull ();                          \
        }                                               \
        return m_instance->impl_func (                  \
            param1->as##param1type ()                   \
            , param2->as##param2type ());               \
    }                                                   \
}
Macro to declare a class for calling a C++-based method with two parameters.

The method impl_func must return a YCPValue. The types of parameters are prefixed with YCP to get a valid YCPValue-based classes. As a consequence, the parameter type must start with the uppercase letter, for example List for YCPList.

Parameters:
namespace in which namespace should the method exist
name the name in the namespace, how should the method be known
signature textual representation of the method signature
param1type the type of the method 1st parameter
param2type the type of the method 2nd parameter
impl_class C++ class implementing the method
impl_func method of the impl_class to be called
The following example will declare a class allowing to call boolean Pkg::TargetInit(string root, boolean new), which is implemented by a method YCPValue PkgModuleFunctions::TargetInit (const YCPString& root, const YCPString& new):

Y2FUNCTIONCALL2 (Pkg, TargetInit, "boolean (string, boolean)", PkgModuleFunctions, TargetInit)

#define Y2FUNCTIONCALL3 namespace,
name,
signature,
param1type,
param2type,
param3type,
impl_class,
impl_func   ) 
 

Macro to declare a class for calling a C++-based method with three parameters.

The method impl_func must return a YCPValue. The types of parameters are prefixed with YCP to get a valid YCPValue-based classes. As a consequence, the parameter type must start with the uppercase letter, for example List for YCPList.

Parameters:
namespace in which namespace should the method exist
name the name in the namespace, how should the method be known
signature textual representation of the method signature
param1type the type of the method 1st parameter
param2type the type of the method 2nd parameter
param3type the type of the method 3rd parameter
impl_class C++ class implementing the method
impl_func method of the impl_class to be called
The following example will declare a class allowing to call string Pkg::SourceProvideFile (integer SrcId, integer medianr, string file), which is implemented by a method YCPValue PkgModuleFunctions::SourceProvideFile (const YCPInteger& id, const YCPInteger& mid, const YCPString& f):

Y2FUNCTIONCALL3 (Pkg, SourceProvideFile, "string (integer, integer, string)", PkgModuleFunctions, SourceProvideFile)

#define Y2FUNCTIONCALL4 namespace,
name,
signature,
param1type,
param2type,
param3type,
param4type,
impl_class,
impl_func   ) 
 

Macro to declare a class for calling a C++-based method with three parameters.

The method impl_func must return a YCPValue. The types of parameters are prefixed with YCP to get a valid YCPValue-based classes. As a consequence, the parameter type must start with the uppercase letter, for example List for YCPList.

Parameters:
namespace in which namespace should the method exist
name the name in the namespace, how should the method be known
signature textual representation of the method signature
param1type the type of the method 1st parameter
param2type the type of the method 2nd parameter
param3type the type of the method 3rd parameter
param4type the type of the method 4th parameter
impl_class C++ class implementing the method
impl_func method of the impl_class to be called
The following example will declare a class allowing to call list<string> Pkg::FilterPackages (bool byAuto, bool byApp, bool byUser, bool names_only), which is implemented by a method YCPValue PkgModuleFunctions::FilterPackages(const YCPBoolean& byAuto, const YCPBoolean& byApp, const YCPBoolean& byUser, const YCPBoolean& names_only):

Y2FUNCTIONCALL4 ( Pkg, FilterPackages, "list<string> (boolean, boolean, boolean, boolean)", Boolean, Boolean, Boolean, Boolean, PkgModuleFunctions, FilterPackages);


Generated on Fri Nov 9 18:15:23 2007 for yast2-core by doxygen 1.3.6