From 24a6db6cd912cd8618fd003fbccec81f4a343f2d Mon Sep 17 00:00:00 2001 From: Mesalu Date: Sat, 6 Jan 2018 11:36:39 -0800 Subject: [PATCH] Add similar tactics to wxArray (and variants) According to RobinD42, use cases in wxPython should be limited to Arrays that are full (no gaps) --- etgtools/tweaker_tools.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/etgtools/tweaker_tools.py b/etgtools/tweaker_tools.py index 7f57c340..55aed97b 100644 --- a/etgtools/tweaker_tools.py +++ b/etgtools/tweaker_tools.py @@ -1004,9 +1004,12 @@ def wxArrayWrapperTemplate(ArrayClass, ItemClass, module, itemIsPtr=False, getIt if not getItemCopy: getitemMeth = '''\ - {ItemClass}{itemRef} __getitem__(ulong index); + {ItemClass}{itemRef} __getitem__(long index); %MethodCode - if (index < sipCpp->GetCount()) {{ + if (0 > index) + index += sipCpp->GetCount(); + + if ((index < sipCpp->GetCount()) && (0 <= index)) {{ sipRes = {addrOf}sipCpp->Item(index); }} else {{ @@ -1017,9 +1020,11 @@ def wxArrayWrapperTemplate(ArrayClass, ItemClass, module, itemIsPtr=False, getIt '''.format(**locals()) else: getitemMeth = '''\ - {ItemClass}* __getitem__(ulong index) /Factory/; + {ItemClass}* __getitem__(long index) /Factory/; %MethodCode - if (index < sipCpp->GetCount()) {{ + if (0 > index) + index += sipCpp->GetCount(); + if ((index < sipCpp->GetCount()) && (0 <= index)) {{ sipRes = new {ItemClass}(sipCpp->Item(index)); }} else {{ @@ -1093,9 +1098,12 @@ public: sipRes = sipCpp->GetCount(); %End - {ItemClass}* __getitem__(ulong index); + {ItemClass}* __getitem__(long index); %MethodCode - if (index < sipCpp->GetCount()) {{ + if (0 > index) + index += sipCpp->GetCount(); + + if ((index < sipCpp->GetCount()) && (0 <= index)) {{ sipRes = sipCpp->Item(index); }} else {{