void TestBinaryStream::TestProperties() { Registry R; R.AddClass<void>(); R.AddClass<int>(); R.AddClass<String>(); ClassBuilder<TestPropertiesStruct>(R, "TestPropertiesStruct") .Methods .Properties ("num", &TestPropertiesStruct::num) ("str", &TestPropertiesStruct::str) ("foo", &TestPropertiesStruct::foo) ; Pointer<TestPropertiesStruct> tps = R.New<TestPropertiesStruct>(); tps->num = 42; tps->str = "hello"; tps->foo = R.New<TestPropertiesStruct>(); KAI_TRACE_1(tps); BinaryStream stream(R); stream << tps; KAI_TRACE_1(stream); Object result; stream >> result; KAI_TRACE_1(result); KAI_TEST_TRUE(result.Exists()); KAI_TEST_TRUE(result.IsType<TestPropertiesStruct>()); KAI_TEST_EQUIV(result.GetValue<int>("num"), 42); KAI_TEST_EQUIV(result.GetValue<String>("str"), "hello"); KAI_TEST_TRUE(result.Get("foo").IsType<TestPropertiesStruct>()); }
void TestBinaryStream::TestList() { Registry R; List::Register(R); R.AddClass<void>("void"); R.AddClass<int>("int"); R.AddClass<String>("String"); Pointer<List> list = R.New<List>(); list->Append(R.New(123)); list->Append(R.New(456)); list->Append(R.New("Hello")); BinaryStream stream(R); stream << list; Object result; stream >> result; KAI_TRACE_1(list); KAI_TRACE_1(stream); KAI_TRACE_1(result); KAI_TEST_TRUE(result.Exists()); KAI_TEST_TRUE(result.IsType<List>()); KAI_TEST_EQUIV(ConstDeref<List>(result).Size(), 3); KAI_TEST_EQUIV(result, list); Pointer<List> result_list = result; KAI_TEST_EQUIV(ConstDeref<String>(result_list->Back()), "Hello"); result_list->PopBack(); KAI_TEST_EQUIV(ConstDeref<int>(result_list->Back()), 456); result_list->PopBack(); KAI_TEST_EQUIV(ConstDeref<int>(result_list->Back()), 123); result_list->PopBack(); KAI_TEST_EQUIV(ConstDeref<List>(result_list).Size(), 0); }
void MarkObjectAndChildren(Object const &Q, bool M) { if (!Q.Exists()) return; MarkObjectAndChildren(Q.GetStorageBase(), M); }
void Registry::PruneRetained() { RetainedObjects::iterator retained = retained_objects.begin(), end = retained_objects.end(); while (retained != end) { Object object = GetObject(*retained); if (!object.Exists()) retained = retained_objects.erase(retained); else ++retained; } }
void StorageBase::Set(const Label &name, Object const &child) { if (child.GetHandle() == GetHandle()) KAI_THROW_1(InternalError, "Recursion"); // mark the object as being altered SetDirty(); // set a property if it exists ClassBase const *klass = GetClass(); if (klass->HasProperty(name)) { klass->GetProperty(name).SetValue(*this, child); return; } // otherwise this is a child object. remove any existing child Remove(name); // update the child object if (!child.Exists()) { Dictionary::iterator ch = dictionary.find(name); if (ch != dictionary.end()) dictionary.erase(ch); return; } StorageBase &base = KAI_NAMESPACE(GetStorageBase(child)); base.SetLabel(name); base.SetParentHandle(GetHandle()); bool clean = base.IsClean(); bool konst = base.IsConst(); bool managed = base.IsManaged(); base.switches = switches; // inherit properties of parent... if (clean) // ...but preserve cleanliness base.switches |= IObject::Clean; else base.switches &= ~IObject::Clean; if (konst) // ...and constness base.switches |= IObject::Const; if (managed) // ...and managed base.switches |= IObject::Managed; // add it to this dictionary, inform it of being added to a container dictionary[name] = child; base.AddedToContainer(*this); }
void Registry::Mark(Object root) { // now mark everything that is reachable from the given object root if (root.Exists()) MarkAll(root.GetStorageBase(), true); }