mirror of
https://github.com/boostorg/python.git
synced 2026-01-22 05:22:45 +00:00
added ExtensionClass<...>::declare_base(...) which
- declares a wrapped C++ class to be a base class of another wrapped class - enables conversions between those classes - ensures that base class methods are inherited by the subclass [SVN r7971]
This commit is contained in:
37
extclass.cpp
37
extclass.cpp
@@ -157,7 +157,7 @@ void report_missing_instance_data(
|
||||
}
|
||||
else
|
||||
{
|
||||
two_string_error(PyExc_TypeError, "extension class '%.*s' is not derived from '%.*s'.",
|
||||
two_string_error(PyExc_TypeError, "extension class '%.*s' is not convertible into '%.*s'.",
|
||||
instance->ob_type->tp_name, target_class->tp_name);
|
||||
}
|
||||
}
|
||||
@@ -218,6 +218,41 @@ ExtensionClassBase::ExtensionClassBase(const char* name)
|
||||
{
|
||||
}
|
||||
|
||||
void * ExtensionClassBase::try_class_conversions(InstanceHolderBase * object) const
|
||||
{
|
||||
void * result = try_sub_class_conversions(object);
|
||||
if(result) return result;
|
||||
result = try_super_class_conversions(object);
|
||||
return result;
|
||||
}
|
||||
|
||||
void * ExtensionClassBase::try_super_class_conversions(InstanceHolderBase * object) const
|
||||
{
|
||||
void * result = 0;
|
||||
for(int i=0; i<base_classes().size(); ++i)
|
||||
{
|
||||
if(base_classes()[i].second == 0) continue;
|
||||
result = base_classes()[i].first->convert_from_holder(object);
|
||||
if(result) return (*base_classes()[i].second)(result);
|
||||
result = base_classes()[i].first->try_super_class_conversions(object);
|
||||
if(result) return (*base_classes()[i].second)(result);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void * ExtensionClassBase::try_sub_class_conversions(InstanceHolderBase * object) const
|
||||
{
|
||||
void * result = 0;
|
||||
for(int i=0; i<sub_classes().size(); ++i)
|
||||
{
|
||||
result = sub_classes()[i].first->convert_from_holder(object);
|
||||
if(result) return (*sub_classes()[i].second)(result);
|
||||
result = sub_classes()[i].first->try_sub_class_conversions(object);
|
||||
if(result) return (*sub_classes()[i].second)(result);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ExtensionClassBase::add_method(Function* method, const char* name)
|
||||
{
|
||||
add_method(PyPtr<Function>(method), name);
|
||||
|
||||
Reference in New Issue
Block a user