The Serializable class is the top class of all xdata data types.
The interface, depicted below, is currently very spartan.
Interface
namespace xdata
{
class Serializable
{
public:
virtual std::string type() const = 0;
virtual void setValue (const Serializable& s);
virtual int equals(const xdata::Serializable & s) = 0;
};
}
You can retrieve the type of the xdata object through the
type()
function. If you want
to use the value contained by the serializable you need to downcast it to the concrete type. Then
you can get a hand on the value contained or convert it to a string. The code snippet demonstrating
this has been taken from a callback of an
InfoSpace event. The event contains the pointer of
the modified
xdata::Serializable
value. To access it it needs to be downcasted.
void actionPerformed(xdata::Event & received )
{
xdata::ItemEvent& e = dynamic_cast(received);
xdata::Serializable* s = e.item();
if (s->type() == "int")
{
xdata::Integer * i = dynamic_cast(s);
std::cout << "value as integer: " << (int)*i << std::endl;
std::cout << "value as string : " << i->toString() << std::endl;
}
}
Outlook
Future releases will contain an augmented interface to allow for more powerful manipulations.