From 81d00c8bd64c4cf96032fbcc4dd714084939d0a0 Mon Sep 17 00:00:00 2001 From: Darren Ranalli Date: Tue, 13 May 2003 22:47:07 +0000 Subject: [PATCH] added PureVirtual --- direct/src/showbase/PythonUtil.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/direct/src/showbase/PythonUtil.py b/direct/src/showbase/PythonUtil.py index 5328b732a6..cc249ae182 100644 --- a/direct/src/showbase/PythonUtil.py +++ b/direct/src/showbase/PythonUtil.py @@ -662,3 +662,15 @@ def lineTag(baseFileName=1, verbose=0, separator=':'): else: return '%s%s%s%s%s' % (fileName, separator, lineNum, separator, funcName) + +class PureVirtual: + """ Python classes that want to have C++-style pure-virtual functions + can derive from this class and call 'derivedMustOverride' from their + 'pure virtual' methods. Such Python classes can still be instantiated, + but they will give an informative error when a pure-virtual method + is invoked. """ + def derivedMustOverride(self): + """ call this function from methods that must be overriden + and are not meant to be chained down to. This simulates C++ + pure-virtual methods. """ + raise 'error: derived class must implement %s' % callerInfo()[2]