Move gmxapicompat TPR tools to libgmxapi.
[gromacs.git] / src / api / cpp / include / gmxapi / compat / exceptions.h
blob8b7489926fab2004d13f977e87fbe3ab0420492d
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 C++ exceptions for the gmxapi compatibility tools.
38 * Used internally for the gmxapi compatibility helpers that manage type
39 * mappings of older GROMACS structures. The long-term disposition of this
40 * code is uncertain, but the headers are not likely to be public. If they
41 * do persist in some form, we can integrate the exception hierarchy into
42 * whatever module takes ownership of this code.
44 * Exceptions defined here should only be caught by code that understands the
45 * implementation details of these compatibility tools. Exposure of these
46 * exceptions outside of the installed object files should be treated as a bug.
48 * \author M. Eric Irrgang <ericirrgang@gmail.com>
49 * \ingroup gmxapi_compat
52 #ifndef GMXAPICOMPAT_EXCEPTIONS_H
53 #define GMXAPICOMPAT_EXCEPTIONS_H
55 #include <exception>
56 #include <string>
58 namespace gmxapicompat
61 /*!
62 * \brief Generic exception class for gmxapicompat.
64 class Exception : public std::exception
66 public:
67 using std::exception::exception;
69 explicit Exception(const std::string &message) :
70 message_ {message}
72 explicit Exception(const char* message) : Exception(std::string(message)) {}
74 const char *what() const noexcept override
76 return message_.c_str();
79 private:
80 std::string message_;
83 /*!
84 * \brief The key name provided for a key-value mapping is invalid.
86 class KeyError : public Exception
88 using Exception::Exception;
91 /*!
92 * \brief The value provided for a key-value mapping is invalid.
94 class ValueError : public Exception
96 using Exception::Exception;
99 /*!
100 * \brief Value provided for a key-value mapping is of an incompatible type.
102 class TypeError : public Exception
104 using Exception::Exception;
107 } // end namespace gmxapicompat
108 #endif //GMXAPICOMPAT_EXCEPTIONS_H