Hongtae Kim 7 лет назад
Родитель
Сommit
59d46933c7
1 измененных файлов: 87 добавлений и 39 удалений
  1. 87
    39
      TestApp1/TestApp1.cpp

+ 87
- 39
TestApp1/TestApp1.cpp Просмотреть файл

@@ -8,49 +8,85 @@
8 8
 #include <DK.h>
9 9
 
10 10
 
11
-class TestApp1 : public DKApplication
11
+void PrintVariant(const DKString& name, const DKVariant& var, int indent = 0)
12 12
 {
13
-	DKObject<DKWindow> window;
14
-public:
15
-	void OnInitialize(void) override
13
+	char ind[1024];
16 14
 	{
17
-		DKLog("%s", DKGL_FUNCTION_NAME);
18
-		window = DKWindow::Create("DefaultWindow");
19
-		window->Activate();
20
-
21
-		window->AddEventHandler(this,
22
-			DKFunction([this](const DKWindow::WindowEvent& e) {
23
-			if (e.type == DKWindow::WindowEvent::WindowClosed)
24
-				DKApplication::Instance()->Terminate(0);
25
-		}),
26
-			NULL, NULL);
27
-
15
+		int i = 0;
16
+		while (i < indent)
17
+		{
18
+			ind[i++] = ' ';
19
+		}
20
+		ind[i] = 0;
28 21
 	}
29
-	void OnTerminate(void) override
22
+
23
+	switch (var.ValueType())
30 24
 	{
31
-		DKLog("%s", DKGL_FUNCTION_NAME);
32
-		DKLog("Memory Pool Statistics");
33
-		size_t numBuckets = DKMemoryPoolNumberOfBuckets();
34
-		DKMemoryPoolBucketStatus* buckets = new DKMemoryPoolBucketStatus[numBuckets];
35
-		DKMemoryPoolQueryAllocationStatus(buckets, numBuckets);
36
-		size_t usedBytes = 0;
37
-		for (int i = 0; i < numBuckets; ++i)
25
+	case DKVariant::TypeUndefined:
26
+		DKLog("%s %ls (Undefined)", ind, (const wchar_t*)name);
27
+		break;
28
+	case DKVariant::TypeInteger:
29
+		DKLog("%s %ls (Integer) : %lld", ind, (const wchar_t*)name, var.Integer());
30
+		break;
31
+	case DKVariant::TypeFloat:
32
+		DKLog("%s %ls (Float) : %f", ind, (const wchar_t*)name, var.Float());
33
+		break;
34
+	case DKVariant::TypeVector2:
35
+		DKLog("%s %ls (Vector2)", ind, (const wchar_t*)name);
36
+		break;
37
+	case DKVariant::TypeVector3:
38
+		DKLog("%s %ls (Vector3)", ind, (const wchar_t*)name);
39
+		break;
40
+	case DKVariant::TypeVector4:
41
+		DKLog("%s %ls (Vector4)", ind, (const wchar_t*)name);
42
+		break;
43
+	case DKVariant::TypeMatrix2:
44
+		DKLog("%s %ls (Matrix2x2)", ind, (const wchar_t*)name);
45
+		break;
46
+	case DKVariant::TypeMatrix3:
47
+		DKLog("%s %ls (Matrix3x3)", ind, (const wchar_t*)name);
48
+		break;
49
+	case DKVariant::TypeMatrix4:
50
+		DKLog("%s %ls (Matrix4x4)", ind, (const wchar_t*)name);
51
+		break;
52
+	case DKVariant::TypeQuaternion:
53
+		DKLog("%s %ls (Quat)", ind, (const wchar_t*)name);
54
+		break;
55
+	case DKVariant::TypeRational:
56
+		DKLog("%s %ls (Rational) %lld / %lld", ind, (const wchar_t*)name, var.Rational().Numerator(), var.Rational().Denominator());
57
+		break;
58
+	case DKVariant::TypeString:
59
+		DKLog("%s %ls (String) : %ls", ind, (const wchar_t*)name, (const wchar_t*)var.String());
60
+		break;
61
+	case DKVariant::TypeDateTime:
62
+		DKLog("%s %ls (DateTime)", ind, (const wchar_t*)name);
63
+		break;
64
+	case DKVariant::TypeData:
65
+		DKLog("%s %ls (Data)", ind, (const wchar_t*)name);
66
+		break;
67
+	case DKVariant::TypeStructData:
68
+		DKLog("%s %ls (StructData)", ind, (const wchar_t*)name);
69
+		break;
70
+	case DKVariant::TypeArray:
71
+		DKLog("%s %ls (Array)", ind, (const wchar_t*)name);
72
+		for (int i = 0; i < var.Array().Count(); ++i)
38 73
 		{
39
-			if (buckets[i].totalChunks > 0)
40
-			{
41
-				DKLog("--> %lu: allocated:%lu, reserved:%.1fKB. (usage:%.1f%%)",
42
-					buckets[i].chunkSize,
43
-					buckets[i].chunkSize * buckets[i].usedChunks,
44
-					double(buckets[i].chunkSize * (buckets[i].totalChunks - buckets[i].usedChunks)) / 1024.0,
45
-					double(buckets[i].usedChunks) / double(buckets[i].totalChunks) * 100.0);
46
-				usedBytes += buckets[i].chunkSize * buckets[i].usedChunks;
47
-			}
74
+			const DKVariant& sub = var.Array().Value(i);
75
+			PrintVariant(DKString::Format("%ls[%d]", name, i), sub, indent + 4);
48 76
 		}
49
-		DKLog("MemoryPool Usage: %.1fMB / %.1fMB", double(usedBytes) / (1024 * 1024), double(DKMemoryPoolSize()) / (1024 * 1024));
50
-		delete[] buckets;
77
+		break;
78
+	case DKVariant::TypePairs:
79
+		DKLog("%s %ls (Pairs)", ind, (const wchar_t*)name);
80
+		var.Pairs().EnumerateForward([indent](const DKVariant::VPairs::Pair& pair)
81
+		{
82
+			PrintVariant(pair.key, pair.value, indent+4);
83
+		});
84
+		break;
85
+	default:
86
+		DKLog("%s %ls (Unknown)");
87
+		break;
51 88
 	}
52
-};
53
-
89
+}
54 90
 
55 91
 #ifdef _WIN32
56 92
 int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
@@ -61,7 +97,19 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
61 97
 int main(int argc, const char * argv[])
62 98
 #endif
63 99
 {
64
-	TestApp1 app;
65
-	DKPropertySet::SystemConfig().SetValue("AppDelegate", "AppDelegate");
66
-	return app.Run();
100
+	DKApplication app;	// for DKLog to console
101
+
102
+	DKVariant prop = DKVariant::TypePairs;
103
+
104
+	DKVariant::VPairs& root = prop.Pairs();
105
+	DKVariant::VPairs& sub1 = root.Value("Sub1").Pairs();
106
+		
107
+
108
+	DKVariant::VPairs& sub2 = root.Value("Sub2").Pairs();
109
+	DKVariant::VInteger& sub3 = root.Value("Sub3").Integer();
110
+
111
+	PrintVariant("ROOT", prop);
112
+
113
+
114
+	return 0;
67 115
 }