Skip to content

Commit

Permalink
add has methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sunethwarna authored Jul 28, 2024
1 parent c1c64c7 commit 7e92d64
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ def SetDataBuffer(self, buffer_size: int):
if buffered_data.GetBufferSize() < buffer_size:
raise RuntimeError(f"The required buffer size is not satisfied with the existing problem data container. [ component data container buffer size = {buffered_data.GetBufferSize()}, required buffer size = {buffer_size}, component = {self.__component_name}, component type = {self.__component_type}")

def HasDataBuffer(self) -> bool:
return self.__problem_data.HasValue(self.__buffered_data_name)

def GetComponent(self) -> Any:
return self.__component

def GetBufferedData(self) -> BufferedDict:
if not self.__problem_data.HasValue(self.__buffered_data_name):
raise RuntimeError(f"Buffered data is not set by calling ComponentData::SetBuffer for component of type \"{self.__component_type}\" with component name \"{self.__component_name}\".")
if not self.HasDataBuffer():
raise RuntimeError(f"Buffered data is not set by calling ComponentData::SetDataBuffer for component of type \"{self.__component_type}\" with component name \"{self.__component_name}\".")

return self.__problem_data[self.__buffered_data_name]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ def GetResponse(self, name: str) -> ResponseFunction:
def GetListOfResponses(self) -> 'list[ResponseFunction]':
return self.__components[ResponseFunction].values()

def HasResponse(self, name_or_response: 'Union[str, ResponseFunction]') -> bool:
if isinstance(name_or_response, str):
return name_or_response in [response_function.GetName() for response_function in self.GetListOfResponses()]
elif isinstance(name_or_response, ResponseFunction):
return name_or_response in self.GetListOfResponses()
else:
raise RuntimeError(f"Unsupported type provided for name_or_response. Only allowed to have string or ResponseFunction types.")

def RemoveResponse(self, name: str) -> None:
self.RemoveComponent(name, ResponseFunction)

Expand All @@ -89,6 +97,14 @@ def GetExecutionPolicy(self, name: str) -> ExecutionPolicy:
def GetListOfExecutionPolicies(self) -> 'list[ExecutionPolicy]':
return self.__components[ExecutionPolicy].values()

def HasExecutionPolicy(self, name_or_execution_policy: 'Union[str, ExecutionPolicy]') -> bool:
if isinstance(name_or_execution_policy, str):
return name_or_execution_policy in [execution_policy.GetName() for execution_policy in self.GetListOfExecutionPolicies()]
elif isinstance(name_or_execution_policy, ExecutionPolicy):
return name_or_execution_policy in self.GetListOfExecutionPolicies()
else:
raise RuntimeError(f"Unsupported type provided for name_or_execution_policy. Only allowed to have string or ExecutionPolicy types.")

def RemoveExecutionPolicy(self, name: str) -> None:
self.RemoveComponent(name, ExecutionPolicy)

Expand All @@ -98,6 +114,14 @@ def GetControl(self, name: str) -> Control:
def GetListOfControls(self) -> 'list[Control]':
return self.__components[Control].values()

def HasControl(self, name_or_control: 'Union[str, Control]') -> bool:
if isinstance(name_or_control, str):
return name_or_control in [control.GetName() for control in self.GetListOfControls()]
elif isinstance(name_or_control, Control):
return name_or_control in self.GetListOfControls()
else:
raise RuntimeError(f"Unsupported type provided for name_or_control. Only allowed to have string or Control types.")

def RemoveControl(self, name: str) -> None:
self.RemoveComponent(name, Control)

Expand Down

0 comments on commit 7e92d64

Please sign in to comment.