Skip to content

Commit 98dc409

Browse files
committed
APP: allow retrieval of Register by name from dictionary
1 parent e0a9f73 commit 98dc409

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

chb/app/BDictionary.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import chb.util.IndexedTable as IT
4747
import chb.util.StringIndexedTable as SI
4848

49-
from typing import Callable, List, Tuple, TYPE_CHECKING
49+
from typing import Callable, List, Optional, Tuple, TYPE_CHECKING
5050

5151
if TYPE_CHECKING:
5252
from chb.app.AppAccess import AppAccess
@@ -125,6 +125,21 @@ def register(self, ix: int) -> Register:
125125
return bdregistry.mk_instance(
126126
self, self.register_table.retrieve(ix), Register)
127127

128+
def register_index_by_name(self, name: str) -> Optional[int]:
129+
ixvalues = self.register_table.values()
130+
for ixvalue in ixvalues:
131+
if len(ixvalue.tags) >= 2:
132+
if ixvalue.tags[1] == name:
133+
return ixvalue.index
134+
return None
135+
136+
def register_by_name(self, name: str) -> Optional[Register]:
137+
ix = self.register_index_by_name(name)
138+
if ix is not None:
139+
return self.register(ix)
140+
else:
141+
return None
142+
128143
# ----------------------- xml accessors ------------------------------------
129144

130145
def read_xml_string(self, n: ET.Element) -> str:

0 commit comments

Comments
 (0)