Newer
Older
Import / applications / MakePDF / Framework / Final.h
#ifndef FINAL_H
#define FINAL_H


///
/// Make classes Final/NotInheritable/Sealed
///
/// Making a class 'Final' means preventing it from being inherited from. This is useful if the
/// class is unsafe to inherit from or not intended to be inherited. This has some overhead to
/// enforece this, so a macro is provided which will only enforce this in debug builds, but will
/// produce the more optimal code in release builds
///
/// Idea comes from here:  http://www.codeproject.com/Articles/4444/A-non-inheritable-class
///
template <typename T>
class MakeSealed
{
private:
	~MakeSealed() {};
	friend T;
};


#ifndef _NDEBUG
#  define  FINAL_CLASS(ClassName)		class ClassName : virtual public MakeSealed<ClassName>
#else
#  define  FINAL_CLASS(ClassName)		class ClassName
#endif


/*

	Example usage:

	FINAL_CLASS(MyFinalClass)
	{
		public:
			MyFinalClass() {}
	};

	Now it is not possible to do this without a compiler error when compiling in debug:

	class MyDerivedClass : public MyFinalClass
	{
	};

*/


#endif // FINAL_H