From 347bde31a42d420aa2a948fc1e33f0a022c83212 Mon Sep 17 00:00:00 2001 From: Simon Birkholz Date: Mon, 20 Jan 2025 10:47:59 +0100 Subject: [PATCH] added __copy__ and __deepcopy__ functions to make, clear which objects are allowed to be copied and which not --- cuvis/AcquisitionContext.py | 9 +++++++++ cuvis/Async.py | 18 ++++++++++++++++++ cuvis/Calibration.py | 8 ++++++++ cuvis/Export.py | 9 +++++++++ cuvis/Measurement.py | 7 +++++++ cuvis/ProcessingContext.py | 12 +++++++++++- cuvis/SessionFile.py | 8 ++++++++ cuvis/Viewer.py | 8 ++++++++ cuvis/Worker.py | 8 ++++++++ 9 files changed, 86 insertions(+), 1 deletion(-) diff --git a/cuvis/AcquisitionContext.py b/cuvis/AcquisitionContext.py index a78cf21..4eb6198 100644 --- a/cuvis/AcquisitionContext.py +++ b/cuvis/AcquisitionContext.py @@ -536,6 +536,15 @@ def __del__(self): cuvis_il.cuvis_acq_cont_free(_ptr) self._handle = cuvis_il.p_int_value(_ptr) + def __deepcopy__(self, memo): + '''This functions is not permitted due to the class only keeping a handle, that is managed by the cuvis sdk.''' + raise TypeError('Deep copying is not supported for AcquisitionContext') + + def __copy__(self): + '''This functions is not permitted due to the class only keeping a handle, that is managed by the cuvis sdk.''' + raise TypeError( + 'Shallow copying is not supported for AcquisitionContext') + class Component: """ diff --git a/cuvis/Async.py b/cuvis/Async.py index dd2ed26..0339a97 100644 --- a/cuvis/Async.py +++ b/cuvis/Async.py @@ -66,6 +66,15 @@ def __del__(self): cuvis_il.cuvis_async_capture_free(_ptr) self._handle = cuvis_il.p_int_value(_ptr) + def __deepcopy__(self, memo): + '''This functions is not permitted due to the class only keeping a handle, that is managed by the cuvis sdk.''' + raise TypeError('Deep copying is not supported for AsyncMesu') + + def __copy__(self): + '''This functions is not permitted due to the class only keeping a handle, that is managed by the cuvis sdk.''' + raise TypeError( + 'Shallow copying is not supported for AsyncMesu') + class Async(object): def __init__(self, handle): @@ -111,3 +120,12 @@ def __del__(self): cuvis_il.p_int_assign(_ptr, self._handle) cuvis_il.cuvis_async_call_free(_ptr) self._handle = cuvis_il.p_int_value(_ptr) + + def __deepcopy__(self, memo): + '''This functions is not permitted due to the class only keeping a handle, that is managed by the cuvis sdk.''' + raise TypeError('Deep copying is not supported for Async') + + def __copy__(self): + '''This functions is not permitted due to the class only keeping a handle, that is managed by the cuvis sdk.''' + raise TypeError( + 'Shallow copying is not supported for Async') diff --git a/cuvis/Calibration.py b/cuvis/Calibration.py index 981f4f3..e781ea4 100644 --- a/cuvis/Calibration.py +++ b/cuvis/Calibration.py @@ -60,3 +60,11 @@ def __del__(self): _ptr = cuvis_il.new_p_int() cuvis_il.p_int_assign(_ptr, self._handle) cuvis_il.cuvis_calib_free(_ptr) + + def __deepcopy__(self, memo): + '''This functions is not permitted due to the class only keeping a handle, that is managed by the cuvis sdk.''' + raise TypeError('Deep copying is not supported for Calibration') + + def __copy__(self): + '''This functions is not permitted due to the class only keeping a handle, that is managed by the cuvis sdk.''' + raise TypeError('Shallow copying is not supported for Calibration') diff --git a/cuvis/Export.py b/cuvis/Export.py index 81cc71f..015deb5 100644 --- a/cuvis/Export.py +++ b/cuvis/Export.py @@ -4,6 +4,7 @@ from .Measurement import Measurement from .FileWriteSettings import GeneralExportSettings, EnviExportSettings, TiffExportSettings, ViewExportSettings, SaveArgs + class Exporter(object): def __init__(self): self._handle = None @@ -26,6 +27,14 @@ def flush(self): if cuvis_il.status_ok != cuvis_il.cuvis_exporter_flush(self._handle): raise SDKException() + def __deepcopy__(self, memo): + '''This functions is not permitted due to the class only keeping a handle, that is managed by the cuvis sdk.''' + raise TypeError('Deep copying is not supported for Exporter') + + def __copy__(self): + '''This functions is not permitted due to the class only keeping a handle, that is managed by the cuvis sdk.''' + raise TypeError('Shallow copying is not supported for Exporter') + @property def queue_used(self) -> int: _ptr = cuvis_il.new_p_int() diff --git a/cuvis/Measurement.py b/cuvis/Measurement.py index f0d9fb2..8caccaf 100644 --- a/cuvis/Measurement.py +++ b/cuvis/Measurement.py @@ -237,3 +237,10 @@ def __del__(self): cuvis_il.cuvis_measurement_free(_ptr) self._handle = cuvis_il.p_int_value(_ptr) pass + + def __deepcopy__(self, memo): + return self.deepcopy() + + def __copy__(self, memo): + '''This functions is not permitted due to the class only keeping a handle, that is managed by the cuvis sdk.''' + raise TypeError('Shallow copying is not supported for Measurement') diff --git a/cuvis/ProcessingContext.py b/cuvis/ProcessingContext.py index fbe64e8..c860dce 100644 --- a/cuvis/ProcessingContext.py +++ b/cuvis/ProcessingContext.py @@ -12,6 +12,7 @@ import dataclasses + class ProcessingContext(object): def __init__(self, base: Union[Calibration, SessionFile, Measurement]): self._handle = None @@ -132,4 +133,13 @@ def __del__(self): cuvis_il.p_int_assign(_ptr, self._handle) cuvis_il.cuvis_proc_cont_free(_ptr) self._handle = cuvis_il.p_int_value(_ptr) - pass \ No newline at end of file + pass + + def __deepcopy__(self, memo): + '''This functions is not permitted due to the class only keeping a handle, that is managed by the cuvis sdk.''' + raise TypeError('Deep copying is not supported for ProcessingContext') + + def __copy__(self): + '''This functions is not permitted due to the class only keeping a handle, that is managed by the cuvis sdk.''' + raise TypeError( + 'Shallow copying is not supported for ProcessingContext') diff --git a/cuvis/SessionFile.py b/cuvis/SessionFile.py index d6f7e8f..7cf1e17 100644 --- a/cuvis/SessionFile.py +++ b/cuvis/SessionFile.py @@ -104,3 +104,11 @@ def __del__(self): cuvis_il.p_int_assign(_ptr, self._handle) cuvis_il.cuvis_session_file_free(_ptr) self._handle = cuvis_il.p_int_value(_ptr) + + def __deepcopy__(self, memo): + '''This functions is not permitted due to the class only keeping a handle, that is managed by the cuvis sdk.''' + raise TypeError('Deep copying is not supported for SessionFile') + + def __copy__(self): + '''This functions is not permitted due to the class only keeping a handle, that is managed by the cuvis sdk.''' + raise TypeError('Shallow copying is not supported for SessionFile') diff --git a/cuvis/Viewer.py b/cuvis/Viewer.py index 66d1aa6..5e7c0df 100644 --- a/cuvis/Viewer.py +++ b/cuvis/Viewer.py @@ -67,3 +67,11 @@ def __del__(self): cuvis_il.p_int_assign(_ptr, self._handle) cuvis_il.cuvis_viewer_free(_ptr) self._handle = cuvis_il.p_int_value(_ptr) + + def __deepcopy__(self, memo): + '''This functions is not permitted due to the class only keeping a handle, that is managed by the cuvis sdk.''' + raise TypeError('Deep copying is not supported for Viewer') + + def __copy__(self): + '''This functions is not permitted due to the class only keeping a handle, that is managed by the cuvis sdk.''' + raise TypeError('Shallow copying is not supported for Viewer') diff --git a/cuvis/Worker.py b/cuvis/Worker.py index 34c2f87..28359ac 100644 --- a/cuvis/Worker.py +++ b/cuvis/Worker.py @@ -318,3 +318,11 @@ def __del__(self): cuvis_il.p_int_assign(_ptr, self._handle) cuvis_il.cuvis_worker_free(_ptr) self._handle = cuvis_il.p_int_value(_ptr) + + def __deepcopy__(self, memo): + '''This functions is not permitted due to the class only keeping a handle, that is managed by the cuvis sdk.''' + raise TypeError('Deep copying is not supported for Worker') + + def __copy__(self): + '''This functions is not permitted due to the class only keeping a handle, that is managed by the cuvis sdk.''' + raise TypeError('Shallow copying is not supported for Worker')