Implement support for enum reference parameters

This commit is contained in:
Gustavo J. A. M. Carneiro committed 2009-05-28 12:12:12 +01:00
1 parent 2476cba49c
commit f3f4e7df9c
5 files changed
+29

No files matched your search

+15
View File
@@ -75,15 +75,26 @@ class Enum(object):
full_type_name = self.full_name
def __init__(self, ctype, name, *args, **kwargs):
super(ThisEnumParameter, self).__init__(self.full_type_name, name, *args, **kwargs)
class ThisEnumReturn(inttype.IntReturn):
CTYPES = []
full_type_name = self.full_name
def __init__(self, ctype, *args, **kwargs):
super(ThisEnumReturn, self).__init__(self.full_type_name, *args, **kwargs)
class ThisEnumRefParameter(inttype.IntRefParam):
CTYPES = []
full_type_name = self.full_name + " &"
def __init__(self, ctype, name, *args, **kwargs):
super(ThisEnumRefParameter, self).__init__(self.full_type_name, name, *args, **kwargs)
self.ThisEnumParameter = ThisEnumParameter
self.ThisEnumReturn = ThisEnumReturn
self.ThisEnumRefParameter = ThisEnumRefParameter
param_type_matcher.register(self.full_name, self.ThisEnumParameter)
return_type_matcher.register(self.full_name, self.ThisEnumReturn)
param_type_matcher.register(self.full_name + ' &', self.ThisEnumRefParameter)
if self.name != self.full_name:
try:
@@ -94,6 +105,10 @@ class Enum(object):
return_type_matcher.register(self.name, self.ThisEnumReturn)
except ValueError:
pass
try:
param_type_matcher.register(self.name+' &', self.ThisEnumRefParameter)
except ValueError:
pass
module = property(get_module, set_module)
+7
View File
@@ -216,6 +216,13 @@ namespace xpto
{
g_fooType = type;
}
void set_foo_type_inout (FooType &type)
{
FooType oldfooType = g_fooType;
g_fooType = type;
type = oldfooType;
}
}
+3
View File
@@ -479,6 +479,9 @@ namespace xpto
FooType get_foo_type ();
void set_foo_type (FooType type);
// -#- @type(direction=inout) -#-
void set_foo_type_inout (FooType &type);
typedef Foo FooXpto;
std::string get_foo_datum(FooXpto const &foo);
+2
View File
@@ -263,6 +263,8 @@ int %s::custom_method_added_by_a_hook(int x)
xpto.add_enum('FooType', ['FOO_TYPE_AAA', 'FOO_TYPE_BBB', 'FOO_TYPE_CCC'])
xpto.add_function('get_foo_type', ReturnValue.new('FooType'), [])
xpto.add_function('set_foo_type', ReturnValue.new('void'), [Parameter.new("FooType", 'type')])
xpto.add_function('set_foo_type_inout', ReturnValue.new('void'),
[Parameter.new("FooType&", 'type', direction=Parameter.DIRECTION_INOUT)])
xpto_SomeClass = xpto.add_class('SomeClass', docstring="This is the docstring for SomeClass")
+2
View File
@@ -590,6 +590,8 @@ class TestFoo(unittest.TestCase):
def test_enum(self):
foo.xpto.set_foo_type(foo.xpto.FOO_TYPE_BBB)
self.assertEqual(foo.xpto.get_foo_type(), foo.xpto.FOO_TYPE_BBB)
old = foo.xpto.set_foo_type_inout(foo.xpto.FOO_TYPE_CCC)
self.assertEqual(old, foo.xpto.FOO_TYPE_BBB)
def test_virtual_overload(self):
## first test the plain object