Moved first batch of analysis tool source to C++
[gromacs.git] / src / gromacs / utility.h
blob158328682137cd280997fc8f5b5361f03171b819
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2010,2011,2012,2013,2014,2015, 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 /*! \defgroup module_utility Low-Level Utilities (utility)
36 * \ingroup group_utilitymodules
37 * \brief
38 * Provides low-level utilities for error handling and other tasks.
40 * This module provides various low-level utilities for tasks such as error
41 * handling and string formatting, as well as helper classes and common custom
42 * containers to simplify implementation of other code. Contents of the module
43 * are discussed in more details under the different headings below.
44 * Some of the code in installed headers in the module is intended for use
45 * directly from code outside the \Gromacs library, but a significant portion
46 * is exposed only because other public headers depend on it.
48 * Since this module implements error handling, it should be at the lowest
49 * level: it should not depend on other modules. Any functionality needed by
50 * the error handling code should also be kept in this module.
52 * <H3>Error handling</H3>
54 * Exception classes used in the library are declared in the exceptions.h header
55 * file. Most \Gromacs-specific exceptions derive from gmx::GromacsException.
57 * This header also declares a ::GMX_THROW macro that should be used for
58 * throwing exceptions. ::GMX_THROW_WITH_ERRNO is also provided for reporting
59 * syscall errors, but its use should be mostly limited to within the library.
60 * This header also declares helper functions printFatalErrorMessage(),
61 * formatExceptionMessageToString(), formatExceptionMessageToFile(), and
62 * translateException() for creating standard error messages and translating
63 * exceptions to error return codes. processExceptionAtExit() provides
64 * clean-up code before exiting the program after an exception.
65 * To help in cases where bottom-up conversion to C++ is appropriate, macro
66 * ::GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR is also provided to catch all
67 * exceptions at C++ to C boundary.
69 * Use of error return codes should be avoided in new code except in C wrappers
70 * and similar, but to ease migration (and for these cases where they are
71 * necessary), facilities for handling them are provided by the errorcodes.h
72 * header file.
73 * It provides a set of error codes (the enum \ref gmx::ErrorCode) that should
74 * be used for return codes in functions.
75 * It also provides macros ::GMX_ERROR and ::GMX_ERROR_NORET that should be
76 * used for returning an error code. setFatalErrorHandler() is provided to
77 * alter the behavior of ::GMX_ERROR and ::GMX_ERROR_NORET. The default
78 * handler prints the reason of the error to \c stderr and aborts the
79 * execution.
81 * Header file gmxassert.h is also provided for assertions. It declares macros
82 * ::GMX_ASSERT and ::GMX_RELEASE_ASSERT that should be used for assertions.
84 * \if internal
85 * Internally, functions from errorformat.h are used for all the above cases to
86 * format error messages to \c stderr.
87 * \endif
90 * \if libapi
92 * <H3>Basic file handling and streams</H3>
94 * The header textstream.h declares interfaces for simple text format streams.
95 * Headers filestream.h and stringstream.h provide implementations for these
96 * streams for reading/writing files and for writing to in-memory strings.
98 * The header fileredirector.h provides interfaces for redirecting file input
99 * and/or output to alternative streams, for use in testing, as well as default
100 * implementations for these interfaces that just use the file system.
102 * The header textwriter.h provides gmx::TextWriter for more formatting support
103 * when writing to a text stream. Similarly, textreader.h provides more
104 * formatting support when reading from a text stream.
106 * The header path.h declares helpers for manipulating paths as strings and for
107 * managing directories and files.
108 * The fate of this header depends on what is decided in Redmine issue #950.
110 * \endif
112 * <H3>Implementation helpers</H3>
114 * The header basedefinitions.h contains common definitions and macros used
115 * throughout \Gromacs. It includes fixed-width integer types (`gmx_int64_t`
116 * and friends), `gmx_bool` for C code, some macros for compiler-specific
117 * attributes, and ::GMX_UNUSED_VALUE and ::GMX_IGNORE_RETURN_VALUE for
118 * handling warnings about unused values.
120 * The header classhelpers.h implements a gmx::PrivateImplPointer template for easily
121 * writing classes that use the private implementation idiom. This header also
122 * declares ::GMX_DISALLOW_COPY_AND_ASSIGN and ::GMX_DISALLOW_ASSIGN macros for
123 * class declarations.
125 * The header flags.h implements a gmx::FlagsTemplate template for better type
126 * safety when using bit flag fields.
129 * <H3>Other functionality</H3>
131 * The header init.h declares gmx::init() and gmx::finalize() for initializing
132 * and deinitializing the \Gromacs library.
134 * The header arrayref.h implements a gmx::ConstArrayRef class for exposing a
135 * C array or part of a std::vector (basically, any continuous stretch of
136 * memory) throuh a std::vector-like interface.
138 * The header stringutil.h declares various string utility routines.
140 * \if libapi
142 * The header gmxmpi.h abstracts away the mechanism of including either MPI or
143 * thread-MPI headers depending on compilation options.
144 * Similarly, gmxomp.h removes the need to use conditional compilation for code
145 * that needs to include omp.h for OpenMP functions.
147 * The header gmxregex.h declares gmx::Regex and regexMatch() for basic regular
148 * expression matching using an interface similar to C++11.
150 * The header messagestringcollector.h declares a gmx::MessageStringCollector
151 * class for composing messages with context information.
153 * The header sysinfo.h declares gmx_getpid() for getting the current process
154 * id.
156 * The header programcontext.h declares a gmx::IProgramContext that is
157 * used to
158 * initialize and access information about the running program, such as the
159 * name and path of the executable. This information is used, e.g., by the
160 * error handling code in formatting standard error messages.
162 * The header qsort_threadsafe.h provides a guaranteed threadsafe
163 * implementation for qsort().
165 * The header uniqueptr.h declares gmx::gmx_unique_ptr, which is intended for
166 * declaring smart pointer types with unique ownership.
168 * \endif
170 * \author Teemu Murtola <teemu.murtola@gmail.com>
172 /*! \file
173 * \brief
174 * Public API convenience header for low-level utilities.
176 * \author Teemu Murtola <teemu.murtola@gmail.com>
177 * \inpublicapi
178 * \ingroup module_utility
180 #ifndef GMX_UTILITY_H
181 #define GMX_UTILITY_H
183 #include "gromacs/utility/errorcodes.h"
184 #include "gromacs/utility/exceptions.h"
185 #include "gromacs/utility/gmxassert.h"
186 #include "gromacs/utility/init.h"
187 #include "gromacs/utility/programcontext.h"
189 #endif