joachim99@8
|
1 /***************************************************************************
|
joachim99@8
|
2 common.h - Things that are needed often
|
joachim99@8
|
3 -------------------
|
joachim99@8
|
4 begin : Mon Mar 18 2002
|
joachim99@77
|
5 copyright : (C) 2002-2007 by Joachim Eibl
|
joachim99@69
|
6 email : joachim.eibl at gmx.de
|
joachim99@8
|
7 ***************************************************************************/
|
joachim99@8
|
8
|
joachim99@8
|
9 /***************************************************************************
|
joachim99@8
|
10 * *
|
joachim99@8
|
11 * This program is free software; you can redistribute it and/or modify *
|
joachim99@8
|
12 * it under the terms of the GNU General Public License as published by *
|
joachim99@8
|
13 * the Free Software Foundation; either version 2 of the License, or *
|
joachim99@8
|
14 * (at your option) any later version. *
|
joachim99@8
|
15 * *
|
joachim99@8
|
16 ***************************************************************************/
|
joachim99@8
|
17
|
joachim99@8
|
18 #ifndef _COMMON_H
|
joachim99@8
|
19 #define _COMMON_H
|
joachim99@8
|
20
|
joachim99@66
|
21 #include <assert.h>
|
joachim99@66
|
22
|
joachim99@80
|
23
|
joachim99@8
|
24 template< class T >
|
joachim99@8
|
25 T min2( T x, T y )
|
joachim99@8
|
26 {
|
joachim99@8
|
27 return x<y ? x : y;
|
joachim99@8
|
28 }
|
joachim99@8
|
29 template< class T >
|
joachim99@8
|
30 T max2( T x, T y )
|
joachim99@8
|
31 {
|
joachim99@8
|
32 return x>y ? x : y;
|
joachim99@8
|
33 }
|
joachim99@8
|
34
|
joachim99@8
|
35 typedef unsigned char UINT8;
|
joachim99@8
|
36 typedef unsigned short UINT16;
|
joachim99@8
|
37 typedef unsigned int UINT32;
|
joachim99@8
|
38
|
joachim99@8
|
39
|
joachim99@8
|
40 template <class T>
|
joachim99@8
|
41 T min3( T d1, T d2, T d3 )
|
joachim99@8
|
42 {
|
joachim99@8
|
43 if ( d1 < d2 && d1 < d3 ) return d1;
|
joachim99@8
|
44 if ( d2 < d3 ) return d2;
|
joachim99@8
|
45 return d3;
|
joachim99@8
|
46 }
|
joachim99@8
|
47
|
joachim99@8
|
48 template <class T>
|
joachim99@8
|
49 T max3( T d1, T d2, T d3 )
|
joachim99@8
|
50 {
|
joachim99@8
|
51
|
joachim99@8
|
52 if ( d1 > d2 && d1 > d3 ) return d1;
|
joachim99@8
|
53
|
joachim99@8
|
54
|
joachim99@8
|
55 if ( d2 > d3 ) return d2;
|
joachim99@8
|
56 return d3;
|
joachim99@8
|
57
|
joachim99@8
|
58 }
|
joachim99@8
|
59
|
joachim99@8
|
60 template <class T>
|
joachim99@8
|
61 T minMaxLimiter( T d, T minimum, T maximum )
|
joachim99@8
|
62 {
|
joachim99@8
|
63 assert(minimum<=maximum);
|
joachim99@8
|
64 if ( d < minimum ) return minimum;
|
joachim99@8
|
65 if ( d > maximum ) return maximum;
|
joachim99@8
|
66 return d;
|
joachim99@8
|
67 }
|
joachim99@8
|
68
|
joachim99@69
|
69 #include <map>
|
joachim99@69
|
70 #include <qstring.h>
|
joachim99@69
|
71 class QFont;
|
joachim99@69
|
72 class QColor;
|
joachim99@69
|
73 class QSize;
|
joachim99@69
|
74 class QPoint;
|
joachim99@69
|
75 class QStringList;
|
joachim99@69
|
76 class QTextStream;
|
joachim99@69
|
77
|
joachim99@69
|
78 class ValueMap
|
joachim99@69
|
79 {
|
joachim99@69
|
80 private:
|
joachim99@69
|
81 std::map<QString,QString> m_map;
|
joachim99@69
|
82 public:
|
joachim99@69
|
83 ValueMap();
|
joachim99@69
|
84 virtual ~ValueMap();
|
joachim99@69
|
85
|
joachim99@69
|
86 void save( QTextStream& ts );
|
joachim99@69
|
87 void load( QTextStream& ts );
|
joachim99@69
|
88 QString getAsString();
|
joachim99@69
|
89 // void load( const QString& s );
|
joachim99@69
|
90
|
joachim99@69
|
91 virtual void writeEntry(const QString&, const QFont& );
|
joachim99@69
|
92 virtual void writeEntry(const QString&, const QColor& );
|
joachim99@69
|
93 virtual void writeEntry(const QString&, const QSize& );
|
joachim99@69
|
94 virtual void writeEntry(const QString&, const QPoint& );
|
joachim99@69
|
95 virtual void writeEntry(const QString&, int );
|
joachim99@69
|
96 virtual void writeEntry(const QString&, bool );
|
joachim99@80
|
97 virtual void writeEntry(const QString&, const QStringList&, char separator='|' );
|
joachim99@69
|
98 virtual void writeEntry(const QString&, const QString& );
|
joachim99@69
|
99 virtual void writeEntry(const QString&, const char* );
|
joachim99@69
|
100
|
joachim99@80
|
101 virtual QFont readFontEntry (const QString&, const QFont* defaultVal );
|
joachim99@80
|
102 virtual QColor readColorEntry(const QString&, const QColor* defaultVal );
|
joachim99@80
|
103 virtual QSize readSizeEntry (const QString&, const QSize* defaultVal );
|
joachim99@80
|
104 virtual QPoint readPointEntry(const QString&, const QPoint* defaultVal );
|
joachim99@69
|
105 virtual bool readBoolEntry (const QString&, bool bDefault );
|
joachim99@69
|
106 virtual int readNumEntry (const QString&, int iDefault );
|
joachim99@80
|
107 virtual QStringList readListEntry (const QString&, const QStringList& defaultVal, char separator='|' );
|
joachim99@80
|
108 virtual QString readStringEntry(const QString&, const QString& );
|
joachim99@80
|
109
|
joachim99@80
|
110 QString readEntry (const QString& s, const QString& defaultVal );
|
joachim99@80
|
111 QString readEntry (const QString& s, const char* defaultVal );
|
joachim99@80
|
112 QFont readEntry (const QString& s, const QFont& defaultVal );
|
joachim99@80
|
113 QColor readEntry(const QString& s, const QColor defaultVal );
|
joachim99@80
|
114 QSize readEntry (const QString& s, const QSize defaultVal );
|
joachim99@80
|
115 QPoint readEntry(const QString& s, const QPoint defaultVal );
|
joachim99@80
|
116 bool readEntry (const QString& s, bool bDefault );
|
joachim99@80
|
117 int readEntry (const QString& s, int iDefault );
|
joachim99@80
|
118 QStringList readEntry (const QString& s, const QStringList& defaultVal, char separator='|' );
|
joachim99@69
|
119 };
|
joachim99@69
|
120
|
joachim99@69
|
121 QStringList safeStringSplit(const QString& s, char sepChar=',', char metaChar='\\' );
|
joachim99@69
|
122 QString safeStringJoin(const QStringList& sl, char sepChar=',', char metaChar='\\' );
|
joachim99@69
|
123
|
joachim99@8
|
124 #endif
|