def raise_error_if_necessary(*args, **kwargs): failed = func(*args, **kwargs) if failed is None: err = _pyom.get_last_error() _pyom.clear_last_error() raise OmexMetaException(err) if isinstance(failed, int): if failed < 0: err = _pyom.get_last_error() _pyom.clear_last_error() raise OmexMetaException(err) return failed
def propagate_omexmeta_error(func): """ If @param func is a callable then this function behaves like a decorator, checking the return type for a omexmeta error. This is used in simpler functions (of which there are many) that only call a omexmeta method. If @param func is not callable, then we check to see whether func is nullptr or < 0, indicative of a omexmeta error. This is used in more complicated situations Args: func: callable or value. Returns: a func of @param is callable or the original value if not. todo split into two functions (voilation of SRP). - check_for_error_value - check_for_error_return (for decorator) """ if callable(func): def raise_error_if_necessary(*args, **kwargs): failed = func(*args, **kwargs) if failed is None: err = _pyom.get_last_error() _pyom.clear_last_error() raise OmexMetaException(err) if isinstance(failed, int): if failed < 0: err = _pyom.get_last_error() _pyom.clear_last_error() raise OmexMetaException(err) return failed return raise_error_if_necessary else: value = func if value is None: err = _pyom.get_last_error() _pyom.clear_last_error() raise OmexMetaException(err) if isinstance(func, int): if func < 0: err = _pyom.get_last_error() _pyom.clear_last_error() raise OmexMetaException(err) return func
def new_energy_diff(self) -> EnergyDiff: obj = _pyom.editor_new_energy_diff(self._obj) if obj is None: raise OmexMetaException(_pyom.get_last_error()) energy_diff = EnergyDiff(obj) try: yield energy_diff finally: self.add_energy_diff(energy_diff)
def new_physical_process(self) -> PhysicalProcess: obj = _pyom.editor_new_physical_process(self._obj) if obj is None: raise OmexMetaException(_pyom.get_last_error()) physical_process = PhysicalProcess(obj) try: yield physical_process finally: self.add_physical_process(physical_process)
def new_physical_entity(self) -> PhysicalEntity: obj = _pyom.editor_new_physical_entity(self._obj) if obj is None: raise OmexMetaException(_pyom.get_last_error()) physical_entity = PhysicalEntity(obj) try: yield physical_entity finally: self.add_physical_entity(physical_entity)
def new_personal_information(self) -> SingularAnnotation: obj = _pyom.editor_new_personal_information(self._obj) if obj is None: raise OmexMetaException(_pyom.get_last_error()) information = PersonalInformation(obj) try: yield information finally: self.add_personal_information(information)
def new_singular_annotation(self) -> SingularAnnotation: obj = _pyom.editor_new_singular_annotation(self._obj) if obj is None: raise OmexMetaException(_pyom.get_last_error()) singular_annotation = SingularAnnotation(obj) try: yield singular_annotation finally: self.add_singular_annotation(singular_annotation)
def new_physical_property(self) -> PhysicalProperty: obj = _pyom.editor_new_physical_property(self._obj) if obj is None: raise OmexMetaException(_pyom.get_last_error()) return PhysicalProperty(obj)