tutorial: Core09

git-svn-id: svn://ultimatepp.org/upp/trunk@5159 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2012-07-09 07:05:51 +00:00
parent 54ef8749b5
commit 0d71d9e148
13 changed files with 81 additions and 8 deletions

View file

@ -1,3 +1,5 @@
description "String\377";
uses
Core;
@ -6,3 +8,4 @@ file
mainconfig
"" = "";

View file

@ -1,3 +1,5 @@
description "StringBuffer\377";
uses
Core;
@ -6,3 +8,4 @@ file
mainconfig
"" = "";

View file

@ -1,3 +1,5 @@
description "WString\377";
uses
Core;
@ -6,3 +8,4 @@ file
mainconfig
"" = "";

View file

@ -1,3 +1,5 @@
description "Date and Time\377";
uses
Core;
@ -6,3 +8,4 @@ file
mainconfig
"" = "";

View file

@ -1,3 +1,5 @@
description "AsString, ToString and operator<<\377";
uses
Core;
@ -6,3 +8,4 @@ file
mainconfig
"" = "";

View file

@ -1,3 +1,5 @@
description "Value\377";
uses
Core;
@ -6,3 +8,4 @@ file
mainconfig
"" = "";

View file

@ -1,3 +1,5 @@
description "Null\377";
uses
Core;
@ -6,3 +8,4 @@ file
mainconfig
"" = "";

View file

@ -2,9 +2,14 @@
using namespace Upp;
struct Foo : AssignValueTypeNo<Foo, 10010> {
struct RawFoo {
String x;
};
struct Foo : ValueType<Foo, 10010> {
int x;
Foo(const Nuller&) { x = Null; }
Foo(int x) : x(x) {}
Foo() {}
@ -14,27 +19,30 @@ struct Foo : AssignValueTypeNo<Foo, 10010> {
bool operator==(const Foo& b) const { return x == b.x; }
bool IsNullInstance() const { return IsNull(x); }
operator Value() { return RichToValue(*this); }
Foo(const Value& v) { *this = ValueTo<Foo>(v); }
operator Value() { return RichToValue(*this); }
Foo(const Value& v) { *this = v.Get<Foo>(); }
};
INITBLOCK {
RichValue<Foo>::Register();
Value::Register<Foo>();
}
CONSOLE_APP_MAIN
{
Value v = RawToValue(Foo(12345));
DUMP(v.Is<Foo>());
DUMP(ValueTo<Foo>(v).x);
RawFoo h;
h.x = "hello";
Value q = RawToValue(h);
DUMP(q.Is<RawFoo>());
DUMP(q.To<RawFoo>().x);
Value a = RichToValue(Foo(54321));
Value b = RichToValue(Foo(54321));
DUMP(a == b);
DUMP(IsNull(a));
String s = StoreAsString(a);
Value v;
LoadFromString(v, s);
DUMP(ValueTo<Foo>(v));
DUMP(v.Get<Foo>());
Value c = Foo(321);
Foo x = c;

View file

@ -1,3 +1,5 @@
description "Client types and Value, RawValue, RichValue\377";
uses
Core;

4
tutorial/Core08/init Normal file
View file

@ -0,0 +1,4 @@
#ifndef _Core08_icpp_init_stub
#define _Core08_icpp_init_stub
#include "Core/init"
#endif

View file

@ -0,0 +1,23 @@
#include <Core/Core.h>
using namespace Upp;
struct Foo {
String a;
int b;
unsigned GetHashValue() const { return CombineHash(a, b); }
};
CONSOLE_APP_MAIN
{
Foo x;
x.a = "world";
x.b = 22;
DUMP(GetHashValue(x));
x.a << '!';
DUMP(GetHashValue(x));
}

View file

@ -0,0 +1,11 @@
description "CombineHash\377";
uses
Core;
file
Core09.cpp;
mainconfig
"" = "SSE2";

4
tutorial/Core09/init Normal file
View file

@ -0,0 +1,4 @@
#ifndef _Core09_icpp_init_stub
#define _Core09_icpp_init_stub
#include "Core/init"
#endif