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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
// -*-c++-*-
// ------------------------------------------
// RCS data:
// $Date: 2003/06/23 14:47:22 $
// $Revision: 1.1.1.1 $
// $Source: /cvsroot/miwm/miwm/miwm/alpha.h,v $
// $Id: alpha.h,v 1.1.1.1 2003/06/23 14:47:22 bwise837 Exp $
// $RCSfile: alpha.h,v $
// -------------------------------------------
// Copyright by Ben Paul Wise.
// -------------------------------------------
// 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.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// -------------------------------------------
// these are my extremely common headers.
// ------------------------------------------
#ifndef ALPHA_H
#define ALPHA_H
using namespace std;
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <assert.h>
// ------------------------------------------
// Xt does '#define Boolean int', which plays havoc
// with any reasonable name for the following
enum TLogical { tbFalse, tbTrue, tbUnknown };
ostream& operator << (ostream& s, TLogical r);
// ------------------------------------------
// useful macros for debugging.
//
// use assert and ASSERT liberally, with DebugCheck on user-set flags
// (and BPWDEBUG to shut it all off)
//
// ------------------------------------------
// BPWDEBUG is the "one big switch" that controls debugging-mode
// in alpha and everything that uses alpha.
#define BPWDEBUG
// note that the way cdbg is defined, it must be protected
// by a bDebug statment
#ifdef BPWDEBUG
#define cdbg cerr<<endl<<__FILE__<<":"<<__LINE__<<" "<<"CDBG: "
#else
#define cdbg
#endif
// This prints out a newline, followed by the current file name
// and line number, e.g.,
//
// cdbg << "Bad data encountered!";
//
// would print out something like
//
// widget.cc:379 CDBG: Bad data encountered!
//
// which can be used by the next-error facility of emacs or grep-ed for.
// ------------------------------------------
#ifdef BPWDEBUG
#define bDebug(expression) { expression }
#else
#define bDebug(expression) {}
#endif
// This causes stuff to be expanded if and only if the preprocessor
// variable BPWDEBUG is defined. This enables more thorough and
// time-consuming checks than can be done in a simple 'assert'.
// For instance,
//
// bDebug(
// for( i = 0; i < tableSize; ++i ) {
// if( table[i] < 0) {
// cdbg << i << "-th entry is out of range!";
// }
// }
// );
// it is crucial that the empty {} be put there, so that the syntax does not change
// depending on the conditional compilation, as would happen below:
//
//if ( stuff1 ) { }
//else
//bDebug ( stuff2 )
//
//stuff3
//
// which would compile as EITHER
//
//if ( stuff1 ) { }
//else
// stuff2
//
//stuff3
//
// OR
//
//if ( stuff1 ) { }
//else
//stuff3
//
// which is clearly wrong
// ------------------------------------------
// a facility to use bit-masked categories of
// checks would be nice. An approximation is below.
// remember, & is bitwise AND, | is OR, ^ is XOR
#define ASSERT(x, msg) \
if ((x) == 0) { cerr<<__FILE__<<":"<<__LINE__<<" " <<msg<<endl; exit(0); }
#ifdef BPWDEBUG
#define DebugCheck(Mask, Cat, Exp) { if (Mask & Cat) Exp }
#else
#define DebugCheck(Mask, Cat, Exp) {}
#endif
// note these working example of DebugCheck from code.
// I use the private static data member VPool::debugPools as the category,
// and enumerated (1,2,4) levels of debugging.
//
// no compound bitmask, no compound statement:
// DebugCheck(MuchPoolDebugging , debugPools,
// cout << "ran off the end - construct a new one" << endl;
// )
//
// note how the ( ) on the compound bitmask and the { } on compound statements work
// DebugCheck((LittlePoolDebugging | MuchPoolDebugging) , debugPools,
// {
// cout << "Number of remaining allocated pool objects: " << count;
// cout << " out of " << total << endl;
// }
// );
// this is a global variable we could use to control DebugCheck
extern int theDBGAlpha;
// these are the debug-categories for Alpha. We arbitrarily label
// them 1-5. You can add more, but please do not change these.
//
// Put notes in your header files saying how you've used each
// category.
//
// E.g.:
// 'DbgAlpha1' might be events and conditions related to constructing,
// modifying (complexify/simplify), and destructing MRM objects.
// 'DbgAlpha2' might be events and conditions related to tactical
// behavior
enum AlphaDBGCategories {
DbgAlpha1 = 1,
DbgAlpha2 = 2,
DbgAlpha3 = 4,
DbgAlpha4 = 8,
DbgAlpha5 = 16
};
void setAlphaDBG(AlphaDBGCategories, TLogical);
// ------------------------------------------
double dabs (double x);
double dmax (double a, double b);
double dmin (double a, double b);
int iabs (int x);
int imax(int a, int b);
int imin(int a, int b);
// return x ^ n
double expt (double x, int n);
// return x ^ e
double dexpt (double x, double e);
int oddP(int x);
int evenP(int x);
double delta(double a, double b); // symettric % difference
int iround(double x);
double round (double x, int n);
int gcd(int a, int b);
// the /usr/include/math.h covers floor but not ceiling.
// and /usr/include/math.h/floor returns a float, not an int
int ifloor (double x);
int iceiling (double x);
// ------------------------------------------
#endif
// ------------------------------------------
// end of alpha.h
// ------------------------------------------
|