reference: Value related examples modernized

git-svn-id: svn://ultimatepp.org/upp/trunk@5157 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2012-07-09 07:02:51 +00:00
parent 9d32760da1
commit 52329bf08f
2 changed files with 14 additions and 18 deletions

View file

@ -7,7 +7,7 @@ struct RawFoo {
int b;
};
struct RichFoo : AssignValueTypeNo<RichFoo, 513, Comparable<RichFoo, Moveable<RichFoo> > > {
struct RichFoo : ValueType<RichFoo, 513, Comparable<RichFoo, Moveable<RichFoo> > > {
String a;
int b;
@ -18,14 +18,14 @@ struct RichFoo : AssignValueTypeNo<RichFoo, 513, Comparable<RichFoo, Moveable<Ri
bool IsNullInstance() const { return IsNull(a); }
operator Value() const { return RichValue<RichFoo>(*this); }
RichFoo(const Value& v) { *this = ValueTo<RichFoo>(v); }
RichFoo(const Value& v) { *this = v.To<RichFoo>(); }
RichFoo() {}
};
INITBLOCK
{
RichValue<RichFoo>::Register();
Value::Register<RichFoo>();
}
void Print(const Value& x)

View file

@ -2,36 +2,32 @@
using namespace Upp;
struct MyCustomValue : AssignValueTypeNo<MyCustomValue, 514> {
struct MyCustomValue : ValueType<MyCustomValue, 514> {
int x, y, z;
bool operator==(const MyCustomValue& o) const { return false; }
void Serialize(Stream& s) {}
String ToString() const { return "MyCustomValue"; }
unsigned GetHashValue() const { return 0; }
bool IsNullInstance() const { return false; }
String ToString() const { return "MyCustomValue"; }
operator Value() const { return RichValue<MyCustomValue>(*this); }
MyCustomValue(const Value& v) { *this = ValueTo<MyCustomValue>(v); }
MyCustomValue(const Value& v) { *this = v.To<MyCustomValue>(); }
void Xmlize(XmlIO& xio);
MyCustomValue() {}
};
void Xmlize(XmlIO xml, MyCustomValue& v)
void MyCustomValue::Xmlize(XmlIO& xio)
{
xml
.Attr("x", v.x)
.Attr("y", v.y)
.Attr("z", v.z)
xio
.Attr("x", x)
.Attr("y", y)
.Attr("z", z)
;
}
INITBLOCK {
RichValue<MyCustomValue>::Register();
Value::Register<MyCustomValue>("MyCustomValue");
}
REGISTER_VALUE_XMLIZE(MyCustomValue);
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);