From a15d5fa21382edd367203bf04456887b07b6445a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Tue, 9 May 2023 18:22:33 +0200 Subject: [PATCH 1/2] script_interface: Rewrite ObjectList as AutoParameters --- src/python/espressomd/script_interface.pyx | 27 -------- src/script_interface/ObjectContainer.hpp | 42 ++++++++++++ src/script_interface/ObjectList.hpp | 65 ++++++++----------- .../tests/serialization_mpi_guard_test.cpp | 21 +++--- testsuite/python/save_checkpoint.py | 5 +- testsuite/python/test_checkpoint.py | 49 +++++++++----- 6 files changed, 111 insertions(+), 98 deletions(-) create mode 100644 src/script_interface/ObjectContainer.hpp diff --git a/src/python/espressomd/script_interface.pyx b/src/python/espressomd/script_interface.pyx index 940c1f3e2cb..458d5eb1e61 100644 --- a/src/python/espressomd/script_interface.pyx +++ b/src/python/espressomd/script_interface.pyx @@ -457,15 +457,6 @@ class ScriptObjectList(ScriptInterfaceHelper): """ - def __init__(self, *args, **kwargs): - if args: - params, (_unpickle_so_class, (_so_name, bytestring)) = args - assert _so_name == self._so_name - self = _unpickle_so_class(_so_name, bytestring) - self.__setstate__(params) - else: - super().__init__(**kwargs) - def __getitem__(self, key): return self.call_method("get_elements")[key] @@ -477,24 +468,6 @@ class ScriptObjectList(ScriptInterfaceHelper): def __len__(self): return self.call_method("size") - @classmethod - def _restore_object(cls, so_callback, so_callback_args, state): - so = so_callback(*so_callback_args) - so.__setstate__(state) - return so - - def __reduce__(self): - so_callback, (so_name, so_bytestring) = super().__reduce__() - return (ScriptObjectList._restore_object, - (so_callback, (so_name, so_bytestring), self.__getstate__())) - - def __getstate__(self): - return self.call_method("get_elements") - - def __setstate__(self, object_list): - for item in object_list: - self.add(item) - class ScriptObjectMap(ScriptInterfaceHelper): """ diff --git a/src/script_interface/ObjectContainer.hpp b/src/script_interface/ObjectContainer.hpp new file mode 100644 index 00000000000..f5a8e89e2da --- /dev/null +++ b/src/script_interface/ObjectContainer.hpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2023 The ESPResSo project + * + * This file is part of ESPResSo. + * + * ESPResSo is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ESPResSo is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef SCRIPT_INTERFACE_OBJECT_CONTAINER_HPP +#define SCRIPT_INTERFACE_OBJECT_CONTAINER_HPP + +#include "script_interface/auto_parameters/AutoParameters.hpp" + +#include + +namespace ScriptInterface { + +/** + * @brief Base class for containers whose @c BaseType might be a full + * specialization of @ref AutoParameters. + */ +template