From 0228e5963123633c45c52cbb616e5872c689be46 Mon Sep 17 00:00:00 2001 From: cxl Date: Mon, 28 Dec 2020 10:22:37 +0000 Subject: [PATCH] tutorials: CoreTutorial fixed git-svn-id: svn://ultimatepp.org/upp/trunk@15623 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- tutorial/CoreTutorial/Value2.cpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/tutorial/CoreTutorial/Value2.cpp b/tutorial/CoreTutorial/Value2.cpp index 7a253003e..7160462b8 100644 --- a/tutorial/CoreTutorial/Value2.cpp +++ b/tutorial/CoreTutorial/Value2.cpp @@ -1,5 +1,29 @@ #include "Tutorial.h" +struct Foo : ValueType { + int x; + + Foo(const Nuller&) { x = Null; } + Foo(int x) : x(x) {} + Foo() {} + + // We provide these methods to allow automatic conversion of Foo to/from Value + operator Value() const { return RichToValue(*this); } + Foo(const Value& v) { *this = v.Get(); } + + String ToString() const { return AsString(x); } + unsigned GetHashValue() const { return x; } + void Serialize(Stream& s) { s % x; } + bool operator==(const Foo& b) const { return x == b.x; } + bool IsNullInstance() const { return IsNull(x); } + int Compare(const Foo& b) const { return SgnCompare(x, b.x); } + // This type does not define XML nor Json serialization +}; + +INITBLOCK { // This has to be at file level scope + Value::Register(); // need to register value type integer id to allow serialization +} + void Value2Tutorial() { /// .Client types and `Value`, `RawValue`, `RichValue` @@ -33,6 +57,7 @@ void Value2Tutorial() /// support for these operations via template function specializations or (perhaps more /// convenient) using defined methods and inheriting from `ValueType` base class template: +#if 0 struct Foo : ValueType { int x; @@ -53,11 +78,8 @@ void Value2Tutorial() // This type does not define XML nor Json serialization }; -#if 0 INITBLOCK { // This has to be at file level scope -#endif Value::Register(); // need to register value type integer id to allow serialization -#if 0 } #endif