Code beautification with uncrustify
[alexxy/gromacs.git] / src / gromacs / utility / gmxregex.h
1 /*
2  *
3  *                This source code is part of
4  *
5  *                 G   R   O   M   A   C   S
6  *
7  *          GROningen MAchine for Chemical Simulations
8  *
9  * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
10  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
11  * Copyright (c) 2001-2009, The GROMACS development team,
12  * check out http://www.gromacs.org for more information.
13  *
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  *
19  * If you want to redistribute modifications, please consider that
20  * scientific software is very special. Version control is crucial -
21  * bugs must be traceable. We will be happy to consider code for
22  * inclusion in the official distribution, but derived work must not
23  * be called official GROMACS. Details are found in the README & COPYING
24  * files - if they are missing, get the official version at www.gromacs.org.
25  *
26  * To help us fund GROMACS development, we humbly ask that you cite
27  * the papers on the package - you can find them in the top README file.
28  *
29  * For more info, check our website at http://www.gromacs.org
30  */
31 /*! \libinternal \file
32  * \brief
33  * Declares simple wrapper for regular expression functionality.
34  *
35  * \author Teemu Murtola <teemu.murtola@cbr.su.se>
36  * \inlibraryapi
37  * \ingroup module_utility
38  */
39 #ifndef GMX_UTILITY_GMXREGEX_H
40 #define GMX_UTILITY_GMXREGEX_H
41
42 #include <string>
43
44 #include "common.h"
45
46 namespace gmx
47 {
48
49 class Regex;
50
51 /*! \cond libapi */
52 /*! \libinternal \brief
53  * Matches a string with a regular expression.
54  *
55  * \param[in] str   String to match.
56  * \param[in] regex Regular expression to match.
57  * \returns   true if \p regex matches the whole \p str.
58  *
59  * Does not throw currently, but this is subject to change if/when better error
60  * handling is implemented (currently, it returns false if the matching fails,
61  * e.g., because of out-of-memory).
62  *
63  * \ingroup module_utility
64  */
65 bool regexMatch(const char *str, const Regex &regex);
66 //! \copydoc regexMatch(const char *, const Regex &)
67 bool regexMatch(const std::string &str, const Regex &regex);
68 //! \endcond
69
70 /*! \libinternal \brief
71  * Represents a regular expression.
72  *
73  * This class provides a simple interface for regular expression construction.
74  * regexMatch() is used to match the regular expression against a string.
75  * POSIX extended regular expression syntax is used.
76  *
77  * Currently, isSupported() will return false if POSIX regular expression
78  * header is not available (i.e., on Windows).  In this case, calling other
79  * constructors than the default constructor throws an exception.
80  *
81  * \see regexMatch()
82  *
83  * \inlibraryapi
84  * \ingroup module_utility
85  */
86 class Regex
87 {
88     public:
89         /*! \brief
90          * Returns true if regular expression support has been compiled in.
91          *
92          * Does not throw.
93          */
94         static bool isSupported();
95
96         /*! \brief
97          * Constructs a regular expression that matches nothing.
98          *
99          * Does not throw.
100          */
101         Regex();
102         /*! \brief
103          * Constructs a regular expression from a string.
104          *
105          * \param[in] value  String to compile into a regular expression.
106          * \throws    std::bad_alloc if out of memory.
107          * \throws    InvalidInputError if \p value is not a valid regular
108          *      expression.
109          *
110          * \todo
111          * Consider whether some other exception type would be better.
112          */
113         explicit Regex(const char *value);
114         //! \copydoc Regex(const char *)
115         explicit Regex(const std::string &value);
116         //! Frees memory allocated for the regular expression.
117         ~Regex();
118
119     private:
120         class Impl;
121
122         PrivateImplPointer<Impl> impl_;
123
124         friend bool regexMatch(const char *str, const Regex &regex);
125         friend bool regexMatch(const std::string &str, const Regex &regex);
126 };
127
128 } // namespace gmx
129
130 #endif