コード例 #1
0
	void OpenglObjectManager::deleteObject(GLuint &id)
	{
		if(--refCounts[id] == 0)
		{
			if(deleter) deleter(1, &id);
			else deleter2(id);
			refCounts.erase(id);
		}
	}
コード例 #2
0
/*
	bool operator==(const BMessenger &other) const
	bool operator!=(const BMessenger &a, const BMessenger &b)
	bool operator<(const BMessenger &a, const BMessenger &b)
	@case 3			this and other are initialized, different cases:
					- same object => true
					- different objects same target => true
					- looper preferred handler vs. same looper but the looper
					  itself as handler => false
					- looper preferred handler vs. other looper preferred
					  handler => false
					- looper preferred handler vs. other looper specific
					  handler => false
					- local looper vs. remote looper => false
 */
void MessengerComparissonTester::ComparissonTest3()
{
	// messenger1: looper and handler
	BLooper *looper1 = new BLooper;
	looper1->Run();
	LooperQuitter quitter1(looper1);
	BHandler *handler1 = new BHandler;
	HandlerDeleter deleter1(handler1);
	CHK(looper1->Lock());
	looper1->AddHandler(handler1);
	looper1->Unlock();
	BMessenger messenger1(handler1, looper1);
	BMessenger messenger1a(handler1, looper1);
	// messenger2: looper (1)
	BMessenger messenger2(NULL, looper1);
	BMessenger messenger2a(NULL, looper1);
	// messenger3: looper and handler
	BLooper *looper2 = new BLooper;
	looper2->Run();
	LooperQuitter quitter2(looper2);
	BHandler *handler2 = new BHandler;
	HandlerDeleter deleter2(handler2);
	CHK(looper2->Lock());
	looper2->AddHandler(handler2);
	looper2->Unlock();
	BMessenger messenger3(handler2, looper2);
	BMessenger messenger3a(handler2, looper2);
	// messenger4: looper (2)
	BMessenger messenger4(NULL, looper2);
	BMessenger messenger4a(NULL, looper2);
	// remote targets
	RemoteSMTarget remoteTarget1(false);
	RemoteSMTarget remoteTarget2(true);
	BMessenger messenger5(remoteTarget1.Messenger());
	BMessenger messenger5a(remoteTarget1.Messenger());
	BMessenger messenger6(remoteTarget2.Messenger());
	BMessenger messenger6a(remoteTarget2.Messenger());

	// targets -- test data
	struct target {
		BMessenger	&messenger;
		int32		id;			// identifies the target
	} targets[] = {
		{ messenger1,	1 },
		{ messenger1a,	1 },
		{ messenger2,	2 },
		{ messenger2,	2 },
		{ messenger3,	3 },
		{ messenger3a,	3 },
		{ messenger4,	4 },
		{ messenger4a,	4 },
		{ messenger5,	5 },
		{ messenger5a,	5 },
		{ messenger6,	6 },
		{ messenger6a,	6 },
	};
	int32 targetCount = sizeof(targets) / sizeof(target);

	// test
	for (int32 i = 0; i < targetCount; i++) {
		NextSubTest();
		const target &target1 = targets[i];
		const BMessenger &a = target1.messenger;
		for (int32 k = 0; k < targetCount; k++) {
			const target &target2 = targets[k];
			const BMessenger &b = target2.messenger;
			bool areEqual = (target1.id == target2.id);
			CHK((a == b) == areEqual);
			CHK((b == a) == areEqual);
			CHK((a != b) == !areEqual);
			CHK((b != a) == !areEqual);
		}
	}
}