当前位置: 首页>>代码示例>>C++>>正文


C++ Registry::New方法代码示例

本文整理汇总了C++中Registry::New方法的典型用法代码示例。如果您正苦于以下问题:C++ Registry::New方法的具体用法?C++ Registry::New怎么用?C++ Registry::New使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Registry的用法示例。


在下文中一共展示了Registry::New方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: TestArray

void TestBinaryStream::TestArray()
{
	Registry R;
	R.AddClass<Array>("Array");
	R.AddClass<int>("int");

	Pointer<Array> A = R.New<Array>();
	A->Append(R.New(0));
	A->Append(R.New(1));
	A->Append(R.New(2));
	A->Append(R.New(3));

	BinaryStream S;
	S.SetRegistry(&R);

	S << A;
	Object Q;
	S >> Q;

	KAI_TEST_FALSE(S.CanRead(1));
	KAI_TEST_EQUIV(Q.GetTypeNumber(), Type::Traits<Array>::Number);
	const Array &B = ConstDeref<Array>(Q);
	KAI_TEST_EQUIV(B.Size(), 4);
	KAI_TEST_EQUIV(ConstDeref<int>(B.At(0)), 0);
	KAI_TEST_EQUIV(ConstDeref<int>(B.At(1)), 1);
	KAI_TEST_EQUIV(ConstDeref<int>(B.At(2)), 2);
	KAI_TEST_EQUIV(ConstDeref<int>(B.At(3)), 3);
}
开发者ID:kalineh,项目名称:KAI,代码行数:28,代码来源:TestBinaryStream.cpp

示例2: TestList

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);
}
开发者ID:kalineh,项目名称:KAI,代码行数:35,代码来源:TestBinaryStream.cpp

示例3: TestObject

void TestBinaryStream::TestObject()
{
	Registry R;
	R.AddClass<int>("int");

	BinaryStream S;
	S.SetRegistry(&R);

	Pointer<int> N = R.New(42);
	S << N;
	Object Q;
	S >> Q;
	KAI_TEST_FALSE(S.CanRead(1));
	KAI_TEST_EQUIV(Q.GetTypeNumber(), Type::Traits<int>::Number);
	KAI_TEST_EQUIV(ConstDeref<int>(Q), 42);

	S.Clear();
	KAI_TEST_TRUE(S.Empty());

	N.Set("child0", R.New(123));
	S << N;
	Object M;
	S >> M;
	KAI_TEST_FALSE(S.CanRead(1));
	KAI_TEST_EQUIV(ConstDeref<int>(M), 42);
	KAI_TEST_TRUE(M.Has("child0"));
	KAI_TEST_EQUIV(ConstDeref<int>(M.Get("child0")), 123);
}
开发者ID:kalineh,项目名称:KAI,代码行数:28,代码来源:TestBinaryStream.cpp

示例4:

TEST_F(TestProperties, TestBuilder)
{
	Registry R;
	R.AddClass<int>();
	R.AddClass<Vector>();

	ClassBuilder<PropTest>(R)
		.Methods
		.Properties
			("num", &PropTest::num)
			("p_num", &PropTest::p_num)
			("object", &PropTest::object)
		;
	Pointer<PropTest> prop_test = R.New<PropTest>();
	ASSERT_TRUE(prop_test);
	ClassBase const *klass = prop_test.GetClass();
	ASSERT_TRUE(klass->HasProperty("num"));
	ASSERT_TRUE(klass->HasProperty("p_num"));
	ASSERT_TRUE(prop_test.Has("num"));
	ASSERT_FALSE(prop_test.Has("p_num"));

	Pointer<int> N1 = R.New(123);
	Pointer<int> N2 = R.New(456);
	Pointer<int> N3 = R.New(789);

	ASSERT_FALSE(N1.HasParent());
	prop_test->p_num = N1;
	ASSERT_TRUE(N1.HasParent());
	ASSERT_TRUE(N1.GetParentHandle() == prop_test.GetHandle());
	
	prop_test.Set("num", N2);
	ASSERT_TRUE(prop_test->num == *N2);
	ASSERT_FALSE(N2.HasParent());
	prop_test.SetValue("num", 666);
	ASSERT_TRUE(prop_test->num == 666);
	ASSERT_FALSE(N2.HasParent());


	ASSERT_TRUE(N1.HasParent());
	ASSERT_FALSE(N3.HasParent());
	prop_test.Set("p_num", N3);
	ASSERT_FALSE(N1.HasParent());
	ASSERT_TRUE(N3.HasParent());
	ASSERT_TRUE(N3.GetParentHandle() == prop_test.GetHandle());

	prop_test.SetValue("p_num", 42);
	EXPECT_EQ(*N3, 42);

	prop_test.SetValue("num", 13);
	EXPECT_EQ(prop_test->num, 13);
}
开发者ID:koden-km,项目名称:ObjectModel,代码行数:51,代码来源:TestProperties.cpp


注:本文中的Registry::New方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。