11# Copyright (c) 2023-2024 Paulo Meira
22# Copyright (c) 2023-2024 DSS-Extensions contributors
3- from typing import Union , Iterator
3+ from typing import Union , Iterator , List
44from dss .enums import DSSJSONFlags
55from .types import Float64Array , Int32Array , ComplexArray
66from .common import Base , InvalidatedBus
@@ -417,17 +417,29 @@ def to_json(self, options: Union[int, DSSJSONFlags] = 0):
417417
418418
419419class BusBatch (Base ):
420+ def _unpack (self ):
421+ ptr , cnt = self ._get_ptr_cnt ()
422+ if cnt == 0 :
423+ return []
424+
425+ return self ._api_util .ffi .unpack (ptr , cnt )
426+
420427 def ZSCRefresh (self ) -> bool :
421428 '''
422429 Refreshes the Zsc matrix for all buses in the batch
423430 '''
424- ptrList , cnt = self ._get_ptr_cnt ()
425431 res = True
426- for n in range ( cnt ):
427- res = res and (self ._lib .Alt_Bus_ZscRefresh (ptrList [ n ] ) != 0 )
432+ for ptr in self . _unpack ( ):
433+ res = res and (self ._lib .Alt_Bus_ZscRefresh (ptr ) != 0 )
428434
429435 return res
430436
437+ def Name (self ) -> List [str ]:
438+ '''
439+ Array of strings containing names of all buses in circuit.
440+ '''
441+ return [self ._get_string (self ._lib .Alt_Bus_Get_Name (ptr )) for ptr in self ._unpack ()]
442+
431443 def _busbatch_float64 (self , fname : str ):
432444 return self ._get_float64_array (
433445 self ._lib .Alt_BusBatch_GetFloat64FromFunc ,
@@ -515,9 +527,8 @@ def __len__(self) -> int:
515527 return self ._cnt
516528
517529 def __iter__ (self ) -> Iterator [Bus ]:
518- ptrList , cnt = self ._get_ptr_cnt ()
519- for n in range (cnt ):
520- yield Bus (self ._api_util , ptrList [n ])
530+ for ptr in self ._unpack ():
531+ yield Bus (self ._api_util , ptr )
521532
522533 def to_json (self , options : Union [int , DSSJSONFlags ] = 0 ):
523534 '''
@@ -560,3 +571,8 @@ def find(self, index_or_name: Union[int, str]) -> Bus:
560571 '''
561572 return self [index_or_name ]
562573
574+ def Name (self ) -> List [str ]:
575+ '''
576+ Array of strings containing names of all buses in circuit.
577+ '''
578+ return self ._check_for_error (self ._get_string_array (self ._lib .Circuit_Get_AllBusNames ))
0 commit comments