summaryrefslogtreecommitdiffabout
path: root/pwmanager/pwmanager/globalstuff.h
blob: 090fcdaf7cb3f540753591d9a6c44050e3ef252a (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/***************************************************************************
 *                                                                         *
 *   copyright (C) 2003, 2004 by Michael Buesch                            *
 *   email: mbuesch@freenet.de                                             *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License version 2        *
 *   as published by the Free Software Foundation.                         *
 *                                                                         *
 ***************************************************************************/

/***************************************************************************
 * copyright (C) 2004 by Ulf Schenk
 * This file is originaly based on version 1.0.1 of pwmanager
 * and was modified to run on embedded devices that run microkde
 *
 * $Id$
 **************************************************************************/  

#ifndef __GLOBALSTUFF_H
#define __GLOBALSTUFF_H

#ifndef PWM_EMBEDDED
#include "config.h"
#endif

#include "compiler.h"

  //US BUG: the following code caused compile errors with certain gcccompilers (2.95).
  // Because of that I replaced it with a Qt version, which should do the same.
#include <string>

#ifndef PWM_EMBEDDED
#include <sstream>
#else
#include <qstring.h>
#include <qtextstream.h>
#endif

#ifndef CONFIG_KEYCARD
class QWidget;
void no_keycard_support_msg_box(QWidget *parentWidget);
#endif // CONFIG_KEYCARD

#ifdef PROG_NAME
# undef PROG_NAME
#endif
#define PROG_NAME	"PwM/Pi"

#ifdef PACKAGE_NAME
# undef PACKAGE_NAME
#endif
#define PACKAGE_NAME	"pwm-pi"

#ifdef PACKAGE_VER
# undef PACKAGE_VER
#endif
#define PACKAGE_VER	"1.0.1"

#ifdef CONFIG_DEBUG
# define PWM_DEBUG
#else
# undef PWM_DEBUG
#endif

#ifdef QT_MAKE_VERSION
# undef QT_MAKE_VERSION
#endif
#define QT_MAKE_VERSION(a,b,c)	(((a) << 16) | ((b) << 8) | (c))

/** remove "unused parameter" warnings */
#ifdef PARAM_UNUSED
# undef PARAM_UNUSED
#endif
#define PARAM_UNUSED(x)	(void)x

/** return the number of elements in an array */
#ifdef array_size
# undef array_size
#endif
#define array_size(x)	(sizeof(x) / sizeof((x)[0]))

//US BUG: the following code caused compile errors with certain gcccompilers (2.95).
// Because of that I replaced it with a Qt version, which should do the same.
#ifndef PWM_EMBEDDED
/** convert something to string using ostringstream */
template <class T> inline
std::string tostr(const T &t)
{
  std::ostringstream s;
  s << t;
  return s.str();
}
#else
/** convert something to string using ostringstream */
template <class T> inline
std::string tostr(const T &t)
{
  QString result;
  QTextOStream(&result) << t;
  return result.latin1();
}
#endif

/** delete the memory and NULL the pointer */
template<class T> inline
void delete_and_null(T *&p)
{
	delete p;
	p = 0;
}
/** delete the memory if the pointer isn't a NULL pointer */
template<class T> inline
void delete_ifnot_null(T *&p)
{
	if (p)
		delete_and_null(p);
}

template<class T> inline
void delete_and_null_array(T *&p)
{
	delete [] p;
	p = 0;
}

template<class T> inline
void delete_ifnot_null_array(T *&p)
{
	if (p)
		delete_and_null_array(p);
}

#endif // GLOBALSTUFF_H