]>
vaikene.ee Git - evaf/blob - src/libs/Common/util.h
3 * @brief Global utility functions for eVaf
6 * Copyright (c) 2011 Enar Vaikene
8 * This file is part of the eVaf C++ cross-platform application development framework.
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.
16 * Alternatively, this file may be used in accordance with the Commercial License
17 * Agreement provided with the Software.
20 #ifndef __COMMON_UTIL_H
21 # define __COMMON_UTIL_H
23 #include "libcommon.h"
32 * Tests if the string means 'true'
33 * @param str The string
34 * @return True if the string is 'yes', 'true', 'on' or '1'.
36 * This function tests if the string means 'true'. Use this function when the default value
39 inline bool isTrue(QString
const & str
)
41 return str
== "1" || str
.toLower() == "yes" || str
.toLower() == "true" || str
.toLower() == "on";
45 * Tests if the string means 'false'
46 * @param str The string
47 * @return True if the string is 'no', 'false', 'off' or '0'.
49 * This function tests if the string means 'false'. Use this function when the default value
52 inline bool isFalse(QString
const & str
)
54 return str
== "0" || str
.toLower() == "no" || str
.toLower() == "false" || str
.toLower() == "off";
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
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
68 COMMON_EXPORT QVariant
toVariant(QString
const & value
, QVariant
const & defaultValue
);
71 } // namespace eVaf::Common