iLand
global.h
Go to the documentation of this file.
1/********************************************************************************************
2** iLand - an individual based forest landscape and disturbance model
3** http://iland-model.org
4** Copyright (C) 2009- Werner Rammer, Rupert Seidl
5**
6** This program is free software: you can redistribute it and/or modify
7** it under the terms of the GNU General Public License as published by
8** the Free Software Foundation, either version 3 of the License, or
9** (at your option) any later version.
10**
11** This program is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14** GNU General Public License for more details.
15**
16** You should have received a copy of the GNU General Public License
17** along with this program. If not, see <http://www.gnu.org/licenses/>.
18********************************************************************************************/
19
20#ifndef GLOBAL_H
21#define GLOBAL_H
22
23#define MSGRETURN(x) { qDebug() << x; return; }
24#define WARNINGRETURN(x) { qWarning() << x; return; }
25#define ERRORRETURN(x) { qError() << x; return; }
26// conversions rad/degree
27#define RAD(x) (x*M_PI/180.)
28#define GRAD(x) (x/M_PI*180.)
29#define PI2 2*M_PI
30
31#include <cstdlib>
32#include "math.h"
33#include "exception.h"
34// general datatypes
35//typedef int TreeSpecies;
36
37// global debug helpers (used by macros!)
38void dbg_helper(const char *where, const char *what,const char* file,int line);
39void dbg_helper_ext(const char *where, const char *what,const char* file,int line, const QString &s);
40
41// change to enabled detailed debug messages.
42// if NO_DEBUG_MSGS is defined, NO debug outputs are generated.
43// NO_DEBUG_MSG
44//#if !defined(QT_DEBUG)
45//#define NO_DEBUG_MSGS
46//#endif
47
48#if !defined(DBG_IF)
49# ifndef NO_DEBUG_MSGS
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)
57# ifndef NO_DEBUG_MSGS
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
64#if !defined(DBGMODE)
65# ifndef NO_DEBUG_MSGS
66# define DBGMODE(stmts) { stmts }
67# else
68# define DBGMODE(stmts) qt_noop()
69# endif
70#endif
71
72// log level functions
73bool logLevelDebug(); // true, if detailed debug information is logged
74bool logLevelInfo(); // true, if only important aggreate info is logged
75bool logLevelWarning(); // true if only severe warnings/errors are logged.
76void setLogLevel(int loglevel); // setter function
77
78// the random number generator:
79#include "randomgenerator.h"
80
81
82inline double limit(const double value, const double lower, const double upper)
83{
84 return qMax(qMin(value, upper), lower);
85}
86inline int limit(const int value, const int lower, const int upper)
87{
88 return qMax(qMin(value, upper), lower);
89}
90inline void setBit(unsigned 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}
97inline bool isBitSet(const unsigned int value, const int bit)
98{
99 return value & (1 << bit);
100}
101
102// define a global isnan() function
103#ifndef isnan
104#define isnan(x) ((x) != (x))
105#endif
106
107#include "globalsettings.h"
108
109#endif // GLOBAL_H
bool logLevelInfo()
Definition: main.cpp:21
bool isBitSet(const unsigned int value, const int bit)
Definition: global.h:97
void dbg_helper(const char *where, const char *what, const char *file, int line)
Definition: globalsettings.cpp:91
bool logLevelWarning()
Definition: main.cpp:27
void setBit(unsigned int &rTarget, const int bit, const bool value)
Definition: global.h:90
void dbg_helper_ext(const char *where, const char *what, const char *file, int line, const QString &s)
Definition: globalsettings.cpp:95
bool logLevelDebug()
Definition: main.cpp:15
double limit(const double value, const double lower, const double upper)
Definition: global.h:82
void setLogLevel(int loglevel)
Definition: main.cpp:31