source: cpp/gdk/nonstd.h @ 5

Last change on this file since 5 was 5, checked in by sz, 15 years ago

added the GDK (Genotype Development Kit)

File size: 2.5 KB
Line 
1// This file is a part of Framsticks GDK library.
2// Copyright (C) 2002-2006  Szymon Ulatowski.  See LICENSE.txt for details.
3// Refer to http://www.frams.alife.pl/ for further information.
4
5//Define rnd01, rnd0N, and randomN so that they
6//work in your C++ environment.
7//Some other functions/macros may also be needed if they
8//are missing in your environment, like min, max, etc.
9
10#ifndef __NONSTD_H
11#define __NONSTD_H
12
13#define APPLICATION_NAME "Framsticks"
14#define MAIN_FRAMSTICKS
15#define SAFEDELETE(p) {if (p) {delete p; p=NULL;}}
16#define SAFEDELETEARRAY(p) {if (p) {delete[] p; p=NULL;}}
17
18//#ifndef _Windows   included below?
19//#include <stdlib.h>
20//#endif
21
22#define DB(x) //output debug info. If needed, use #define DB(x) x
23//#define DB(x) x
24
25// ms visual c++
26#ifdef _MSC_VER
27 #define WIN32_LEAN_AND_MEAN     // Exclude rarely-used stuff from Windows headers
28 #include <windows.h>
29 #include <stdio.h>
30 #include <stdarg.h>
31 #define vsnprintf _vsnprintf
32 #define _USE_MATH_DEFINES
33
34 #ifndef M_PI
35 #define M_PI 3.1415926535897932384626433832795
36 #endif
37 #ifndef M_PI_2
38 #define M_PI_2 (M_PI/2)
39 #endif
40
41#endif
42
43/////////////////////////////////////////////////////// 64-bit int type and other macros
44#ifdef _Windows
45        typedef __int64 LONGLONG;
46        #define PATHSEPARATORCHAR '\\'
47        #define PATHSEPARATORSTRING "\\"
48        #define FPU_THROWS_EXCEPTIONS
49#else
50        #define LONGLONG long long int
51        #define PATHSEPARATORCHAR '/'
52        #define PATHSEPARATORSTRING "/"
53#endif
54
55#ifdef __BORLANDC__
56        #define fileExists(f) (!access(f,0))
57        #include "stdlib.h" //random
58        #define FOPEN_READ "rt"
59        #define FOPEN_WRITE "wt"
60        #define FOPEN_APPEND "at"
61        #define rnd01 ((double)((double)_lrand()/(double)(LRAND_MAX+1)))
62        //#define rnd01 ((double)((double)rand()/(RAND_MAX+1)))
63        #define rnd0N(num) ((double)((num)*rnd01))
64        #define randomN(num) random(num) //uses _lrand
65#else
66        #ifdef _MSC_VER
67        #define fileExists(f) (!access(f,0))
68        #else
69        #define fileExists(f) (!access(f,R_OK))
70        #endif
71
72        #define FOPEN_WRITE "wa"
73        #define FOPEN_APPEND "aa"
74        #define FOPEN_READ "ra"
75        //#define FLOATRAND
76        #ifdef FLOATRAND
77                #define randomN(x) ((int)((x)*drand48()))
78                #define rnd01 (drand48())
79                #define rnd0N(x) (drand48()*(x))
80        #else
81                #define rnd01 ((double)(rand()/(RAND_MAX+1.0)))
82                #define rnd0N(x) ((x)*rnd01)
83                #define randomN(x) ((int)rnd0N(x))
84        #endif
85#endif
86
87
88#ifdef __GNUC__
89/*
90        #define min(a,b) (((a)>(b))?(b):(a))
91        #define max(a,b) (((a)>(b))?(a):(b))
92        #define abs(a) ((a)>=0?(a):-(a))
93*/
94#include <algorithm>
95using namespace std;
96#endif
97
98#endif
Note: See TracBrowser for help on using the repository browser.