Wolframe, 0.0.3

C++ form function module

The following example of a form function in C++ declares structures for input and output with help of serialization. If you have a function with an empty input or empty output (procedure) then you can use the predefined structure _Wolframe::serialize::EmptyStruct for that.

struct MyInput
{
std::string data;
int id;
// ... your data structures are here
static const _Wolframe::serialize::StructDescriptionBase *getStructDescription();
};
class MyInputDescription :public _Wolframe::serialize::StructDescription<MyInput>
{
public:
MyInputDescription()
{
// here you define introspection for your data:
(*this)
("data", &MyInput::data)
("id", &MyInput::id)
;
}
};
const _Wolframe::serialize::StructDescriptionBase* MyInput::getStructDescription()
{
static MyInputDescription rt;
return &rt;
}
struct MyOutput
{
// ... your data structures are here as in MyInput
static const _Wolframe::serialize::StructDescriptionBase *getStructDescription()
{
// ... your data structure description is here as for MyInput
}
};
int myFunction( _Wolframe::proc::ExecContext* ctx, MyOutput& res, const MyInput& param)
{
// ... your function implementation is here
// ... it returns 0 on success or else an error code
}
WF_MODULE_BEGIN( "MyFunctions", "my functions short description")
WF_FORM_FUNCTION( "myfunc", myFunction, MyOutput, MyInput)