BCBvcl4pyAPI 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
from typing import Generic, TypeVar, List, Any, Iterator, Optional
|
|
2
|
+
|
|
3
|
+
T = TypeVar("T")
|
|
4
|
+
|
|
5
|
+
# --------------------------------------------------------
|
|
6
|
+
# TStringList (含簡單 Objects 支援)
|
|
7
|
+
# --------------------------------------------------------
|
|
8
|
+
class TStringList:
|
|
9
|
+
def __init__(self):
|
|
10
|
+
self.items: List[str] = []
|
|
11
|
+
self._objects: List[Any] = []
|
|
12
|
+
|
|
13
|
+
def Add(self, value: str, obj: Any = None) -> int:
|
|
14
|
+
"""回傳新加入項目的索引 (像 BCB 的 Add 回傳 index)"""
|
|
15
|
+
self.items.append(value)
|
|
16
|
+
self._objects.append(obj)
|
|
17
|
+
return len(self.items) - 1
|
|
18
|
+
|
|
19
|
+
def Insert(self, index: int, value: str, obj: Any = None):
|
|
20
|
+
self.items.insert(index, value)
|
|
21
|
+
self._objects.insert(index, obj)
|
|
22
|
+
|
|
23
|
+
def Delete(self, index: int):
|
|
24
|
+
self.items.pop(index)
|
|
25
|
+
self._objects.pop(index)
|
|
26
|
+
|
|
27
|
+
def Clear(self):
|
|
28
|
+
self.items.clear()
|
|
29
|
+
self._objects.clear()
|
|
30
|
+
|
|
31
|
+
def Sort(self):
|
|
32
|
+
# 排序時一併保留 objects 對應關係
|
|
33
|
+
zipped = list(zip(self.items, self._objects))
|
|
34
|
+
zipped.sort(key=lambda pair: pair[0])
|
|
35
|
+
if zipped:
|
|
36
|
+
self.items, self._objects = map(list, zip(*zipped))
|
|
37
|
+
else:
|
|
38
|
+
self.items, self._objects = [], []
|
|
39
|
+
|
|
40
|
+
def IndexOf(self, value: str) -> int:
|
|
41
|
+
try:
|
|
42
|
+
return self.items.index(value)
|
|
43
|
+
except ValueError:
|
|
44
|
+
return -1
|
|
45
|
+
|
|
46
|
+
def Count(self) -> int:
|
|
47
|
+
"""與 BCB 的 Count() 類似"""
|
|
48
|
+
return len(self.items)
|
|
49
|
+
|
|
50
|
+
# Objects 存取(模擬 TStringList.Objects[index])
|
|
51
|
+
def Objects(self, index: int) -> Any:
|
|
52
|
+
return self._objects[index]
|
|
53
|
+
|
|
54
|
+
def SetObject(self, index: int, obj: Any):
|
|
55
|
+
self._objects[index] = obj
|
|
56
|
+
|
|
57
|
+
def __getitem__(self, index: int) -> str:
|
|
58
|
+
return self.items[index]
|
|
59
|
+
|
|
60
|
+
def __setitem__(self, index: int, value: str):
|
|
61
|
+
self.items[index] = value
|
|
62
|
+
|
|
63
|
+
def __len__(self) -> int:
|
|
64
|
+
return len(self.items)
|
|
65
|
+
|
|
66
|
+
def __iter__(self) -> Iterator[str]:
|
|
67
|
+
return iter(self.items)
|
|
68
|
+
|
|
69
|
+
def __repr__(self):
|
|
70
|
+
return f"TStringList({self.items})"
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
# --------------------------------------------------------
|
|
74
|
+
# TList<T>
|
|
75
|
+
# --------------------------------------------------------
|
|
76
|
+
class TList(Generic[T]):
|
|
77
|
+
def __init__(self):
|
|
78
|
+
self.items: List[T] = []
|
|
79
|
+
|
|
80
|
+
def Add(self, value: T) -> int:
|
|
81
|
+
self.items.append(value)
|
|
82
|
+
return len(self.items) - 1
|
|
83
|
+
|
|
84
|
+
def Delete(self, index: int):
|
|
85
|
+
self.items.pop(index)
|
|
86
|
+
|
|
87
|
+
def Clear(self):
|
|
88
|
+
self.items.clear()
|
|
89
|
+
|
|
90
|
+
def Count(self) -> int:
|
|
91
|
+
return len(self.items)
|
|
92
|
+
|
|
93
|
+
def __getitem__(self, index: int) -> T:
|
|
94
|
+
return self.items[index]
|
|
95
|
+
|
|
96
|
+
def __setitem__(self, index: int, value: T):
|
|
97
|
+
self.items[index] = value
|
|
98
|
+
|
|
99
|
+
def __len__(self) -> int:
|
|
100
|
+
return len(self.items)
|
|
101
|
+
|
|
102
|
+
def __iter__(self) -> Iterator[T]:
|
|
103
|
+
return iter(self.items)
|
|
104
|
+
|
|
105
|
+
def __repr__(self):
|
|
106
|
+
return f"TList({self.items})"
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
# --------------------------------------------------------
|
|
110
|
+
# DynamicArray<T>
|
|
111
|
+
# --------------------------------------------------------
|
|
112
|
+
class DynamicArray(Generic[T]):
|
|
113
|
+
def __init__(self, initial: Optional[List[T]] = None):
|
|
114
|
+
self.items: List[T] = list(initial) if initial is not None else []
|
|
115
|
+
|
|
116
|
+
def Add(self, value: T) -> int:
|
|
117
|
+
self.items.append(value)
|
|
118
|
+
return len(self.items) - 1
|
|
119
|
+
|
|
120
|
+
def Resize(self, new_size: int, default: Optional[T] = None):
|
|
121
|
+
if new_size < len(self.items):
|
|
122
|
+
# truncate
|
|
123
|
+
self.items = self.items[:new_size]
|
|
124
|
+
else:
|
|
125
|
+
# extend with default
|
|
126
|
+
self.items.extend([default] * (new_size - len(self.items)))
|
|
127
|
+
|
|
128
|
+
def Length(self) -> int:
|
|
129
|
+
return len(self.items)
|
|
130
|
+
|
|
131
|
+
def __getitem__(self, index: int) -> T:
|
|
132
|
+
return self.items[index]
|
|
133
|
+
|
|
134
|
+
def __setitem__(self, index: int, value: T):
|
|
135
|
+
self.items[index] = value
|
|
136
|
+
|
|
137
|
+
def __len__(self) -> int:
|
|
138
|
+
return len(self.items)
|
|
139
|
+
|
|
140
|
+
def __iter__(self) -> Iterator[T]:
|
|
141
|
+
return iter(self.items)
|
|
142
|
+
|
|
143
|
+
def __repr__(self):
|
|
144
|
+
return f"DynamicArray({self.items})"
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
BCBvcl4pyAPI/BCBvcl4pyAPI.py,sha256=2c1VZERkoSaco8ZxKic5oYuVCNKR2THoKUcSibM7n3U,4204
|
|
2
|
+
bcbvcl4pyapi-0.1.0.dist-info/METADATA,sha256=0fb15kYtP8jVUAF9IVYnd_wTyZ_4qFivRR8yjo13yLU,236
|
|
3
|
+
bcbvcl4pyapi-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
4
|
+
bcbvcl4pyapi-0.1.0.dist-info/top_level.txt,sha256=JN0xPGy0RatXpYJUxK6ee9MER30gl2gd-dk_KFt0EaI,13
|
|
5
|
+
bcbvcl4pyapi-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
BCBvcl4pyAPI
|