summaryrefslogtreecommitdiffstats
path: root/src/common.h
blob: c5b27d308e3c43ba72bdabb33c47cc0f4f0cb662 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/***************************************************************************
                          common.h  -  Things that are needed often
                             -------------------
    begin                : Mon Mar 18 2002
    copyright            : (C) 2002-2007 by Joachim Eibl
    email                : joachim.eibl at gmx.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef _COMMON_H
#define _COMMON_H

#include <assert.h>

template< class T >
T min2( T x, T y )
{
   return x<y ? x : y;
}
template< class T >
T max2( T x, T y )
{
   return x>y ? x : y;
}

typedef unsigned char UINT8;
typedef unsigned short UINT16;
typedef unsigned int UINT32;


template <class T>
T min3( T d1, T d2, T d3 )
{
   if ( d1 < d2  &&  d1 < d3 ) return d1;
   if ( d2 < d3 ) return d2;
   return d3;
}

template <class T>
T max3( T d1, T d2, T d3 )
{

   if ( d1 > d2  &&  d1 > d3 ) return d1;


   if ( d2 > d3 ) return d2;
   return d3;

}

template <class T>
T minMaxLimiter( T d, T minimum, T maximum )
{
   assert(minimum<=maximum);
   if ( d < minimum ) return minimum;
   if ( d > maximum ) return maximum;
   return d;
}

#include <map>
#include <tqstring.h>
class TQFont;
class TQColor;
class TQSize;
class TQPoint;
class TQStringList;
class TQTextStream;

class ValueMap
{
private:
   std::map<TQString,TQString> m_map;
public:
   ValueMap();
   virtual ~ValueMap();

   void save( TQTextStream& ts );
   void load( TQTextStream& ts );
   TQString getAsString();
   // void load( const TQString& s );

   virtual void writeEntry(const TQString&, const TQFont& );
   virtual void writeEntry(const TQString&, const TQColor& );
   virtual void writeEntry(const TQString&, const TQSize& );
   virtual void writeEntry(const TQString&, const TQPoint& );
   virtual void writeEntry(const TQString&, int );
   virtual void writeEntry(const TQString&, bool );
   virtual void writeEntry(const TQString&, const TQStringList&, char separator );
   virtual void writeEntry(const TQString&, const TQString& );
   virtual void writeEntry(const TQString&, const char* );

   virtual TQFont       readFontEntry (const TQString&, TQFont* defaultVal );
   virtual TQColor      readColorEntry(const TQString&, TQColor* defaultVal );
   virtual TQSize       readSizeEntry (const TQString&, TQSize* defaultVal );
   virtual TQPoint      readPointEntry(const TQString&, TQPoint* defaultVal );
   virtual bool        readBoolEntry (const TQString&, bool bDefault );
   virtual int         readNumEntry  (const TQString&, int iDefault );
   virtual TQStringList readListEntry (const TQString&, const TQStringList& defaultVal, char separator );
   virtual TQString     readEntry     (const TQString&, const TQString& );
};

TQStringList safeStringSplit(const TQString& s, char sepChar=',', char metaChar='\\' );
TQString safeStringJoin(const TQStringList& sl, char sepChar=',', char metaChar='\\' );

#endif