123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- // TestApp1.cpp : Defines the entry point for the application.
- //
-
- #ifdef _WIN32
- #include "Win32/stdafx.h"
- #endif
-
- #include <DK.h>
-
-
- void PrintVariant(const DKString& name, const DKVariant& var, int indent = 0)
- {
- char ind[1024];
- {
- int i = 0;
- while (i < indent)
- {
- ind[i++] = ' ';
- }
- ind[i] = 0;
- }
-
- switch (var.ValueType())
- {
- case DKVariant::TypeUndefined:
- DKLog("%s \"%ls\" (Undefined)", ind, (const wchar_t*)name);
- break;
- case DKVariant::TypeInteger:
- DKLog("%s \"%ls\" (Integer) : %lld", ind, (const wchar_t*)name, var.Integer());
- break;
- case DKVariant::TypeFloat:
- DKLog("%s \"%ls\" (Float) : %f", ind, (const wchar_t*)name, var.Float());
- break;
- case DKVariant::TypeVector2:
- DKLog("%s \"%ls\" (Vector2)", ind, (const wchar_t*)name);
- break;
- case DKVariant::TypeVector3:
- DKLog("%s \"%ls\" (Vector3)", ind, (const wchar_t*)name);
- break;
- case DKVariant::TypeVector4:
- DKLog("%s \"%ls\" (Vector4)", ind, (const wchar_t*)name);
- break;
- case DKVariant::TypeMatrix2:
- DKLog("%s \"%ls\" (Matrix2x2)", ind, (const wchar_t*)name);
- break;
- case DKVariant::TypeMatrix3:
- DKLog("%s \"%ls\" (Matrix3x3)", ind, (const wchar_t*)name);
- break;
- case DKVariant::TypeMatrix4:
- DKLog("%s \"%ls\" (Matrix4x4)", ind, (const wchar_t*)name);
- break;
- case DKVariant::TypeQuaternion:
- DKLog("%s \"%ls\" (Quat)", ind, (const wchar_t*)name);
- break;
- case DKVariant::TypeRational:
- DKLog("%s \"%ls\" (Rational) %lld / %lld", ind, (const wchar_t*)name, var.Rational().Numerator(), var.Rational().Denominator());
- break;
- case DKVariant::TypeString:
- DKLog("%s \"%ls\" (String) : %ls", ind, (const wchar_t*)name, (const wchar_t*)var.String());
- break;
- case DKVariant::TypeDateTime:
- DKLog("%s \"%ls\" (DateTime)", ind, (const wchar_t*)name);
- break;
- case DKVariant::TypeData:
- DKLog("%s \"%ls\" (Data)", ind, (const wchar_t*)name);
- break;
- case DKVariant::TypeStructData:
- DKLog("%s \"%ls\" (StructData)", ind, (const wchar_t*)name);
- break;
- case DKVariant::TypeArray:
- DKLog("%s \"%ls\" (Array)", ind, (const wchar_t*)name);
- for (int i = 0; i < var.Array().Count(); ++i)
- {
- const DKVariant& sub = var.Array().Value(i);
- PrintVariant(DKString::Format("%ls[%d]", name, i), sub, indent + 4);
- }
- break;
- case DKVariant::TypePairs:
- DKLog("%s \"%ls\" (Pairs)", ind, (const wchar_t*)name);
- var.Pairs().EnumerateForward([indent](const DKVariant::VPairs::Pair& pair)
- {
- PrintVariant(pair.key, pair.value, indent+4);
- });
- break;
- default:
- DKLog("%s %ls (Unknown)");
- break;
- }
- }
-
- #ifdef _WIN32
- int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
- _In_opt_ HINSTANCE hPrevInstance,
- _In_ LPWSTR lpCmdLine,
- _In_ int nCmdShow)
- #else
- int main(int argc, const char * argv[])
- #endif
- {
- DKApplication app; // for DKLog to console
-
- DKVariant prop = DKVariant::TypePairs;
-
- prop.NewValueAtKeyPath("Root.Group1.Sub1.Container1.Item1", "1");
- prop.NewValueAtKeyPath("Root.Group1.Sub1.Container1.Item1", "2");
- prop.NewValueAtKeyPath("Root.Group1.Sub1.Container1.Item1", "3");
- prop.NewValueAtKeyPath("Root.Group1.Sub1.Container1.Item1", "4");
- prop.NewValueAtKeyPath("Root.Group1.Sub1.Container1.Item1", "5");
- prop.NewValueAtKeyPath("Root.Group1.Sub1.Container1.Item1", "6");
- prop.NewValueAtKeyPath("Root.Group1.Sub1.Container1.Item1", "7");
- prop.NewValueAtKeyPath("Root.Group1.Sub1.Container1.Item1", "8");
- prop.NewValueAtKeyPath("Root.Group1.Sub1.Container1.Item1", "9");
- prop.NewValueAtKeyPath("Root.Group1.Sub1.Container1.Item1", "10");
- prop.NewValueAtKeyPath("Root.Group1.Sub1.Container1.Item1", "11");
- prop.NewValueAtKeyPath("Root.Group1.Sub1.Container1.Item1", "12");
- prop.NewValueAtKeyPath("Root.Group1.Sub1.Container1.Item1", "13");
- prop.NewValueAtKeyPath("Root.Group1.Sub1.Container1.Item1", "14");
- prop.NewValueAtKeyPath("Root.Group1.Sub1.Container1.Item1", "15");
-
-
- PrintVariant("ROOT", prop);
- DKLog("-------------------");
- DKString findKey = "Root.Group1.Sub1.Container1.Item1";
- bool b = prop.FindObjectAtKeyPath(findKey, DKFunction([&](DKVariant& var)
- {
- PrintVariant(DKString::Format("(%ls)", (const wchar_t*)findKey), var);
- return false;
- }));
- DKLog("FindObjectAtKeyPath result: %d", (int)b);
-
-
- return 0;
- }
|