2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2020, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 * \brief Public interface for SimulationInput facilities.
38 * \author M. Eric Irrgang <ericirrgang@gmail.com>
39 * \ingroup module_mdrun
43 #ifndef GMX_MDRUN_SIMULATIONINPUTHANDLE_H
44 #define GMX_MDRUN_SIMULATIONINPUTHANDLE_H
51 // Forward declarations for types from other modules that are opaque to the public API.
52 class LegacyMdrunOptions;
55 * \brief Prescription for molecular simulation.
57 * Represent the complete and unique information needed to generate a simulation
58 * trajectory segment. SimulationInput objects are opaque to the public API.
59 * Ownership can be managed with SimulationInputHolder objects. Clients can
60 * acquire owning references to SimulationInput objects (as SimulationInputHolder)
61 * through makeSimulationInput() or from other SimulationInputHolders.
63 * A SimulationInput object represents an immutable source of data, and is safe
64 * to share. A SimulationInput object may have internal state to support
65 * performance optimizations when shared by multiple SimulationInputHolders.
66 * The SimulationInput is guaranteed to live at least as long as any associated
67 * SimulationInputHolders. The API does not specify whether it may persist
68 * longer internally or be reused for later equivalent requests.
70 * \see SimulationInputHandle
71 * \see makeSimulationInput()
74 * SimulationInput has no public interface yet, but we need a forward declaration for the
75 * library symbol. Library interface provided through simulationinput.h
76 * See also https://gitlab.com/gromacs/gromacs/-/issues/3379 for design and development road map.
78 class SimulationInput;
81 * Client software developers do not interact directly with the contents of gmx::detail,
82 * but some declarations and definitions are necessary in the public headers, such as
83 * forward declarations of implementation classes and definitions of custom deleters.
88 * \brief Private implementation class;
90 class SimulationInputHandleImpl;
93 * \brief Explicit deleter details for SimulationInputHolderImpl.
95 * SimulationInputHolderImpl objects are created by the GROMACS library, but
96 * are destroyed when the SimulationInputHolder goes out of scope in the client
97 * code, which may be linked to a different allocator.
98 * We want to make sure that objects are allocated and deallocated with the same
99 * allocator, so we avoid the default deleter in unique_ptrs and compile allocation
100 * and deallocation code in the same translation unit.
102 * Note that this does not solve potential ABI incompatibilities between the
103 * unique_ptr implementations themselves, but we need to consider ABI
104 * compatibility goals and challenges as well as supported use cases and
105 * ownership semantics.
107 struct SimulationInputHandleImplDeleter
110 SimulationInputHandleImplDeleter();
111 SimulationInputHandleImplDeleter(const SimulationInputHandleImplDeleter& deleter) noexcept;
112 SimulationInputHandleImplDeleter(SimulationInputHandleImplDeleter&& deleter) noexcept;
113 SimulationInputHandleImplDeleter& operator=(const SimulationInputHandleImplDeleter& deleter) noexcept;
114 SimulationInputHandleImplDeleter& operator=(SimulationInputHandleImplDeleter&& deleter) noexcept;
115 void operator()(SimulationInputHandleImpl* impl) const;
118 } // end namespace detail
119 /*! \endcond internal */
122 * \brief Owning handle to a SimulationInput object.
124 * SimulationInput objects are logically immutable, so ownership may be shared
125 * by multiple SimulationInputHolders.
127 * Acquire a SimulationInputHolder with makeSimulationInput() and pass to (e.g.)
128 * gmx::MdrunnerBuilder::addInput()
130 * SimulationInput has no public API yet.
131 * \see https://gitlab.com/gromacs/gromacs/-/issues/3379
133 class SimulationInputHandle
136 /*! \cond internal */
137 SimulationInputHandle();
138 ~SimulationInputHandle();
140 SimulationInputHandle(const SimulationInputHandle& source);
141 SimulationInputHandle(SimulationInputHandle&&) noexcept = default;
143 SimulationInputHandle& operator=(const SimulationInputHandle& rhs);
144 SimulationInputHandle& operator=(SimulationInputHandle&&) noexcept = default;
147 * \brief Take ownership of private implementation object to produce a new public holder.
149 explicit SimulationInputHandle(std::unique_ptr<detail::SimulationInputHandleImpl> impl);
153 * \brief Access opaque SimulationInput pointer.
155 * \return Borrowed access to the SimulationInput, if present.
157 [[nodiscard]] SimulationInput* get() const noexcept;
160 * \brief Boolean context returns true if an input is held, else false.
162 operator bool() const;
165 std::unique_ptr<detail::SimulationInputHandleImpl, detail::SimulationInputHandleImplDeleter> impl_;
168 /*! \brief Direct the construction of a SimulationInput.
170 * \warning Creation methods for SimulationInput resources are under rapid development.
171 * Reference https://gitlab.com/gromacs/gromacs/-/issues/3652
173 * \param options library-internal container holding partially processed user input.
175 * \ingroup module_mdrun
178 * This isn't really a public API function until its arguments are obtainable
179 * through the public API.
181 * Design notes: SimulationInput creation will warrant a builder protocol, and
182 * this helper can evolve into a director to apply the contents of LegacyMdrunOptions,
183 * while such an operation is still relevant.
186 * // After preparing a LegacyMdrunOptions and calling handleRestart()...
187 * SimulationInputBuilder builder;
188 * auto simulationInputHandle = makeSimulationInput(options, &builder);
190 * // In addition to MdrunnerBuilder::addFiles(),
191 * mdrunnerBuilder.addInput(simulationInputHandle.get());
194 SimulationInputHandle makeSimulationInput(const LegacyMdrunOptions& options);
196 } // end namespace gmx
198 #endif // GMX_MDRUN_SIMULATIONINPUTHANDLE_H