]> vaikene.ee Git - evaf/blob - src/libs/Common/util.h
Doxygen documentation fixes.
[evaf] / src / libs / Common / util.h
1 /**
2 * @file Common/util.h
3 * @brief Global utility functions for eVaf
4 * @author Enar Vaikene
5 *
6 * Copyright (c) 2011 Enar Vaikene
7 *
8 * This file is part of the eVaf C++ cross-platform application development framework.
9 *
10 * This file can be used under the terms of the GNU General Public License
11 * version 3.0 as published by the Free Software Foundation and appearing in
12 * the file LICENSE included in the packaging of this file. Please review the
13 * the following information to ensure the GNU General Public License version
14 * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
15 *
16 * Alternatively, this file may be used in accordance with the Commercial License
17 * Agreement provided with the Software.
18 */
19
20 #ifndef __COMMON_UTIL_H
21 # define __COMMON_UTIL_H
22
23 #include "libcommon.h"
24
25 #include <QString>
26 #include <QVariant>
27
28 namespace eVaf {
29 namespace Common {
30
31 /**
32 * Tests if the string means 'true'
33 * @param str The string
34 * @return True if the string is 'yes', 'true', 'on' or '1'.
35 *
36 * This function tests if the string means 'true'. Use this function when the default value
37 * should be 'false'.
38 */
39 inline bool isTrue(QString const & str)
40 {
41 return str == "1" || str.toLower() == "yes" || str.toLower() == "true" || str.toLower() == "on";
42 }
43
44 /**
45 * Tests if the string means 'false'
46 * @param str The string
47 * @return True if the string is 'no', 'false', 'off' or '0'.
48 *
49 * This function tests if the string means 'false'. Use this function when the default value
50 * should be 'true'.
51 */
52 inline bool isFalse(QString const & str)
53 {
54 return str == "0" || str.toLower() == "no" || str.toLower() == "false" || str.toLower() == "off";
55 }
56
57 /**
58 * Converts strings to variant values
59 * @param value The string
60 * @param defaultValue The default value
61 * @return value converted from the string or the default if failed
62 *
63 * This function converts strings to variant values. The type of the expected value is determined
64 * from the default value. If the string fails to convert to the expected type, returns the
65 * default value.
66 */
67
68 COMMON_EXPORT QVariant toVariant(QString const & value, QVariant const & defaultValue);
69
70
71 } // namespace eVaf::Common
72 } // namespace eVaf
73
74 #endif // util.h