【Poco】Poco::AutoReleasePool的例子

#include "../tmain.hpp"

namespace
{
	class TestObj
	{
	public:
		TestObj(): _rc(1)
		{
			++_count;
		}

		void duplicate()
		{
			++_rc;
		}

		void release()
		{
			if (--_rc == 0)
				delete this;
		}

		int rc() const
		{
			return _rc;
		}

		static int count()
		{
			return _count;
		}

	protected:
		~TestObj()
		{
			--_count;
		}

	private:
		int _rc;
		static int _count;
	};

	int TestObj::_count = 0;
}

void test_AutoReleasePool()
{
	Poco::AutoReleasePool<TestObj> arp;
	arp.add(new TestObj);
	arp.add(new TestObj);
	arp.add(new TestObj);
	arp.add(new TestObj);
	assert (TestObj::count() == 4);
	arp.release();
	assert (TestObj::count() == 0);
}


你可能感兴趣的:(【Poco】Poco::AutoReleasePool的例子)