Subversion Repositories public iLand

Rev

Rev 706 | Rev 779 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1
 
671 werner 2
/********************************************************************************************
3
**    iLand - an individual based forest landscape and disturbance model
4
**    http://iland.boku.ac.at
5
**    Copyright (C) 2009-  Werner Rammer, Rupert Seidl
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
 
24 Werner 21
#ifndef GLOBAL_H
22
#define GLOBAL_H
23
 
24
#define MSGRETURN(x) { qDebug() << x; return; }
87 Werner 25
#define WARNINGRETURN(x) { qWarning() << x; return; }
91 Werner 26
#define ERRORRETURN(x) { qError() << x; return; }
24 Werner 27
// conversions rad/degree
28
#define RAD(x) (x*M_PI/180.)
29
#define GRAD(x) (x/M_PI*180.)
32 Werner 30
#define PI2 2*M_PI
33 Werner 31
 
706 werner 32
#include <cstdlib>
33
#include "math.h"
102 Werner 34
#include "exception.h"
33 Werner 35
// general datatypes
39 Werner 36
//typedef int TreeSpecies;
117 Werner 37
 
38
// global debug helpers (used by macros!)
39
void dbg_helper(const char *where, const char *what,const char* file,int line);
40
void dbg_helper_ext(const char *where, const char *what,const char* file,int line, const QString &s);
41
 
216 werner 42
// change to enabled detailed debug messages.
43
// if NO_DEBUG_MSGS is defined, NO debug outputs are generated.
44
#if defined(QT_NO_DEBUG)
45
#define NO_DEBUG_MSGS
46
#endif
47
 
117 Werner 48
#if !defined(DBG_IF)
216 werner 49
#  ifndef NO_DEBUG_MSGS
117 Werner 50
#    define DBG_IF(cond, where, what) ((cond) ? dbg_helper(where, what, __FILE__, __LINE__) : qt_noop())
51
#  else
52
#    define DBG_IF(cond, where, what) qt_noop()
53
#  endif
54
#endif
55
 
56
#if !defined(DBG_IF_X)
216 werner 57
#  ifndef NO_DEBUG_MSGS
117 Werner 58
#    define DBG_IF_X(cond, where, what,more) ((cond) ? dbg_helper_ext(where, what, __FILE__, __LINE__,more) : qt_noop())
59
#  else
60
#    define DBG_IF_X(cond, where, what,more) qt_noop()
61
#  endif
62
#endif
63
 
130 Werner 64
#if !defined(DBGMODE)
216 werner 65
#  ifndef NO_DEBUG_MSGS
130 Werner 66
#    define DBGMODE(stmts) { stmts }
67
#  else
68
#    define DBGMODE(stmts) qt_noop()
69
#  endif
70
#endif
71
 
431 werner 72
// log level functions
73
bool logLevelDebug(); // true, if detailed debug information is logged
74
bool logLevelInfo(); // true, if only important aggreate info is logged
75
bool logLevelWarning(); // true if only severe warnings/errors are logged.
76
void setLogLevel(int loglevel); // setter function
705 werner 77
 
707 werner 78
// the random number generator:
79
#include "randomgenerator.h"
210 werner 80
 
443 werner 81
 
210 werner 82
inline double limit(const double value, const double lower, const double upper)
83
{
84
    return qMax(qMin(value, upper), lower);
85
}
216 werner 86
inline int limit(const int value, const int lower, const int upper)
87
{
88
    return qMax(qMin(value, upper), lower);
89
}
285 werner 90
inline void setBit(int &rTarget, const int bit, const bool value)
91
{
92
    if (value)
93
        rTarget |= (1 << bit);  // set bit
94
    else
95
        rTarget &= ( (1 << bit) ^ 0xffffff ); // clear bit
96
}
287 werner 97
inline bool isBitSet(const int value, const int bit)
98
{
99
    return value & (1 << bit);
100
}
615 werner 101
 
102
// define a global isnan() function
706 werner 103
#ifndef isnan
615 werner 104
#define isnan(x) ((x) != (x))
706 werner 105
#endif
615 werner 106
 
705 werner 107
#include "globalsettings.h"
108
 
24 Werner 109
#endif // GLOBAL_H