diff --git a/uppsrc/Core/srcdoc.tpp/CoreTutorial$en-us.tpp b/uppsrc/Core/srcdoc.tpp/CoreTutorial$en-us.tpp index 5d31450a4..6142f443e 100644 --- a/uppsrc/Core/srcdoc.tpp/CoreTutorial$en-us.tpp +++ b/uppsrc/Core/srcdoc.tpp/CoreTutorial$en-us.tpp @@ -465,50 +465,49 @@ to any value type that can contain Null:&] has little requirements for the type used `- only copy constructor and assignment operator are required:&] [s7; &] -[s7; struct Foo `{&] -[s7; -|int x;&] -[s7; -|&] -[s7; -|Foo(int x) : x(x) `{`}&] -[s7; -|Foo() `{`}&] +[s7; struct RawFoo `{&] +[s7; -|String x;&] [s7; `};&] [s7; &] +[s7; &] [s0; (int this case, default copy constructor and assignment operator are provided by compiler).&] [s7; &] -[s7; -|Value v `= RawToValue(Foo(12345));&] +[s7; -|RawFoo h;&] +[s7; -|h.x `= `"hello`";&] +[s7; -|Value q `= RawToValue(h);&] [s7; &] -[s16; v.Is() `= true&] -[s16; ValueTo(v).x `= 12345&] +[s16; q.Is() `= true&] +[s16; q.To().x `= `"hello`"&] [s7; &] [s0; [*/ RichValue] level Values provide more operations for Value `- equality test, IsNull test, hashing, conversion to text and serialization. In order to make serialization work, type must also have assigned an integer id (client types should use ids in range 10000..20000). Type can provide the support for these -operations via templete function specializations or (perhaps -more convenient) using defined methods:&] +operations via template function specializations or (perhaps +more convenient) using defined methods and inheriting from ValueType +base class template:&] [s7; &] -[s7; struct Foo : [* AssignValueTypeNo] `{&] +[s7; struct Foo : ValueType `{&] [s7; -|int x;&] [s7; -|&] +[s7; -|Foo(const Nuller`&) `{ x `= Null; `}&] [s7; -|Foo(int x) : x(x) `{`}&] [s7; -|Foo() `{`}&] [s7; &] -[s7; -|String [* ToString]() const `{ return AsString(x); +[s7; -|String ToString() const `{ return AsString(x); `}&] -[s7; -|unsigned [* GetHashValue]() const `{ return x; `}&] -[s7; -|void [* Serialize](Stream`& s) `{ s % x; `}&] -[s7; -|bool [* operator`=`=](const Foo`& b) const `{ return x `=`= b.x; -`}&] -[s7; -|bool [* IsNullInstance]() const `{ return IsNull(x); +[s7; -|unsigned GetHashValue() const `{ return x; `}&] +[s7; -|void Serialize(Stream`& s) `{ s % x; `}&] +[s7; -|bool operator`=`=(const Foo`& b) const `{ return x `=`= b.x; `}&] +[s7; -|bool IsNullInstance() const `{ return IsNull(x); `}-|&] [s7; `};&] [s7; &] -[s7; &] [s7; INITBLOCK `{&] -[s7; -|RichValue`::[* Register](); // registers the type for serialization&] +[s7; -|Value`::Register();&] [s7; `}&] -[s7; &] [s7; .......&] [s7; &] [s7; -|Value a `= [* RichToValue](Foo(54321));&] @@ -516,23 +515,23 @@ more convenient) using defined methods:&] [s7; &] [s16; (a `=`= b) `= true&] [s16; IsNull(a) `= false&] -[s16; ValueTo(v) `= 54321&] +[s16; v.Get() `= 54321&] [s7; &] [s7; -|String s `= StoreAsString(a);&] [s7; -|LoadFromString(v, s);&] [s7; &] -[s16; ValueTo(v) `= 54321&] +[s16; v.Get() `= 54321&] [s0; &] [s0; To avoid RichToValue and ValueTo calls, the client type can also provide constructor from Value and cast operator to Value:&] [s0; &] -[s7; struct Foo : AssignValueTypeNo `{&] +[s7; struct Foo : ValueType `{&] [s7; -|int x;&] [s7; -|&] [s7; ......&] [s7; -|&] [s7; -|operator Value() `{ return RichToValue(`*this); `}&] -[s7; -|Foo(const Value`& v) `{ `*this `= ValueTo(v); `}&] +[s7; -|Foo(const Value`& v) `{ `*this `= v.Get(); `}&] [s7; `};&] [s7; &] [s7; ......&] @@ -573,4 +572,4 @@ GetHashValue method defines GetHashValue function too.&] [s0; &] [s0; &] [s0; &] -[s0; [/ (to be continued)]] \ No newline at end of file +[s0; [/ (to be continued)]]] \ No newline at end of file