-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathwrapped_container_test.pxd
More file actions
144 lines (121 loc) · 6.25 KB
/
Copy pathwrapped_container_test.pxd
File metadata and controls
144 lines (121 loc) · 6.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# cython: language_level=3
from libcpp.string cimport string as libcpp_string
from libcpp.vector cimport vector as libcpp_vector
from libcpp.map cimport map as libcpp_map
from libcpp.unordered_map cimport unordered_map as libcpp_unordered_map
from libcpp.set cimport set as libcpp_set
from libcpp.unordered_set cimport unordered_set as libcpp_unordered_set
from libcpp.list cimport list as libcpp_list
from libcpp.deque cimport deque as libcpp_deque
from libcpp.pair cimport pair as libcpp_pair
from libcpp cimport bool
cdef extern from "wrapped_container_test.hpp":
# A simple wrapped class used in containers
# wrap-hash and operator== enable Python dict/set lookups with d[item]
cdef cppclass Item:
# wrap-hash:
# getHashValue()
int value_
libcpp_string name_
Item()
Item(int v)
Item(int v, libcpp_string n)
Item(Item&)
bool operator==(Item)
bool operator!=(Item)
int getValue()
void setValue(int v)
libcpp_string getName()
size_t getHashValue()
# Test class with methods that use containers of wrapped classes
cdef cppclass WrappedContainerTest:
WrappedContainerTest()
# ========================================
# VECTOR OF WRAPPED CLASS (by value)
# These are supported - similar to libcpp_test.pxd process25
# ========================================
int sumVectorItems(libcpp_vector[Item]& items)
libcpp_vector[Item] createVectorItems(int count)
void appendToVector(libcpp_vector[Item]& items, int value)
# ========================================
# SET OF WRAPPED CLASS (by value)
# Supported - similar to libcpp_test.pxd process11
# ========================================
int sumSetItems(libcpp_set[Item]& items)
libcpp_set[Item] createSetItems(int count)
# ========================================
# MAP WITH WRAPPED CLASS AS VALUE
# Supported - similar to libcpp_test.pxd process15, process19
# ========================================
int sumMapValues(libcpp_map[int, Item]& m)
libcpp_map[int, Item] createMapIntToItem(int count)
int lookupMapIntToItem(libcpp_map[int, Item]& m, int key)
bool hasKeyMapIntToItem(libcpp_map[int, Item]& m, int key)
# ========================================
# MAP WITH WRAPPED CLASS AS KEY
# Supported - similar to libcpp_stl_test.pxd process_7_map
# ========================================
int sumMapKeys(libcpp_map[Item, int]& m)
libcpp_map[Item, int] createMapItemToInt(int count)
# ========================================
# NESTED CONTAINERS: vector<vector<Item>>
# Input supported, output needs manual handling
# ========================================
int sumNestedVector(libcpp_vector[libcpp_vector[Item]]& nested)
void appendToNestedVector(libcpp_vector[libcpp_vector[Item]]& nested)
# ========================================
# MAP WITH WRAPPED KEY AND VECTOR VALUE (primitives only)
# Supported - similar to libcpp_stl_test.pxd process_13_map
# ========================================
int sumMapItemToVecInt(libcpp_map[Item, libcpp_vector[int]]& m)
# ========================================
# MAP WITH WRAPPED CLASS AS BOTH KEY AND VALUE
# ========================================
int sumMapBoth(libcpp_map[Item, Item]& m)
libcpp_map[Item, Item] createMapItemToItem(int count)
# ========================================
# UNORDERED_MAP WITH WRAPPED CLASS AS KEY
# ========================================
int sumUnorderedMapKeys(libcpp_unordered_map[Item, int]& m)
libcpp_unordered_map[Item, int] createUnorderedMapItemToInt(int count)
# ========================================
# UNORDERED_MAP WITH WRAPPED CLASS AS VALUE
# ========================================
int sumUnorderedMapValues(libcpp_unordered_map[int, Item]& m)
libcpp_unordered_map[int, Item] createUnorderedMapIntToItem(int count)
int lookupUnorderedMapIntToItem(libcpp_unordered_map[int, Item]& m, int key)
bool hasKeyUnorderedMapIntToItem(libcpp_unordered_map[int, Item]& m, int key)
# ========================================
# UNORDERED_MAP WITH WRAPPED CLASS AS BOTH KEY AND VALUE
# ========================================
int sumUnorderedMapBoth(libcpp_unordered_map[Item, Item]& m)
libcpp_unordered_map[Item, Item] createUnorderedMapItemToItem(int count)
# ========================================
# UNORDERED_MAP WITH WRAPPED KEY AND VECTOR VALUE (primitives only)
# ========================================
int sumUnorderedMapItemToVecInt(libcpp_unordered_map[Item, libcpp_vector[int]]& m)
# ========================================
# LIST OF WRAPPED CLASS (by value)
# ========================================
int sumListItems(libcpp_list[Item]& items)
libcpp_list[Item] createListItems(int count)
# ========================================
# DEQUE OF WRAPPED CLASS (by value)
# ========================================
int sumDequeItems(libcpp_deque[Item]& items)
libcpp_deque[Item] createDequeItems(int count)
# ========================================
# UNORDERED_SET OF WRAPPED CLASS (by value)
# ========================================
int sumUnorderedSetItems(libcpp_unordered_set[Item]& items)
libcpp_unordered_set[Item] createUnorderedSetItems(int count)
bool hasItemUnorderedSet(libcpp_unordered_set[Item]& items, Item& item)
int findItemUnorderedSet(libcpp_unordered_set[Item]& items, Item& item)
# ========================================
# NESTED CONTAINERS: list<vector<int>>
# ========================================
int sumListOfVectors(libcpp_list[libcpp_vector[int]]& data)
# ========================================
# NESTED CONTAINERS: deque<vector<int>>
# ========================================
int sumDequeOfVectors(libcpp_deque[libcpp_vector[int]]& data)