Apply clang-format to source tree
[alexxy/gromacs.git] / src / api / cpp / include / gmxapi / status.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2018,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.
8  *
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.
13  *
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.
18  *
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.
23  *
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.
31  *
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.
34  */
35
36 #ifndef GMXAPI_STATUS_H
37 #define GMXAPI_STATUS_H
38 /*! \file
39  * \brief Declare Status class for API operations with no other results.
40  *
41  * \author M. Eric Irrgang <ericirrgang@gmail.com>
42  * \ingroup gmxapi
43  */
44
45 #include <memory>
46
47 namespace gmxapi
48 {
49 /*! \brief Trivial API operation return value.
50  *
51  * Returned by some API operations when a richer return value type does not
52  * exist.
53  *
54  * \cond internal
55  * In general, API operations should return an object and not to allow
56  * unsuccessful operations to go undetected. In some cases, there is either no
57  * obvious result object or the API needs a placeholder for a more elaborate
58  * result to be implemented in a future version. This class allows a return
59  * value and potential proxy object as a fall-back where no other option exists.
60  * \endcond
61  *
62  * \ingroup gmxapi
63  */
64 class Status final
65 {
66 public:
67     /*!
68      * \brief Status is "unsuccessful" until set otherwise.
69      *
70      * \internal
71      * Default constructor can be used for convenience when preparing the
72      * return value for an operation that should be assumed unsuccessful
73      * until proven otherwise.
74      */
75     Status();
76     /*!
77      * \brief Can be copy-initialized
78      *
79      * \param status
80      */
81     Status(const Status& status);
82     /*!
83      * \brief Can be moved.
84      */
85     Status(Status&& /*unused*/) noexcept;
86     /*!
87      * \brief Can be copy-assigned.
88      *
89      * \param status
90      * \return reference to lhs.
91      */
92     Status& operator=(const Status& status);
93     /*!
94      * \brief Transfer ownership by move assignment.
95      *
96      * \param status
97      * \return reference to lhs
98      */
99     Status& operator=(Status&& status) noexcept;
100     /*!
101      * \brief Set success status from boolean.
102      *
103      * \param success true to indicate successful operation.
104      * \return reference to lhs
105      */
106     Status& operator=(bool success);
107
108     /*!
109      * \brief Initialize with success set true or false.
110      *
111      * \param success
112      */
113     explicit Status(bool success);
114
115     /*!
116      * \brief Clean up resources.
117      *
118      * Note non-virtual destructor. This class is not heritable.
119      */
120     ~Status();
121
122     /*!
123      * \brief Check success status.
124      *
125      * Forces evaluation of any pending computation. The operation that
126      * returned the Status object is guaranteed to complete, successfully
127      * or unsuccessfully, before this function returns.
128      *
129      * \return true if the operation described was successful.
130      *
131      * \internal
132      * Unsuccessful operations should have more useful information associated
133      * than just a boolean. Future versions should behave more like a
134      * `gmx::future<gmx::expected<T>>`, but this functionality is not yet
135      * available.
136      */
137     bool success() const;
138
139 private:
140     //! \cond
141     class Impl;
142     std::unique_ptr<Impl> impl_;
143     //! \endcond
144 };
145
146 } // end namespace gmxapi
147
148 #endif // GMXAPI_STATUS_H