ultimatepp/reference/IzeLambda/IzeLambda.cpp
cxl 8bbf8a34e4 .reference
git-svn-id: svn://ultimatepp.org/upp/trunk@12539 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2018-11-15 08:26:07 +00:00

40 lines
864 B
C++

#include <Core/Core.h>
using namespace Upp;
struct Item {
int value;
};
struct Data {
Array<Item> array;
Point p;
template <class IO>
void Ize(IO& io) { // define single template function for both JSON and XML
io
.Var("p", p, [=] (IO& io, Point& m) { // use lambda to define how to 'ize' structure
io("X", m.x)("Y", m.y);
})
.Array("values", array, [=] (IO& io, Item& m) { // use lambda to define how to 'ize' elements
io("value", m.value);
}, "element") // this is ignored in Json, provides tag of single element
;
}
void Xmlize(XmlIO& io) { Ize(io); }
void Jsonize(JsonIO& io) { Ize(io); }
};
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
Data data;
data.array.Add().value = 12345;
data.p.x = 1;
data.p.y = 2;
LOG(StoreAsXML(data));
LOG(StoreAsJson(data));
}