1 /* globals.h */
2 
3 /* Copyright (C) 2012 Michael Lugmair (Lucio Carreras)
4  *
5  * This file is part of sayonara player
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef GLOBALS_H_
22 #define GLOBALS_H_
23 
24 #include <type_traits>
25 
26 #ifndef CAST_MACROS
27 	#define scast(x, y) static_cast<x>(y)
28 	#define dcast(x, y) dynamic_cast<x>(y)
29 	#define rcast(x, y) reinterpret_cast<x>(y)
30 	#define CAST_MACROS
31 #endif
32 
33 #define DARK_BLUE(x) QString("<font color=#0000FF>") + x + QString("</font>")
34 #define LIGHT_BLUE(x) QString("<font color=#8888FF>") + x + QString("</font>")
35 
36 #define CAR_RET QString("<br />")
37 #define BOLD(x) QString("<b>") + x + QString("</b>")
38 #define BLACK(x) QString("<font color=#000000>") + x + QString("</font>")
39 
40 
41 // name, target, dark, string
42 #define LINK(n, t, d, s) if(d) s=QString("<a href=\"t\">)") + LIGHT_BLUE(n) + QString("</a>"); \
43 						 else  s=QString("<a href=\"t\">)") + DARK_BLUE(n) + QString("</a>");
44 
45 #define SAYONARA_ORANGE_STR QString("#e8841a")
46 #define SAYONARA_ORANGE_COL QColor(232, 132, 26)
47 
48 namespace Util
49 {
50 	template<typename TINT, typename T>
51 	typename std::enable_if<std::is_pointer<T>::value, bool>::type
between(TINT idx,const T & cont)52 	between( TINT idx, const T& cont){
53 		return (idx >= 0 && idx < static_cast<TINT>(cont->size()));
54 	}
55 
56 	template<typename TINT, typename T>
57 	typename std::enable_if<std::is_class<T>::value, bool>::type
between(TINT idx,const T & cont)58 	between( TINT idx, const T& cont){
59 		return (idx >= 0 && idx < static_cast<TINT>(cont.size()));
60 	}
61 
62 	template<typename TINT>
63 	typename std::enable_if<std::is_integral<TINT>::value, bool>::type
between(TINT idx,TINT max)64 	between( TINT idx, TINT max){
65 		return (idx >= 0 && idx < max);
66 	}
67 
68 	enum SaveAsAnswer
69 	{
70 		Success,
71 		InvalidName,
72 		NotStorable,
73 		NameAlreadyThere,
74 		InvalidObject,
75 		OtherError
76 	};
77 }
78 
79 template<typename T>
80 typename std::enable_if<std::is_enum<T>::value, typename std::underlying_type<T>::type>::type
81 operator+(T enumValue)
82 {
83 	return static_cast<typename std::underlying_type<T>::type>(enumValue);
84 }
85 
86 #endif /* GLOBALS_H_ */
87