Introduce SimulatorBuilder
[gromacs.git] / src / gromacs / coordinateio / outputadaptercontainer.h
blob1029dd093911b9db4120ee0a17cbe10484dcbc4d
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2019, 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.
35 /*! \file
36 * \brief
37 * Declares gmx::OutputAdapterContainer, a storage object for
38 * multiple outputadapters derived from the IOutputadaper interface.
40 * \author Paul Bauer <paul.bauer.q@gmail.com>
41 * \inlibraryapi
42 * \ingroup module_coordinateio
44 #ifndef GMX_COORDINATEIO_OUTPUTADAPTERCONTAINER_H
45 #define GMX_COORDINATEIO_OUTPUTADAPTERCONTAINER_H
47 #include <memory>
48 #include <vector>
50 #include "gromacs/coordinateio/ioutputadapter.h"
51 #include "gromacs/utility/arrayref.h"
52 #include "gromacs/utility/classhelpers.h"
53 #include "gromacs/utility/enumerationhelpers.h"
55 namespace gmx
58 /*! \libinternal \brief
59 * Storage for output adapters that modify the state of a t_trxframe object.
61 * The OutputAdapterContainer is responsible for storing the number of
62 * OutputAdapters, as well as the bitmask representing the current requirements
63 * for constructing an CoordinateFile object with the modules registered. It is responsible
64 * for ensuring that no module can be registered multiple times, and that the
65 * correct order for some modifications is observed (e.g. we can not reduce the
66 * number of coordinates written to a file before we have set all the other flags).
67 * Any other behaviour indicates a programming error and triggers an assertion.
69 * The abilities that need to be cross checked for the container are usually constrained
70 * by the file format the coordinate data will be written to. When declaring new abilities,
71 * these must match the file type for the output.
73 * \todo Keeping track of those abilities has to be the responsibility of an object
74 * implementing and interface that declares it capabilities and will execute the
75 * the function of writing to a file.
76 * \todo This could be changed to instead construct the container with a pointer to an
77 * ICoordinateOutputWriter that can be passed to the IOutputAdapter modules to check
78 * their cross-dependencies.
80 class OutputAdapterContainer
82 public:
83 //! Only allow constructing the container with defined output abilities.
84 explicit OutputAdapterContainer(unsigned long abilities)
85 : abilities_(abilities)
87 //! Allow abilities to be also defined using the enum class.
88 explicit OutputAdapterContainer(CoordinateFileFlags abilities)
89 : abilities_(convertFlag(abilities))
92 /*! \brief
93 * Add an adapter of a type not previously added.
95 * Only one adapter of each type can be registered, and the order of adapters
96 * is predefined in the underlying storage object.
97 * Calls internal checks to make sure that the new adapter does not violate
98 * any of the preconditions set to make an CoordinateFile object containing
99 * the registered modules.
101 * \param[in] adapter unique_ptr to adapter, with container taking ownership here.
102 * \param[in] type What kind of adapter is being added.
103 * \throws InternalError When registering an adapter of a type already registered .
104 * \throws InconsistentInputError When incompatible modules are added.
106 void addAdapter(OutputAdapterPointer adapter,
107 CoordinateFileFlags type);
109 //! Get vector of all registered adapters.
110 ArrayRef<const OutputAdapterPointer> getAdapters() { return outputAdapters_; }
111 //! Get info if we have any registered adapters.
112 bool isEmpty() const;
114 private:
115 //! Array of registered modules.
116 EnumerationArray<CoordinateFileFlags, OutputAdapterPointer> outputAdapters_;
117 //! Construction time bitmask declaring what the OutputManager can do.
118 unsigned long abilities_ = convertFlag(CoordinateFileFlags::Base);
121 } // namespace gmx
123 #endif