src-common/misc.h

changeset 44
d0bf58f3560f
parent 39
2c368cf5cc19
equal deleted inserted replaced
43:1394901b557a 44:d0bf58f3560f
1 /*
2 * ZCinema: Zandronum demo launcher
3 * Copyright (C) 2013-2015 Teemu Piippo
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #pragma once
20 #include "types.h"
21
22 inline quint32 makeByteID (quint8 a, quint8 b, quint8 c, quint8 d)
23 {
24 return a | (b << 8) | (c << 16) | (d << 24);
25 }
26
27 void commonInit();
28 QString basename (const QString& path);
29 bool confirm (const QString& text);
30 QString getBinaryPath (QWidget* parent);
31
32 //
33 // -----------------------------------------------------------------------------
34 //
35
36 template<typename T>
37 T clamp (T a, T min, T max)
38 {
39 return (a > max) ? max : (a < min) ? min : a;
40 }
41
42 //
43 // -----------------------------------------------------------------------------
44 //
45
46 template<typename T>
47 T min (T a, T b)
48 {
49 return (a < b) ? a : b;
50 }
51
52 //
53 // -----------------------------------------------------------------------------
54 //
55
56 template<typename T>
57 T max (T a, T b)
58 {
59 return (a > b) ? a : b;
60 }
61
62 //
63 // -----------------------------------------------------------------------------
64 //
65
66 template<typename T>
67 T abs (T a)
68 {
69 return (a < 0) ? -a : a;
70 }

mercurial