Wolframe, 0.0.3

Custom data type module
class MyInitializer
{
public:
MyInitializer( const std::vector<_Wolframe::types::Variant>& arg)
{
// ... construct your custom data type initializer object here
}
static _Wolframe::types::CustomDataInitializer* create( const std::vector<_Wolframe::types::Variant>& arg)
{
return new MyInitializer( arg);
}
};
class MyValue
{
public:
explicit MyValue( const std::string& dt, const MyInitializer* ini=0)
{
// ... put your value constructor from string here
}
virtual int compare( const _Wolframe::types::CustomDataValue& o) const
{
// ... put your compare function returning -1,0 or +1 here
}
virtual std::string tostring() const
{
// ... put your conversion of the value to a string here
}
virtual void assign( const _Wolframe::types::Variant& o)
{
// ... put the assignment from a variant data type here
}
virtual bool getBaseTypeValue( _Wolframe::types::Variant& dest) const
{
// ... try to convert this value to a variant data type returned in dest
// ... return false, if not possible
}
{
// ... return an exact copy of this here
}
{
// ... create a default value from initializer (can be NULL) here
}
};
class MyType
{
public:
MyType( const std::string& name_)
:_Wolframe::types::CustomDataType(name_,&MyValue::create,&MyInitializer::create)
{
define( Increment, &increment);
define( Add, &add);
define( "mymethod", &myMethod);
}
static _Wolframe::types::Variant myMethod( const _Wolframe::types::CustomDataValue& operand, const std::vector<_Wolframe::types::Variant>& arg )
{
// ... the implementation of the method "mymethod" operating on operand with arg as list of arguments comes here
}
{
// ... the increment operator implementation follows here
}
{
// ... the implementation of the addition operator operating on operand with arg as argument comes here
}
static _Wolframe::types::CustomDataType* create( const std::string& name)
{
return new MyType( name);
}
};
WF_MODULE_BEGIN( "mydatatype", "my custom data type module")
WF_CUSTOM_DATATYPE( "mydatatype", MyType::create)