mirror of
https://github.com/opnsense/src.git
synced 2026-06-08 16:22:46 -04:00
To the Attic we go..
This commit is contained in:
parent
fbb10fbaa8
commit
cb03015500
188 changed files with 0 additions and 47889 deletions
|
|
@ -1,68 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Dirk Grunwald (grunwald@cs.uiuc.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifndef _ACG_h
|
||||
#define _ACG_h 1
|
||||
|
||||
#include <RNG.h>
|
||||
#include <math.h>
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
//
|
||||
// Additive number generator. This method is presented in Volume II
|
||||
// of The Art of Computer Programming by Knuth. I've coded the algorithm
|
||||
// and have added the extensions by Andres Nowatzyk of CMU to randomize
|
||||
// the result of algorithm M a bit by using an LCG & a spatial
|
||||
// permutation table.
|
||||
//
|
||||
// The version presented uses the same constants for the LCG that Andres
|
||||
// uses (chosen by trial & error). The spatial permutation table is
|
||||
// the same size (it's based on word size). This is for 32-bit words.
|
||||
//
|
||||
// The ``auxillary table'' used by the LCG table varies in size, and
|
||||
// is chosen to be the the smallest power of two which is larger than
|
||||
// twice the size of the state table.
|
||||
//
|
||||
|
||||
class ACG : public RNG {
|
||||
|
||||
_G_uint32_t initialSeed; // used to reset generator
|
||||
int initialTableEntry;
|
||||
|
||||
_G_uint32_t *state;
|
||||
_G_uint32_t *auxState;
|
||||
short stateSize;
|
||||
short auxSize;
|
||||
_G_uint32_t lcgRecurr;
|
||||
short j;
|
||||
short k;
|
||||
|
||||
protected:
|
||||
|
||||
public:
|
||||
ACG(_G_uint32_t seed = 0, int size = 55);
|
||||
virtual ~ACG();
|
||||
//
|
||||
// Return a long-words word of random bits
|
||||
//
|
||||
virtual _G_uint32_t asLong();
|
||||
virtual void reset();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1989 Free Software Foundation
|
||||
written by Doug Lea (dl@rocky.oswego.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _AllocRing_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define _AllocRing_h 1
|
||||
|
||||
|
||||
/*
|
||||
An AllocRing holds the last n malloc'ed strings, reallocating/reusing
|
||||
one only when the queue wraps around. It thus guarantees that the
|
||||
last n allocations are intact. It is useful for things like I/O
|
||||
formatting where reasonable restrictions may be made about the
|
||||
number of allowable live allocations before auto-deletion.
|
||||
*/
|
||||
|
||||
class AllocRing
|
||||
{
|
||||
|
||||
struct AllocQNode
|
||||
{
|
||||
void* ptr;
|
||||
int sz;
|
||||
};
|
||||
|
||||
AllocQNode* nodes;
|
||||
int n;
|
||||
int current;
|
||||
|
||||
int find(void* p);
|
||||
|
||||
public:
|
||||
|
||||
AllocRing(int max);
|
||||
~AllocRing();
|
||||
|
||||
void* alloc(int size);
|
||||
int contains(void* ptr);
|
||||
void clear();
|
||||
void free(void* p);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Dirk Grunwald (grunwald@cs.uiuc.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifndef _Binomial_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define _Binomial_h 1
|
||||
|
||||
#include <Random.h>
|
||||
|
||||
class Binomial: public Random {
|
||||
protected:
|
||||
int pN;
|
||||
double pU;
|
||||
public:
|
||||
Binomial(int n, double u, RNG *gen);
|
||||
|
||||
int n();
|
||||
int n(int xn);
|
||||
|
||||
double u();
|
||||
double u(int xu);
|
||||
|
||||
virtual double operator()();
|
||||
|
||||
};
|
||||
|
||||
|
||||
inline Binomial::Binomial(int n, double u, RNG *gen)
|
||||
: Random(gen){
|
||||
pN = n; pU = u;
|
||||
}
|
||||
|
||||
inline int Binomial::n() { return pN; }
|
||||
inline int Binomial::n(int xn) { int tmp = pN; pN = xn; return tmp; }
|
||||
|
||||
inline double Binomial::u() { return pU; }
|
||||
inline double Binomial::u(int xu) { double tmp = pU; pU = xu; return tmp; }
|
||||
|
||||
#endif
|
||||
|
|
@ -1,374 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Doug Lea (dl@rocky.oswego.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef _BitSet_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#define _BitSet_h 1
|
||||
|
||||
#include <iostream.h>
|
||||
#include <limits.h>
|
||||
|
||||
#define BITSETBITS (sizeof(short) * CHAR_BIT)
|
||||
|
||||
struct BitSetRep
|
||||
{
|
||||
unsigned short len; // number of shorts in s
|
||||
unsigned short sz; // allocated slots
|
||||
unsigned short virt; // virtual 0 or 1
|
||||
unsigned short s[1]; // bits start here
|
||||
};
|
||||
|
||||
extern BitSetRep* BitSetalloc(BitSetRep*, const unsigned short*,
|
||||
int, int, int);
|
||||
extern BitSetRep* BitSetcopy(BitSetRep*, const BitSetRep*);
|
||||
extern BitSetRep* BitSetresize(BitSetRep*, int);
|
||||
extern BitSetRep* BitSetop(const BitSetRep*, const BitSetRep*,
|
||||
BitSetRep*, char);
|
||||
extern BitSetRep* BitSetcmpl(const BitSetRep*, BitSetRep*);
|
||||
|
||||
|
||||
extern BitSetRep _nilBitSetRep;
|
||||
|
||||
class BitSet;
|
||||
|
||||
class BitSetBit
|
||||
{
|
||||
protected:
|
||||
BitSet* src;
|
||||
unsigned long pos;
|
||||
|
||||
public:
|
||||
BitSetBit(BitSet* v, int p);
|
||||
BitSetBit(const BitSetBit& b);
|
||||
~BitSetBit();
|
||||
operator int() const;
|
||||
int operator = (int b);
|
||||
int operator = (const BitSetBit& b);
|
||||
};
|
||||
|
||||
class BitSet
|
||||
{
|
||||
protected:
|
||||
BitSetRep* rep;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// constructors
|
||||
BitSet();
|
||||
BitSet(const BitSet&);
|
||||
|
||||
~BitSet();
|
||||
|
||||
BitSet& operator = (const BitSet& y);
|
||||
|
||||
// equality & subset tests
|
||||
|
||||
friend int operator == (const BitSet& x, const BitSet& y);
|
||||
friend int operator != (const BitSet& x, const BitSet& y);
|
||||
friend int operator < (const BitSet& x, const BitSet& y);
|
||||
friend int operator <= (const BitSet& x, const BitSet& y);
|
||||
friend int operator > (const BitSet& x, const BitSet& y);
|
||||
friend int operator >= (const BitSet& x, const BitSet& y);
|
||||
|
||||
|
||||
// operations on self
|
||||
|
||||
BitSet& operator |= (const BitSet& y);
|
||||
BitSet& operator &= (const BitSet& y);
|
||||
BitSet& operator -= (const BitSet& y);
|
||||
BitSet& operator ^= (const BitSet& y);
|
||||
|
||||
void complement();
|
||||
|
||||
// individual bit manipulation
|
||||
|
||||
void set(int pos);
|
||||
void set(int from, int to);
|
||||
void set(); // set all
|
||||
|
||||
void clear(int pos);
|
||||
void clear(int from, int to);
|
||||
void clear(); // clear all
|
||||
|
||||
void invert(int pos);
|
||||
void invert(int from, int to);
|
||||
|
||||
int test(int pos) const;
|
||||
int test(int from, int to) const;
|
||||
|
||||
BitSetBit operator [] (int i);
|
||||
|
||||
// iterators
|
||||
|
||||
int first(int b = 1) const;
|
||||
int last(int b = 1) const;
|
||||
|
||||
int next(int pos, int b = 1) const;
|
||||
int prev(int pos, int b = 1) const;
|
||||
int previous(int pos, int b = 1) const /* Obsolete synonym */
|
||||
{ return prev(pos, b); }
|
||||
|
||||
// status
|
||||
|
||||
int empty() const;
|
||||
int virtual_bit() const;
|
||||
int count(int b = 1) const;
|
||||
|
||||
// convertors & IO
|
||||
|
||||
friend BitSet atoBitSet(const char* s,
|
||||
char f='0', char t='1', char star='*');
|
||||
// BitSettoa is deprecated; do not use in new programs.
|
||||
friend const char* BitSettoa(const BitSet& x,
|
||||
char f='0', char t='1', char star='*');
|
||||
|
||||
friend BitSet shorttoBitSet(unsigned short w);
|
||||
friend BitSet longtoBitSet(unsigned long w);
|
||||
|
||||
friend ostream& operator << (ostream& s, const BitSet& x);
|
||||
void printon(ostream& s,
|
||||
char f='0', char t='1', char star='*') const;
|
||||
|
||||
// procedural versions of operators
|
||||
|
||||
friend void and(const BitSet& x, const BitSet& y, BitSet& r);
|
||||
friend void or(const BitSet& x, const BitSet& y, BitSet& r);
|
||||
friend void xor(const BitSet& x, const BitSet& y, BitSet& r);
|
||||
friend void diff(const BitSet& x, const BitSet& y, BitSet& r);
|
||||
friend void complement(const BitSet& x, BitSet& r);
|
||||
|
||||
// misc
|
||||
|
||||
void error(const char* msg) const;
|
||||
int OK() const;
|
||||
};
|
||||
|
||||
|
||||
typedef BitSet BitSetTmp;
|
||||
|
||||
|
||||
BitSet operator | (const BitSet& x, const BitSet& y);
|
||||
BitSet operator & (const BitSet& x, const BitSet& y);
|
||||
BitSet operator - (const BitSet& x, const BitSet& y);
|
||||
BitSet operator ^ (const BitSet& x, const BitSet& y);
|
||||
|
||||
BitSet operator ~ (const BitSet& x);
|
||||
|
||||
// These are inlined regardless of optimization
|
||||
|
||||
inline int BitSet_index(int l)
|
||||
{
|
||||
return (unsigned)(l) / BITSETBITS;
|
||||
}
|
||||
|
||||
inline int BitSet_pos(int l)
|
||||
{
|
||||
return l & (BITSETBITS - 1);
|
||||
}
|
||||
|
||||
|
||||
inline BitSet::BitSet() : rep(&_nilBitSetRep) {}
|
||||
|
||||
inline BitSet::BitSet(const BitSet& x) :rep(BitSetcopy(0, x.rep)) {}
|
||||
|
||||
inline BitSet::~BitSet() { if (rep != &_nilBitSetRep) delete rep; }
|
||||
|
||||
inline BitSet& BitSet::operator = (const BitSet& y)
|
||||
{
|
||||
rep = BitSetcopy(rep, y.rep);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline int operator != (const BitSet& x, const BitSet& y) { return !(x == y); }
|
||||
|
||||
inline int operator > (const BitSet& x, const BitSet& y) { return y < x; }
|
||||
|
||||
inline int operator >= (const BitSet& x, const BitSet& y) { return y <= x; }
|
||||
|
||||
inline void and(const BitSet& x, const BitSet& y, BitSet& r)
|
||||
{
|
||||
r.rep = BitSetop(x.rep, y.rep, r.rep, '&');
|
||||
}
|
||||
|
||||
inline void or(const BitSet& x, const BitSet& y, BitSet& r)
|
||||
{
|
||||
r.rep = BitSetop(x.rep, y.rep, r.rep, '|');
|
||||
}
|
||||
|
||||
inline void xor(const BitSet& x, const BitSet& y, BitSet& r)
|
||||
{
|
||||
r.rep = BitSetop(x.rep, y.rep, r.rep, '^');
|
||||
}
|
||||
|
||||
inline void diff(const BitSet& x, const BitSet& y, BitSet& r)
|
||||
{
|
||||
r.rep = BitSetop(x.rep, y.rep, r.rep, '-');
|
||||
}
|
||||
|
||||
inline void complement(const BitSet& x, BitSet& r)
|
||||
{
|
||||
r.rep = BitSetcmpl(x.rep, r.rep);
|
||||
}
|
||||
|
||||
#if defined(__GNUG__) && !defined(_G_NO_NRV)
|
||||
|
||||
inline BitSet operator & (const BitSet& x, const BitSet& y) return r
|
||||
{
|
||||
and(x, y, r);
|
||||
}
|
||||
|
||||
inline BitSet operator | (const BitSet& x, const BitSet& y) return r
|
||||
{
|
||||
or(x, y, r);
|
||||
}
|
||||
|
||||
inline BitSet operator ^ (const BitSet& x, const BitSet& y) return r
|
||||
{
|
||||
xor(x, y, r);
|
||||
}
|
||||
|
||||
inline BitSet operator - (const BitSet& x, const BitSet& y) return r
|
||||
{
|
||||
diff(x, y, r);
|
||||
}
|
||||
|
||||
inline BitSet operator ~ (const BitSet& x) return r
|
||||
{
|
||||
::complement(x, r);
|
||||
}
|
||||
|
||||
#else /* NO_NRV */
|
||||
|
||||
inline BitSet operator & (const BitSet& x, const BitSet& y)
|
||||
{
|
||||
BitSet r; and(x, y, r); return r;
|
||||
}
|
||||
|
||||
inline BitSet operator | (const BitSet& x, const BitSet& y)
|
||||
{
|
||||
BitSet r; or(x, y, r); return r;
|
||||
}
|
||||
|
||||
inline BitSet operator ^ (const BitSet& x, const BitSet& y)
|
||||
{
|
||||
BitSet r; xor(x, y, r); return r;
|
||||
}
|
||||
|
||||
inline BitSet operator - (const BitSet& x, const BitSet& y)
|
||||
{
|
||||
BitSet r; diff(x, y, r); return r;
|
||||
}
|
||||
|
||||
inline BitSet operator ~ (const BitSet& x)
|
||||
{
|
||||
BitSet r; ::complement(x, r); return r;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
inline BitSet& BitSet::operator &= (const BitSet& y)
|
||||
{
|
||||
and(*this, y, *this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline BitSet& BitSet::operator |= (const BitSet& y)
|
||||
{
|
||||
or(*this, y, *this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline BitSet& BitSet::operator ^= (const BitSet& y)
|
||||
{
|
||||
xor(*this, y, *this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline BitSet& BitSet::operator -= (const BitSet& y)
|
||||
{
|
||||
diff(*this, y, *this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline void BitSet::complement()
|
||||
{
|
||||
::complement(*this, *this);
|
||||
}
|
||||
|
||||
inline int BitSet::virtual_bit() const
|
||||
{
|
||||
return rep->virt;
|
||||
}
|
||||
|
||||
inline int BitSet::first(int b) const
|
||||
{
|
||||
return next(-1, b);
|
||||
}
|
||||
|
||||
inline int BitSet::test(int p) const
|
||||
{
|
||||
if (p < 0) error("Illegal bit index");
|
||||
int index = BitSet_index(p);
|
||||
return (index >= rep->len)? rep->virt :
|
||||
((rep->s[index] & (1 << BitSet_pos(p))) != 0);
|
||||
}
|
||||
|
||||
|
||||
inline void BitSet::set()
|
||||
{
|
||||
rep = BitSetalloc(rep, 0, 0, 1, 0);
|
||||
}
|
||||
|
||||
inline BitSetBit::BitSetBit(const BitSetBit& b) :src(b.src), pos(b.pos) {}
|
||||
|
||||
inline BitSetBit::BitSetBit(BitSet* v, int p)
|
||||
{
|
||||
src = v; pos = p;
|
||||
}
|
||||
|
||||
inline BitSetBit::~BitSetBit() {}
|
||||
|
||||
inline BitSetBit::operator int() const
|
||||
{
|
||||
return src->test(pos);
|
||||
}
|
||||
|
||||
inline int BitSetBit::operator = (int b)
|
||||
{
|
||||
if (b) src->set(pos); else src->clear(pos); return b;
|
||||
}
|
||||
|
||||
inline int BitSetBit::operator = (const BitSetBit& b)
|
||||
{
|
||||
int i = (int)b;
|
||||
*this = i;
|
||||
return i;
|
||||
}
|
||||
|
||||
inline BitSetBit BitSet::operator [] (int i)
|
||||
{
|
||||
if (i < 0) error("illegal bit index");
|
||||
return BitSetBit(this, i);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,761 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Doug Lea (dl@rocky.oswego.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef _BitString_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#define _BitString_h 1
|
||||
|
||||
#include <stream.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <bitprims.h>
|
||||
#define BITSTRBITS _BS_BITS_PER_WORD
|
||||
|
||||
struct BitStrRep
|
||||
{
|
||||
unsigned int len; // length in bits
|
||||
unsigned short sz; // allocated slots
|
||||
_BS_word s[1]; // bits start here
|
||||
};
|
||||
|
||||
extern BitStrRep* BStr_alloc(BitStrRep*, const _BS_word*, int, int,int);
|
||||
extern BitStrRep* BStr_resize(BitStrRep*, int);
|
||||
extern BitStrRep* BStr_copy(BitStrRep*, const BitStrRep*);
|
||||
extern BitStrRep* cmpl(const BitStrRep*, BitStrRep*);
|
||||
extern BitStrRep* and(const BitStrRep*, const BitStrRep*, BitStrRep*);
|
||||
extern BitStrRep* or(const BitStrRep*, const BitStrRep*, BitStrRep*);
|
||||
extern BitStrRep* xor(const BitStrRep*, const BitStrRep*, BitStrRep*);
|
||||
extern BitStrRep* diff(const BitStrRep*, const BitStrRep*, BitStrRep*);
|
||||
extern BitStrRep* cat(const BitStrRep*, const BitStrRep*, BitStrRep*);
|
||||
extern BitStrRep* cat(const BitStrRep*, unsigned int, BitStrRep*);
|
||||
extern BitStrRep* lshift(const BitStrRep*, int, BitStrRep*);
|
||||
|
||||
|
||||
class BitString;
|
||||
class BitPattern;
|
||||
|
||||
class BitStrBit
|
||||
{
|
||||
protected:
|
||||
BitString& src;
|
||||
unsigned int pos;
|
||||
|
||||
public:
|
||||
BitStrBit(BitString& v, int p);
|
||||
BitStrBit(const BitStrBit& b);
|
||||
~BitStrBit();
|
||||
operator unsigned int() const;
|
||||
int operator = (unsigned int b);
|
||||
};
|
||||
|
||||
class BitSubString
|
||||
{
|
||||
friend class BitString;
|
||||
friend class BitPattern;
|
||||
|
||||
protected:
|
||||
|
||||
BitString& S;
|
||||
unsigned int pos;
|
||||
unsigned int len;
|
||||
|
||||
BitSubString(BitString& x, int p, int l);
|
||||
BitSubString(const BitSubString& x);
|
||||
public:
|
||||
~BitSubString();
|
||||
|
||||
BitSubString& operator = (const BitString&);
|
||||
BitSubString& operator = (const BitSubString&);
|
||||
|
||||
int length() const;
|
||||
int empty() const;
|
||||
|
||||
int OK() const;
|
||||
};
|
||||
|
||||
class BitString
|
||||
{
|
||||
friend class BitSubString;
|
||||
friend class BitPattern;
|
||||
protected:
|
||||
BitStrRep* rep;
|
||||
|
||||
int search(int, int, const _BS_word*, int, int) const;
|
||||
int match(int, int, int, const _BS_word*,int,int) const;
|
||||
BitSubString _substr(int first, int l);
|
||||
|
||||
public:
|
||||
|
||||
// constructors
|
||||
BitString();
|
||||
BitString(const BitString&);
|
||||
BitString(const BitSubString& y);
|
||||
|
||||
~BitString();
|
||||
|
||||
BitString& operator = (unsigned int bit);
|
||||
BitString& operator = (const BitString& y);
|
||||
BitString& operator = (const BitSubString& y);
|
||||
|
||||
// equality & subset tests
|
||||
|
||||
friend int operator == (const BitString&, const BitString&);
|
||||
friend int operator != (const BitString&, const BitString&);
|
||||
friend int operator < (const BitString&, const BitString&);
|
||||
friend int operator <= (const BitString&, const BitString&);
|
||||
friend int operator > (const BitString&, const BitString&);
|
||||
friend int operator >= (const BitString&, const BitString&);
|
||||
|
||||
// procedural versions of operators
|
||||
|
||||
|
||||
friend void and(const BitString&, const BitString&, BitString&);
|
||||
friend void or(const BitString&, const BitString&, BitString&);
|
||||
friend void xor(const BitString&, const BitString&, BitString&);
|
||||
friend void diff(const BitString&, const BitString&, BitString&);
|
||||
friend void cat(const BitString&, const BitString&, BitString&);
|
||||
friend void cat(const BitString&, unsigned int, BitString&);
|
||||
friend void lshift(const BitString&, int, BitString&);
|
||||
friend void rshift(const BitString&, int, BitString&);
|
||||
|
||||
friend void complement(const BitString&, BitString&);
|
||||
|
||||
friend int lcompare(const BitString&, const BitString&);
|
||||
|
||||
// assignment-based operators
|
||||
// (constuctive versions decalred inline below
|
||||
|
||||
BitString& operator |= (const BitString&);
|
||||
BitString& operator &= (const BitString&);
|
||||
BitString& operator -= (const BitString&);
|
||||
BitString& operator ^= (const BitString&);
|
||||
BitString& operator += (const BitString&);
|
||||
BitString& operator += (unsigned int b);
|
||||
BitString& operator <<=(int s);
|
||||
BitString& operator >>=(int s);
|
||||
|
||||
void complement();
|
||||
|
||||
// individual bit manipulation
|
||||
|
||||
void set(int pos);
|
||||
void set(int from, int to);
|
||||
void set();
|
||||
|
||||
void clear(int pos);
|
||||
void clear(int from, int to);
|
||||
void clear();
|
||||
|
||||
void invert(int pos);
|
||||
void invert(int from, int to);
|
||||
|
||||
int test(int pos) const;
|
||||
int test(int from, int to) const;
|
||||
|
||||
void assign(int p, unsigned int bit);
|
||||
|
||||
// indexing
|
||||
|
||||
BitStrBit operator [] (int pos);
|
||||
|
||||
// iterators
|
||||
|
||||
int first(unsigned int bit = 1) const;
|
||||
int last(unsigned int b = 1) const;
|
||||
|
||||
int next(int pos, unsigned int b = 1) const;
|
||||
int prev(int pos, unsigned int b = 1) const;
|
||||
int previous(int pos, unsigned int b = 1) const
|
||||
{ return prev(pos, b); } /* Obsolete synonym */
|
||||
|
||||
// searching & matching
|
||||
|
||||
int index(unsigned int bit, int startpos = 0) const ;
|
||||
int index(const BitString&, int startpos = 0) const;
|
||||
int index(const BitSubString&, int startpos = 0) const;
|
||||
int index(const BitPattern&, int startpos = 0) const;
|
||||
|
||||
int contains(const BitString&) const;
|
||||
int contains(const BitSubString&) const;
|
||||
int contains(const BitPattern&) const;
|
||||
|
||||
int contains(const BitString&, int pos) const;
|
||||
int contains(const BitSubString&, int pos) const;
|
||||
int contains(const BitPattern&, int pos) const;
|
||||
|
||||
int matches(const BitString&, int pos = 0) const;
|
||||
int matches(const BitSubString&, int pos = 0) const;
|
||||
int matches(const BitPattern&, int pos = 0) const;
|
||||
|
||||
// BitSubString extraction
|
||||
|
||||
BitSubString at(int pos, int len);
|
||||
BitSubString at(const BitString&, int startpos = 0);
|
||||
BitSubString at(const BitSubString&, int startpos = 0);
|
||||
BitSubString at(const BitPattern&, int startpos = 0);
|
||||
|
||||
BitSubString before(int pos);
|
||||
BitSubString before(const BitString&, int startpos = 0);
|
||||
BitSubString before(const BitSubString&, int startpos = 0);
|
||||
BitSubString before(const BitPattern&, int startpos = 0);
|
||||
|
||||
BitSubString after(int pos);
|
||||
BitSubString after(const BitString&, int startpos = 0);
|
||||
BitSubString after(const BitSubString&, int startpos = 0);
|
||||
BitSubString after(const BitPattern&, int startpos = 0);
|
||||
|
||||
// other friends & utilities
|
||||
|
||||
friend BitString common_prefix(const BitString&, const BitString&,
|
||||
int pos = 0);
|
||||
friend BitString common_suffix(const BitString&, const BitString&,
|
||||
int pos = -1);
|
||||
friend BitString reverse(const BitString&);
|
||||
|
||||
void right_trim(unsigned int bit);
|
||||
void left_trim(unsigned int bit);
|
||||
|
||||
// status
|
||||
|
||||
int empty() const ;
|
||||
int count(unsigned int bit = 1) const;
|
||||
int length() const;
|
||||
|
||||
// convertors & IO
|
||||
|
||||
friend BitString atoBitString(const char* s, char f='0', char t='1');
|
||||
// BitStringtoa is deprecated; do not use in new programs!
|
||||
friend const char* BitStringtoa(const BitString&, char f='0', char t='1');
|
||||
void printon(ostream&, char f='0', char t='1') const;
|
||||
|
||||
friend BitString shorttoBitString(unsigned short);
|
||||
friend BitString longtoBitString(unsigned long);
|
||||
|
||||
friend ostream& operator << (ostream& s, const BitString&);
|
||||
|
||||
// misc
|
||||
|
||||
void error(const char* msg) const;
|
||||
|
||||
// indirect friends
|
||||
|
||||
friend BitPattern atoBitPattern(const char* s,
|
||||
char f='0',char t='1',char x='X');
|
||||
friend const char* BitPatterntoa(const BitPattern& p,
|
||||
char f='0',char t='1',char x='X');
|
||||
int OK() const;
|
||||
};
|
||||
|
||||
|
||||
class BitPattern
|
||||
{
|
||||
public:
|
||||
BitString pattern;
|
||||
BitString mask;
|
||||
|
||||
BitPattern();
|
||||
BitPattern(const BitPattern&);
|
||||
BitPattern(const BitString& p, const BitString& m);
|
||||
|
||||
~BitPattern();
|
||||
|
||||
friend const char* BitPatterntoa(const BitPattern& p,
|
||||
char f/*='0'*/,char t/*='1'*/,char x/*='X'*/);
|
||||
void printon(ostream&, char f='0',char t='1',char x='X') const;
|
||||
friend BitPattern atoBitPattern(const char* s, char f,char t, char x);
|
||||
friend ostream& operator << (ostream& s, const BitPattern&);
|
||||
|
||||
int search(const _BS_word*, int, int) const;
|
||||
int match(const _BS_word* xs, int, int, int) const;
|
||||
|
||||
int OK() const;
|
||||
};
|
||||
|
||||
BitString operator & (const BitString& x, const BitString& y);
|
||||
BitString operator | (const BitString& x, const BitString& y);
|
||||
BitString operator ^ (const BitString& x, const BitString& y);
|
||||
BitString operator << (const BitString& x, int y);
|
||||
BitString operator >> (const BitString& x, int y);
|
||||
BitString operator - (const BitString& x, const BitString& y);
|
||||
BitString operator + (const BitString& x, const BitString& y);
|
||||
BitString operator + (const BitString& x, unsigned int y);
|
||||
BitString operator ~ (const BitString& x);
|
||||
int operator != (const BitString& x, const BitString& y);
|
||||
int operator>(const BitString& x, const BitString& y);
|
||||
int operator>=(const BitString& x, const BitString& y);
|
||||
|
||||
extern BitStrRep _nilBitStrRep;
|
||||
extern BitString _nil_BitString;
|
||||
|
||||
// primitive bit extraction
|
||||
|
||||
// These must be inlined regardless of optimization.
|
||||
|
||||
inline int BitStr_index(int l) { return (unsigned)(l) / BITSTRBITS; }
|
||||
|
||||
inline int BitStr_pos(int l) { return l & (BITSTRBITS - 1); }
|
||||
|
||||
|
||||
// constructors & assignment
|
||||
|
||||
inline BitString::BitString() :rep(&_nilBitStrRep) {}
|
||||
|
||||
inline BitString::BitString(const BitString& x) :rep(BStr_copy(0, x.rep)) {}
|
||||
|
||||
inline BitString::BitString(const BitSubString& y)
|
||||
:rep (BStr_alloc(0, y.S.rep->s, y.pos, y.pos+y.len, y.len)) {}
|
||||
|
||||
inline BitString::~BitString()
|
||||
{
|
||||
if (rep != &_nilBitStrRep) delete rep;
|
||||
}
|
||||
|
||||
inline BitString shorttoBitString(unsigned short w)
|
||||
{
|
||||
BitString r;
|
||||
_BS_word ww = w;
|
||||
#if _BS_BIGENDIAN
|
||||
abort();
|
||||
#endif
|
||||
r.rep = BStr_alloc(0, &ww, 0, 8 * sizeof(short), 8 * sizeof(short));
|
||||
return r;
|
||||
}
|
||||
|
||||
inline BitString longtoBitString(unsigned long w)
|
||||
{
|
||||
BitString r;
|
||||
#if 1
|
||||
_BS_word u = w;
|
||||
r.rep = BStr_alloc(0, &u, 0, BITSTRBITS, BITSTRBITS);
|
||||
#else
|
||||
unsigned short u[2];
|
||||
u[0] = w & ((unsigned short)(~(0)));
|
||||
u[1] = w >> BITSTRBITS;
|
||||
r.rep = BStr_alloc(0, &u[0], 0, 2*BITSTRBITS, 2*BITSTRBITS);
|
||||
#endif
|
||||
return r;
|
||||
}
|
||||
|
||||
inline BitString& BitString::operator = (const BitString& y)
|
||||
{
|
||||
rep = BStr_copy(rep, y.rep);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline BitString& BitString::operator = (unsigned int b)
|
||||
{
|
||||
_BS_word bit = b;
|
||||
rep = BStr_alloc(rep, &bit, 0, 1, 1);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline BitString& BitString::operator=(const BitSubString& y)
|
||||
{
|
||||
rep = BStr_alloc(rep, y.S.rep->s, y.pos, y.pos+y.len, y.len);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline BitSubString::BitSubString(const BitSubString& x)
|
||||
:S(x.S), pos(x.pos), len(x.len) {}
|
||||
|
||||
inline BitSubString::BitSubString(BitString& x, int p, int l)
|
||||
: S(x), pos(p), len(l) {}
|
||||
|
||||
inline BitSubString::~BitSubString() {}
|
||||
|
||||
inline BitPattern::BitPattern(const BitString& p, const BitString& m)
|
||||
:pattern(p), mask(m) {}
|
||||
|
||||
inline BitPattern::BitPattern(const BitPattern& b)
|
||||
:pattern(b.pattern), mask(b.mask) {}
|
||||
|
||||
inline BitPattern::BitPattern() {}
|
||||
inline BitPattern::~BitPattern() {}
|
||||
|
||||
|
||||
// procedural versions of operators
|
||||
|
||||
inline void and(const BitString& x, const BitString& y, BitString& r)
|
||||
{
|
||||
r.rep = and(x.rep, y.rep, r.rep);
|
||||
}
|
||||
|
||||
inline void or(const BitString& x, const BitString& y, BitString& r)
|
||||
{
|
||||
r.rep = or(x.rep, y.rep, r.rep);
|
||||
}
|
||||
|
||||
inline void xor(const BitString& x, const BitString& y, BitString& r)
|
||||
{
|
||||
r.rep = xor(x.rep, y.rep, r.rep);
|
||||
}
|
||||
|
||||
inline void diff(const BitString& x, const BitString& y, BitString& r)
|
||||
{
|
||||
r.rep = diff(x.rep, y.rep, r.rep);
|
||||
}
|
||||
|
||||
inline void cat(const BitString& x, const BitString& y, BitString& r)
|
||||
{
|
||||
r.rep = cat(x.rep, y.rep, r.rep);
|
||||
}
|
||||
|
||||
inline void cat(const BitString& x, unsigned int y, BitString& r)
|
||||
{
|
||||
r.rep = cat(x.rep, y, r.rep);
|
||||
}
|
||||
|
||||
inline void rshift(const BitString& x, int y, BitString& r)
|
||||
{
|
||||
r.rep = lshift(x.rep, -y, r.rep);
|
||||
}
|
||||
|
||||
inline void lshift(const BitString& x, int y, BitString& r)
|
||||
{
|
||||
r.rep = lshift(x.rep, y, r.rep);
|
||||
}
|
||||
|
||||
inline void complement(const BitString& x, BitString& r)
|
||||
{
|
||||
r.rep = cmpl(x.rep, r.rep);
|
||||
}
|
||||
|
||||
// operators
|
||||
|
||||
|
||||
inline BitString& BitString::operator &= (const BitString& y)
|
||||
{
|
||||
and(*this, y, *this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline BitString& BitString::operator |= (const BitString& y)
|
||||
{
|
||||
or(*this, y, *this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline BitString& BitString::operator ^= (const BitString& y)
|
||||
{
|
||||
xor(*this, y, *this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline BitString& BitString::operator <<= (int y)
|
||||
{
|
||||
lshift(*this, y, *this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline BitString& BitString::operator >>= (int y)
|
||||
{
|
||||
rshift(*this, y, *this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline BitString& BitString::operator -= (const BitString& y)
|
||||
{
|
||||
diff(*this, y, *this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline BitString& BitString::operator += (const BitString& y)
|
||||
{
|
||||
cat(*this, y, *this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline BitString& BitString::operator += (unsigned int y)
|
||||
{
|
||||
cat(*this, y, *this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void BitString::complement()
|
||||
{
|
||||
::complement(*this, *this);
|
||||
}
|
||||
|
||||
#if defined(__GNUG__) && !defined(_G_NO_NRV)
|
||||
|
||||
inline BitString operator & (const BitString& x, const BitString& y) return r
|
||||
{
|
||||
and(x, y, r);
|
||||
}
|
||||
|
||||
inline BitString operator | (const BitString& x, const BitString& y) return r
|
||||
{
|
||||
or(x, y, r);
|
||||
}
|
||||
|
||||
inline BitString operator ^ (const BitString& x, const BitString& y) return r
|
||||
{
|
||||
xor(x, y, r);
|
||||
}
|
||||
|
||||
inline BitString operator << (const BitString& x, int y) return r
|
||||
{
|
||||
lshift(x, y, r);
|
||||
}
|
||||
|
||||
inline BitString operator >> (const BitString& x, int y) return r
|
||||
{
|
||||
rshift(x, y, r);
|
||||
}
|
||||
|
||||
inline BitString operator - (const BitString& x, const BitString& y) return r
|
||||
{
|
||||
diff(x, y, r);
|
||||
}
|
||||
|
||||
inline BitString operator + (const BitString& x, const BitString& y) return r
|
||||
{
|
||||
cat(x, y, r);
|
||||
}
|
||||
|
||||
inline BitString operator + (const BitString& x, unsigned int y) return r
|
||||
{
|
||||
cat(x, y, r);
|
||||
}
|
||||
|
||||
inline BitString operator ~ (const BitString& x) return r
|
||||
{
|
||||
complement(x, r);
|
||||
}
|
||||
|
||||
#else /* NO_NRV */
|
||||
|
||||
inline BitString operator & (const BitString& x, const BitString& y)
|
||||
{
|
||||
BitString r; and(x, y, r); return r;
|
||||
}
|
||||
|
||||
inline BitString operator | (const BitString& x, const BitString& y)
|
||||
{
|
||||
BitString r; or(x, y, r); return r;
|
||||
}
|
||||
|
||||
inline BitString operator ^ (const BitString& x, const BitString& y)
|
||||
{
|
||||
BitString r; xor(x, y, r); return r;
|
||||
}
|
||||
|
||||
inline BitString operator << (const BitString& x, int y)
|
||||
{
|
||||
BitString r; lshift(x, y, r); return r;
|
||||
}
|
||||
|
||||
inline BitString operator >> (const BitString& x, int y)
|
||||
{
|
||||
BitString r; rshift(x, y, r); return r;
|
||||
}
|
||||
|
||||
inline BitString operator - (const BitString& x, const BitString& y)
|
||||
{
|
||||
BitString r; diff(x, y, r); return r;
|
||||
}
|
||||
|
||||
inline BitString operator + (const BitString& x, const BitString& y)
|
||||
{
|
||||
BitString r; cat(x, y, r); return r;
|
||||
}
|
||||
|
||||
inline BitString operator + (const BitString& x, unsigned int y)
|
||||
{
|
||||
BitString r; cat(x, y, r); return r;
|
||||
}
|
||||
|
||||
inline BitString operator ~ (const BitString& x)
|
||||
{
|
||||
BitString r; complement(x, r); return r;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// status, matching
|
||||
|
||||
inline int BitString::length() const
|
||||
{
|
||||
return rep->len;
|
||||
}
|
||||
|
||||
inline int BitString::empty() const
|
||||
{
|
||||
return rep->len == 0;
|
||||
}
|
||||
|
||||
inline int BitString::index(const BitString& y, int startpos) const
|
||||
{
|
||||
return search(startpos, rep->len, y.rep->s, 0, y.rep->len);
|
||||
}
|
||||
|
||||
inline int BitString::index(const BitSubString& y, int startpos) const
|
||||
{
|
||||
return search(startpos, rep->len, y.S.rep->s, y.pos, y.pos+y.len);
|
||||
}
|
||||
|
||||
inline int BitString::contains(const BitString& y) const
|
||||
{
|
||||
return search(0, rep->len, y.rep->s, 0, y.rep->len) >= 0;
|
||||
}
|
||||
|
||||
inline int BitString::contains(const BitSubString& y) const
|
||||
{
|
||||
return search(0, rep->len, y.S.rep->s, y.pos, y.pos+y.len) >= 0;
|
||||
}
|
||||
|
||||
inline int BitString::contains(const BitString& y, int p) const
|
||||
{
|
||||
return match(p, rep->len, 0, y.rep->s, 0, y.rep->len);
|
||||
}
|
||||
|
||||
inline int BitString::matches(const BitString& y, int p) const
|
||||
{
|
||||
return match(p, rep->len, 1, y.rep->s, 0, y.rep->len);
|
||||
}
|
||||
|
||||
inline int BitString::contains(const BitSubString& y, int p) const
|
||||
{
|
||||
return match(p, rep->len, 0, y.S.rep->s, y.pos, y.pos+y.len);
|
||||
}
|
||||
|
||||
inline int BitString::matches(const BitSubString& y, int p) const
|
||||
{
|
||||
return match(p, rep->len, 1, y.S.rep->s, y.pos, y.pos+y.len);
|
||||
}
|
||||
|
||||
inline int BitString::contains(const BitPattern& r) const
|
||||
{
|
||||
return r.search(rep->s, 0, rep->len) >= 0;
|
||||
}
|
||||
|
||||
inline int BitString::contains(const BitPattern& r, int p) const
|
||||
{
|
||||
return r.match(rep->s, p, rep->len, 0);
|
||||
}
|
||||
|
||||
inline int BitString::matches(const BitPattern& r, int p) const
|
||||
{
|
||||
return r.match(rep->s, p, rep->len, 1);
|
||||
}
|
||||
|
||||
inline int BitString::index(const BitPattern& r, int startpos) const
|
||||
{
|
||||
return r.search(rep->s, startpos, rep->len);
|
||||
}
|
||||
|
||||
inline int BitSubString::length() const
|
||||
{
|
||||
return len;
|
||||
}
|
||||
|
||||
inline int BitSubString::empty() const
|
||||
{
|
||||
return len == 0;
|
||||
}
|
||||
|
||||
inline int operator != (const BitString& x, const BitString& y)
|
||||
{
|
||||
return !(x == y);
|
||||
}
|
||||
|
||||
inline int operator>(const BitString& x, const BitString& y)
|
||||
{
|
||||
return y < x;
|
||||
}
|
||||
|
||||
inline int operator>=(const BitString& x, const BitString& y)
|
||||
{
|
||||
return y <= x;
|
||||
}
|
||||
|
||||
inline int BitString::first(unsigned int b) const
|
||||
{
|
||||
return next(-1, b);
|
||||
}
|
||||
|
||||
inline int BitString::last(unsigned int b) const
|
||||
{
|
||||
return prev(rep->len, b);
|
||||
}
|
||||
|
||||
inline int BitString::index(unsigned int bit, int startpos) const
|
||||
{
|
||||
if (startpos >= 0)
|
||||
return next(startpos - 1, bit);
|
||||
else
|
||||
return prev(rep->len + startpos + 1, bit);
|
||||
}
|
||||
|
||||
inline void BitString::right_trim(unsigned int b)
|
||||
{
|
||||
int nb = (b == 0)? 1 : 0;
|
||||
rep = BStr_resize(rep, prev(rep->len, nb) + 1);
|
||||
}
|
||||
|
||||
inline void BitString::left_trim(unsigned int b)
|
||||
{
|
||||
int nb = (b == 0)? 1 : 0;
|
||||
int p = next(-1, nb);
|
||||
rep = BStr_alloc(rep, rep->s, p, rep->len, rep->len - p);
|
||||
}
|
||||
|
||||
inline int BitString::test(int i) const
|
||||
{
|
||||
return ((unsigned)(i) >= rep->len)? 0 :
|
||||
((rep->s[BitStr_index(i)] & (1 << (BitStr_pos(i)))) != 0);
|
||||
}
|
||||
|
||||
|
||||
// subscripting
|
||||
|
||||
inline BitStrBit::BitStrBit(const BitStrBit& b) :src(b.src), pos(b.pos) {}
|
||||
|
||||
inline BitStrBit::BitStrBit(BitString& v, int p) :src(v), pos(p) {}
|
||||
|
||||
inline BitStrBit::~BitStrBit() {}
|
||||
|
||||
inline BitStrBit::operator unsigned int() const
|
||||
{
|
||||
return src.test(pos);
|
||||
}
|
||||
|
||||
inline int BitStrBit::operator = (unsigned int b)
|
||||
{
|
||||
src.assign(pos, b); return b;
|
||||
}
|
||||
|
||||
inline BitStrBit BitString::operator [] (int i)
|
||||
{
|
||||
if ((unsigned)(i) >= rep->len) error("illegal bit index");
|
||||
return BitStrBit(*this, i);
|
||||
}
|
||||
|
||||
inline BitSubString BitString::_substr(int first, int l)
|
||||
{
|
||||
if (first < 0 || l <= 0 || (unsigned)(first + l) > rep->len)
|
||||
return BitSubString(_nil_BitString, 0, 0) ;
|
||||
else
|
||||
return BitSubString(*this, first, l);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,249 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Doug Lea (dl@rocky.oswego.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef _Complex_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define _Complex_h 1
|
||||
|
||||
|
||||
#include <iostream.h>
|
||||
#include <math.h>
|
||||
|
||||
class Complex
|
||||
{
|
||||
#ifdef __ATT_complex__
|
||||
public:
|
||||
#else
|
||||
protected:
|
||||
#endif
|
||||
|
||||
double re;
|
||||
double im;
|
||||
|
||||
public:
|
||||
|
||||
double real() const;
|
||||
double imag() const;
|
||||
|
||||
Complex();
|
||||
Complex(const Complex& y);
|
||||
Complex(double r, double i=0);
|
||||
|
||||
~Complex();
|
||||
|
||||
Complex& operator = (const Complex& y);
|
||||
|
||||
Complex& operator += (const Complex& y);
|
||||
Complex& operator += (double y);
|
||||
Complex& operator -= (const Complex& y);
|
||||
Complex& operator -= (double y);
|
||||
Complex& operator *= (const Complex& y);
|
||||
Complex& operator *= (double y);
|
||||
|
||||
Complex& operator /= (const Complex& y);
|
||||
Complex& operator /= (double y);
|
||||
|
||||
void error(const char* msg) const;
|
||||
};
|
||||
|
||||
|
||||
// non-inline functions
|
||||
|
||||
Complex operator / (const Complex& x, const Complex& y);
|
||||
Complex operator / (const Complex& x, double y);
|
||||
Complex operator / (double x, const Complex& y);
|
||||
|
||||
Complex cos(const Complex& x);
|
||||
Complex sin(const Complex& x);
|
||||
|
||||
Complex cosh(const Complex& x);
|
||||
Complex sinh(const Complex& x);
|
||||
|
||||
Complex exp(const Complex& x);
|
||||
Complex log(const Complex& x);
|
||||
|
||||
Complex pow(const Complex& x, int p);
|
||||
Complex pow(const Complex& x, const Complex& p);
|
||||
Complex pow(const Complex& x, double y);
|
||||
Complex sqrt(const Complex& x);
|
||||
|
||||
istream& operator >> (istream& s, Complex& x);
|
||||
ostream& operator << (ostream& s, const Complex& x);
|
||||
|
||||
|
||||
// inline members
|
||||
|
||||
inline double Complex::real() const { return re; }
|
||||
inline double Complex::imag() const { return im; }
|
||||
|
||||
inline Complex::Complex() {}
|
||||
inline Complex::Complex(const Complex& y) :re(y.real()), im(y.imag()) {}
|
||||
inline Complex::Complex(double r, double i) :re(r), im(i) {}
|
||||
|
||||
inline Complex::~Complex() {}
|
||||
|
||||
inline Complex& Complex::operator = (const Complex& y)
|
||||
{
|
||||
re = y.real(); im = y.imag(); return *this;
|
||||
}
|
||||
|
||||
inline Complex& Complex::operator += (const Complex& y)
|
||||
{
|
||||
re += y.real(); im += y.imag(); return *this;
|
||||
}
|
||||
|
||||
inline Complex& Complex::operator += (double y)
|
||||
{
|
||||
re += y; return *this;
|
||||
}
|
||||
|
||||
inline Complex& Complex::operator -= (const Complex& y)
|
||||
{
|
||||
re -= y.real(); im -= y.imag(); return *this;
|
||||
}
|
||||
|
||||
inline Complex& Complex::operator -= (double y)
|
||||
{
|
||||
re -= y; return *this;
|
||||
}
|
||||
|
||||
inline Complex& Complex::operator *= (const Complex& y)
|
||||
{
|
||||
double r = re * y.real() - im * y.imag();
|
||||
im = re * y.imag() + im * y.real();
|
||||
re = r;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Complex& Complex::operator *= (double y)
|
||||
{
|
||||
re *= y; im *= y; return *this;
|
||||
}
|
||||
|
||||
|
||||
// functions
|
||||
|
||||
inline int operator == (const Complex& x, const Complex& y)
|
||||
{
|
||||
return x.real() == y.real() && x.imag() == y.imag();
|
||||
}
|
||||
|
||||
inline int operator == (const Complex& x, double y)
|
||||
{
|
||||
return x.imag() == 0.0 && x.real() == y;
|
||||
}
|
||||
|
||||
inline int operator != (const Complex& x, const Complex& y)
|
||||
{
|
||||
return x.real() != y.real() || x.imag() != y.imag();
|
||||
}
|
||||
|
||||
inline int operator != (const Complex& x, double y)
|
||||
{
|
||||
return x.imag() != 0.0 || x.real() != y;
|
||||
}
|
||||
|
||||
inline Complex operator - (const Complex& x)
|
||||
{
|
||||
return Complex(-x.real(), -x.imag());
|
||||
}
|
||||
|
||||
inline Complex conj(const Complex& x)
|
||||
{
|
||||
return Complex(x.real(), -x.imag());
|
||||
}
|
||||
|
||||
inline Complex operator + (const Complex& x, const Complex& y)
|
||||
{
|
||||
return Complex(x.real() + y.real(), x.imag() + y.imag());
|
||||
}
|
||||
|
||||
inline Complex operator + (const Complex& x, double y)
|
||||
{
|
||||
return Complex(x.real() + y, x.imag());
|
||||
}
|
||||
|
||||
inline Complex operator + (double x, const Complex& y)
|
||||
{
|
||||
return Complex(x + y.real(), y.imag());
|
||||
}
|
||||
|
||||
inline Complex operator - (const Complex& x, const Complex& y)
|
||||
{
|
||||
return Complex(x.real() - y.real(), x.imag() - y.imag());
|
||||
}
|
||||
|
||||
inline Complex operator - (const Complex& x, double y)
|
||||
{
|
||||
return Complex(x.real() - y, x.imag());
|
||||
}
|
||||
|
||||
inline Complex operator - (double x, const Complex& y)
|
||||
{
|
||||
return Complex(x - y.real(), -y.imag());
|
||||
}
|
||||
|
||||
inline Complex operator * (const Complex& x, const Complex& y)
|
||||
{
|
||||
return Complex(x.real() * y.real() - x.imag() * y.imag(),
|
||||
x.real() * y.imag() + x.imag() * y.real());
|
||||
}
|
||||
|
||||
inline Complex operator * (const Complex& x, double y)
|
||||
{
|
||||
return Complex(x.real() * y, x.imag() * y);
|
||||
}
|
||||
|
||||
inline Complex operator * (double x, const Complex& y)
|
||||
{
|
||||
return Complex(x * y.real(), x * y.imag());
|
||||
}
|
||||
|
||||
inline double real(const Complex& x)
|
||||
{
|
||||
return x.real();
|
||||
}
|
||||
|
||||
inline double imag(const Complex& x)
|
||||
{
|
||||
return x.imag();
|
||||
}
|
||||
|
||||
inline double abs(const Complex& x)
|
||||
{
|
||||
return hypot(x.real(), x.imag());
|
||||
}
|
||||
|
||||
inline double norm(const Complex& x)
|
||||
{
|
||||
return (x.real() * x.real() + x.imag() * x.imag());
|
||||
}
|
||||
|
||||
inline double arg(const Complex& x)
|
||||
{
|
||||
return atan2(x.imag(), x.real());
|
||||
}
|
||||
|
||||
inline Complex polar(double r, double t)
|
||||
{
|
||||
return Complex(r * cos(t), r * sin(t));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,595 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
|
||||
/*
|
||||
Copyright (C) 1989 Free Software Foundation
|
||||
written by Eric Newton (newton@rocky.oswego.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef _CursesWindow_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define _CursesWindow_h
|
||||
|
||||
#include <_G_config.h>
|
||||
#if _G_HAVE_CURSES
|
||||
// Even many system which mostly have C++-ready header files,
|
||||
// do not have C++-ready curses.h.
|
||||
extern "C" {
|
||||
#include <curses.h>
|
||||
}
|
||||
|
||||
/* SCO 3.2v4 curses.h includes term.h, which defines lines as a macro.
|
||||
Undefine it here, because CursesWindow uses lines as a method. */
|
||||
#undef lines
|
||||
|
||||
// "Convert" macros to inlines, if needed.
|
||||
#ifdef addch
|
||||
inline int (addch)(char ch) { return addch(ch); }
|
||||
#undef addch
|
||||
#endif
|
||||
#ifdef addstr
|
||||
/* The (char*) cast is to hack around missing const's */
|
||||
inline int (addstr)(const char * str) { return addstr((char*)str); }
|
||||
#undef addstr
|
||||
#endif
|
||||
#ifdef clear
|
||||
inline int (clear)() { return clear(); }
|
||||
#undef clear
|
||||
#endif
|
||||
#ifdef clearok
|
||||
inline int (clearok)(WINDOW* win, int bf) { return clearok(win, bf); }
|
||||
#undef clearok
|
||||
#else
|
||||
extern "C" int clearok(WINDOW*, int);
|
||||
#endif
|
||||
#ifdef clrtobot
|
||||
inline int (clrtobot)() { return clrtobot(); }
|
||||
#undef clrtobot
|
||||
#endif
|
||||
#ifdef clrtoeol
|
||||
inline int (clrtoeol)() { return clrtoeol(); }
|
||||
#undef clrtoeol
|
||||
#endif
|
||||
#ifdef delch
|
||||
inline int (delch)() { return delch(); }
|
||||
#undef delch
|
||||
#endif
|
||||
#ifdef deleteln
|
||||
inline int (deleteln)() { return deleteln(); }
|
||||
#undef deleteln
|
||||
#endif
|
||||
#ifdef erase
|
||||
inline int (erase)() { return erase(); }
|
||||
#undef erase
|
||||
#endif
|
||||
#ifdef flushok
|
||||
inline int (flushok)(WINDOW* _win, int _bf) { return flushok(_win, _bf); }
|
||||
#undef flushok
|
||||
#else
|
||||
#define _no_flushok
|
||||
#endif
|
||||
#ifdef getch
|
||||
inline int (getch)() { return getch(); }
|
||||
#undef getch
|
||||
#endif
|
||||
#ifdef getstr
|
||||
inline int (getstr)(char *_str) { return getstr(_str); }
|
||||
#undef getstr
|
||||
#endif
|
||||
#ifdef getyx
|
||||
inline void (getyx)(WINDOW* win, int& y, int& x) { getyx(win, y, x); }
|
||||
#undef getyx
|
||||
#endif
|
||||
#ifdef inch
|
||||
inline int (inch)() { return inch(); }
|
||||
#undef inch
|
||||
#endif
|
||||
#ifdef insch
|
||||
inline int (insch)(char c) { return insch(c); }
|
||||
#undef insch
|
||||
#endif
|
||||
#ifdef insertln
|
||||
inline int (insertln)() { return insertln(); }
|
||||
#undef insertln
|
||||
#endif
|
||||
#ifdef leaveok
|
||||
inline int (leaveok)(WINDOW* win, int bf) { return leaveok(win, bf); }
|
||||
#undef leaveok
|
||||
#else
|
||||
extern "C" int leaveok(WINDOW* win, int bf);
|
||||
#endif
|
||||
#ifdef move
|
||||
inline int (move)(int x, int y) { return move(x, y); }
|
||||
#undef move
|
||||
#endif
|
||||
#ifdef refresh
|
||||
inline int (rfresh)() { return refresh(); }
|
||||
#undef refresh
|
||||
#endif
|
||||
#ifdef scrollok
|
||||
inline int (scrollok)(WINDOW* win, int bf) { return scrollok(win, bf); }
|
||||
#undef scrollok
|
||||
#else
|
||||
#ifndef hpux
|
||||
extern "C" int scrollok(WINDOW*, int);
|
||||
#else
|
||||
extern "C" int scrollok(WINDOW*, char);
|
||||
#endif
|
||||
#endif
|
||||
#ifdef standend
|
||||
inline int (standend)() { return standend(); }
|
||||
#undef standend
|
||||
#endif
|
||||
#ifdef standout
|
||||
inline int (standout)() { return standout(); }
|
||||
#undef standout
|
||||
#endif
|
||||
#ifdef wstandend
|
||||
inline int (wstandend)(WINDOW *win) { return wstandend(win); }
|
||||
#undef wstandend
|
||||
#endif
|
||||
#ifdef wstandout
|
||||
inline int (wstandout)(WINDOW *win) { return wstandout(win); }
|
||||
#undef wstandout
|
||||
#endif
|
||||
#ifdef winch
|
||||
inline int (winch)(WINDOW* win) { return winch(win); }
|
||||
#undef winch
|
||||
#endif
|
||||
|
||||
/* deal with conflicting macros in ncurses.h which is SYSV based*/
|
||||
#ifdef box
|
||||
inline _G_box(WINDOW* win, chtype v, chtype h) {return box(win, v, h); }
|
||||
#undef box
|
||||
inline box(WINDOW* win, chtype v, chtype h) {return _G_box(win, v, h); }
|
||||
#endif
|
||||
#ifdef scroll
|
||||
inline (scroll)(WINDOW* win) { return scroll(win); }
|
||||
#undef scroll
|
||||
#endif
|
||||
#ifdef touchwin
|
||||
inline (touchwin)(WINDOW* win) { return touchwin(win); }
|
||||
#undef touchwin
|
||||
#endif
|
||||
|
||||
#ifdef mvwaddch
|
||||
inline int (mvwaddch)(WINDOW *win, int y, int x, char ch)
|
||||
{ return mvwaddch(win, y, x, ch); }
|
||||
#undef mvwaddch
|
||||
#endif
|
||||
#ifdef mvwaddstr
|
||||
inline int (mvwaddstr)(WINDOW *win, int y, int x, const char * str)
|
||||
{ return mvwaddstr(win, y, x, (char*)str); }
|
||||
#undef mvwaddstr
|
||||
#endif
|
||||
#ifdef mvwdelch
|
||||
inline int (mvwdelch)(WINDOW *win, int y, int x) { return mvwdelch(win, y, x);}
|
||||
#undef mvwdelch
|
||||
#endif
|
||||
#ifdef mvwgetch
|
||||
inline int (mvwgetch)(WINDOW *win, int y, int x) { return mvwgetch(win, y, x);}
|
||||
#undef mvwgetch
|
||||
#endif
|
||||
#ifdef mvwgetstr
|
||||
inline int (mvwgetstr)(WINDOW *win, int y, int x, char *str)
|
||||
{return mvwgetstr(win,y,x, str);}
|
||||
#undef mvwgetstr
|
||||
#endif
|
||||
#ifdef mvwinch
|
||||
inline int (mvwinch)(WINDOW *win, int y, int x) { return mvwinch(win, y, x);}
|
||||
#undef mvwinch
|
||||
#endif
|
||||
#ifdef mvwinsch
|
||||
inline int (mvwinsch)(WINDOW *win, int y, int x, char c)
|
||||
{ return mvwinsch(win, y, x, c); }
|
||||
#undef mvwinsch
|
||||
#endif
|
||||
|
||||
#ifdef mvaddch
|
||||
inline int (mvaddch)(int y, int x, char ch)
|
||||
{ return mvaddch(y, x, ch); }
|
||||
#undef mvaddch
|
||||
#endif
|
||||
#ifdef mvaddstr
|
||||
inline int (mvaddstr)(int y, int x, const char * str)
|
||||
{ return mvaddstr(y, x, (char*)str); }
|
||||
#undef mvaddstr
|
||||
#endif
|
||||
#ifdef mvdelch
|
||||
inline int (mvdelch)(int y, int x) { return mvdelch(y, x);}
|
||||
#undef mvdelch
|
||||
#endif
|
||||
#ifdef mvgetch
|
||||
inline int (mvgetch)(int y, int x) { return mvgetch(y, x);}
|
||||
#undef mvgetch
|
||||
#endif
|
||||
#ifdef mvgetstr
|
||||
inline int (mvgetstr)(int y, int x, char *str) {return mvgetstr(y, x, str);}
|
||||
#undef mvgetstr
|
||||
#endif
|
||||
#ifdef mvinch
|
||||
inline int (mvinch)(int y, int x) { return mvinch(y, x);}
|
||||
#undef mvinch
|
||||
#endif
|
||||
#ifdef mvinsch
|
||||
inline int (mvinsch)(int y, int x, char c)
|
||||
{ return mvinsch(y, x, c); }
|
||||
#undef mvinsch
|
||||
#endif
|
||||
|
||||
/*
|
||||
*
|
||||
* C++ class for windows.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class CursesWindow
|
||||
{
|
||||
protected:
|
||||
static int count; // count of all active windows:
|
||||
// We rely on the c++ promise that
|
||||
// all otherwise uninitialized
|
||||
// static class vars are set to 0
|
||||
|
||||
WINDOW * w; // the curses WINDOW
|
||||
|
||||
int alloced; // true if we own the WINDOW
|
||||
|
||||
CursesWindow* par; // parent, if subwindow
|
||||
CursesWindow* subwins; // head of subwindows list
|
||||
CursesWindow* sib; // next subwindow of parent
|
||||
|
||||
void kill_subwindows(); // disable all subwindows
|
||||
|
||||
public:
|
||||
CursesWindow(WINDOW* &window); // useful only for stdscr
|
||||
|
||||
CursesWindow(int lines, // number of lines
|
||||
int cols, // number of columns
|
||||
int begin_y, // line origin
|
||||
int begin_x); // col origin
|
||||
|
||||
CursesWindow(CursesWindow& par, // parent window
|
||||
int lines, // number of lines
|
||||
int cols, // number of columns
|
||||
int by, // absolute or relative
|
||||
int bx, // origins:
|
||||
char absrel = 'a'); // if `a', by & bx are
|
||||
// absolute screen pos,
|
||||
// else if `r', they are
|
||||
// relative to par origin
|
||||
~CursesWindow();
|
||||
|
||||
// terminal status
|
||||
int lines(); // number of lines on terminal, *not* window
|
||||
int cols(); // number of cols on terminal, *not* window
|
||||
|
||||
// window status
|
||||
int height(); // number of lines in this window
|
||||
int width(); // number of cols in this window
|
||||
int begx(); // smallest x coord in window
|
||||
int begy(); // smallest y coord in window
|
||||
int maxx(); // largest x coord in window
|
||||
int maxy(); // largest x coord in window
|
||||
|
||||
// window positioning
|
||||
int move(int y, int x);
|
||||
|
||||
// coordinate positioning
|
||||
void getyx(int& y, int& x);
|
||||
int mvcur(int sy, int ey, int sx, int ex);
|
||||
|
||||
// input
|
||||
int getch();
|
||||
int getstr(char * str);
|
||||
int scanw(const char *, ...);
|
||||
|
||||
// input + positioning
|
||||
int mvgetch(int y, int x);
|
||||
int mvgetstr(int y, int x, char * str);
|
||||
int mvscanw(int, int, const char*, ...);
|
||||
|
||||
// output
|
||||
int addch(const char ch);
|
||||
int addstr(const char * str);
|
||||
int printw(const char * fmt, ...);
|
||||
int inch();
|
||||
int insch(char c);
|
||||
int insertln();
|
||||
|
||||
// output + positioning
|
||||
int mvaddch(int y, int x, char ch);
|
||||
int mvaddstr(int y, int x, const char * str);
|
||||
int mvprintw(int y, int x, const char * fmt, ...);
|
||||
int mvinch(int y, int x);
|
||||
int mvinsch(int y, int x, char ch);
|
||||
|
||||
// borders
|
||||
int box(char vert, char hor);
|
||||
|
||||
// erasure
|
||||
int erase();
|
||||
int clear();
|
||||
int clearok(int bf);
|
||||
int clrtobot();
|
||||
int clrtoeol();
|
||||
int delch();
|
||||
int mvdelch(int y, int x);
|
||||
int deleteln();
|
||||
|
||||
// screen control
|
||||
int scroll();
|
||||
int scrollok(int bf);
|
||||
int touchwin();
|
||||
int refresh();
|
||||
int leaveok(int bf);
|
||||
#ifndef _no_flushok
|
||||
int flushok(int bf);
|
||||
#endif
|
||||
int standout();
|
||||
int standend();
|
||||
|
||||
// multiple window control
|
||||
int overlay(CursesWindow &win);
|
||||
int overwrite(CursesWindow &win);
|
||||
|
||||
|
||||
// traversal support
|
||||
CursesWindow* child();
|
||||
CursesWindow* sibling();
|
||||
CursesWindow* parent();
|
||||
};
|
||||
|
||||
|
||||
inline int CursesWindow::begx()
|
||||
{
|
||||
return w->_begx;
|
||||
}
|
||||
|
||||
inline int CursesWindow::begy()
|
||||
{
|
||||
return w->_begy;
|
||||
}
|
||||
|
||||
inline int CursesWindow::maxx()
|
||||
{
|
||||
return w->_maxx;
|
||||
}
|
||||
|
||||
inline int CursesWindow::maxy()
|
||||
{
|
||||
return w->_maxy;
|
||||
}
|
||||
|
||||
inline int CursesWindow::height()
|
||||
{
|
||||
return maxy() - begy() + 1;
|
||||
}
|
||||
|
||||
inline int CursesWindow::width()
|
||||
{
|
||||
return maxx() - begx() + 1;
|
||||
}
|
||||
|
||||
inline int CursesWindow::box(char vert, char hor)
|
||||
{
|
||||
return ::box(w, vert, hor);
|
||||
}
|
||||
|
||||
inline int CursesWindow::overlay(CursesWindow &win)
|
||||
{
|
||||
return ::overlay(w, win.w);
|
||||
}
|
||||
|
||||
inline int CursesWindow::overwrite(CursesWindow &win)
|
||||
{
|
||||
return ::overwrite(w, win.w);
|
||||
}
|
||||
|
||||
inline int CursesWindow::scroll()
|
||||
{
|
||||
return ::scroll(w);
|
||||
}
|
||||
|
||||
|
||||
inline int CursesWindow::touchwin()
|
||||
{
|
||||
return ::touchwin(w);
|
||||
}
|
||||
|
||||
inline int CursesWindow::addch(const char ch)
|
||||
{
|
||||
return ::waddch(w, ch);
|
||||
}
|
||||
|
||||
inline int CursesWindow::addstr(const char * str)
|
||||
{
|
||||
// The (char*) cast is to hack around prototypes in curses.h that
|
||||
// have const missing in the parameter lists. [E.g. SVR4]
|
||||
return ::waddstr(w, (char*)str);
|
||||
}
|
||||
|
||||
inline int CursesWindow::clear()
|
||||
{
|
||||
return ::wclear(w);
|
||||
}
|
||||
|
||||
inline int CursesWindow::clrtobot()
|
||||
{
|
||||
return ::wclrtobot(w);
|
||||
}
|
||||
|
||||
inline int CursesWindow::clrtoeol()
|
||||
{
|
||||
return ::wclrtoeol(w);
|
||||
}
|
||||
|
||||
inline int CursesWindow::delch()
|
||||
{
|
||||
return ::wdelch(w);
|
||||
}
|
||||
|
||||
inline int CursesWindow::deleteln()
|
||||
{
|
||||
return ::wdeleteln(w);
|
||||
}
|
||||
|
||||
inline int CursesWindow::erase()
|
||||
{
|
||||
return ::werase(w);
|
||||
}
|
||||
|
||||
inline int CursesWindow::getch()
|
||||
{
|
||||
return ::wgetch(w);
|
||||
}
|
||||
|
||||
inline int CursesWindow::getstr(char * str)
|
||||
{
|
||||
return ::wgetstr(w, str);
|
||||
}
|
||||
|
||||
inline int CursesWindow::inch()
|
||||
{
|
||||
return winch(w);
|
||||
}
|
||||
|
||||
inline int CursesWindow::insch(char c)
|
||||
{
|
||||
return ::winsch(w, c);
|
||||
}
|
||||
|
||||
inline int CursesWindow::insertln()
|
||||
{
|
||||
return ::winsertln(w);
|
||||
}
|
||||
|
||||
inline int CursesWindow::move(int y, int x)
|
||||
{
|
||||
return ::wmove(w, y, x);
|
||||
}
|
||||
|
||||
|
||||
inline int CursesWindow::mvcur(int sy, int ey, int sx, int ex)
|
||||
{
|
||||
return ::mvcur(sy, ey, sx,ex);
|
||||
}
|
||||
|
||||
inline int CursesWindow::mvaddch(int y, int x, char ch)
|
||||
{
|
||||
return (::wmove(w, y, x)==ERR) ? ERR : ::waddch(w, ch);
|
||||
}
|
||||
|
||||
inline int CursesWindow::mvgetch(int y, int x)
|
||||
{
|
||||
return (::wmove(w, y, x)==ERR) ? ERR : ::wgetch(w);
|
||||
}
|
||||
|
||||
inline int CursesWindow::mvaddstr(int y, int x, const char * str)
|
||||
{
|
||||
return (::wmove(w, y, x)==ERR) ? ERR : ::waddstr(w, (char*)str);
|
||||
}
|
||||
|
||||
inline int CursesWindow::mvgetstr(int y, int x, char * str)
|
||||
{
|
||||
return (::wmove(w, y, x)==ERR) ? ERR : ::wgetstr(w, str);
|
||||
}
|
||||
|
||||
inline int CursesWindow::mvinch(int y, int x)
|
||||
{
|
||||
return (::wmove(w, y, x)==ERR) ? ERR : ::winch(w);
|
||||
}
|
||||
|
||||
inline int CursesWindow::mvdelch(int y, int x)
|
||||
{
|
||||
return (::wmove(w, y, x)==ERR) ? ERR : ::wdelch(w);
|
||||
}
|
||||
|
||||
inline int CursesWindow::mvinsch(int y, int x, char ch)
|
||||
{
|
||||
return (::wmove(w, y, x)==ERR) ? ERR : ::winsch(w, ch);
|
||||
}
|
||||
|
||||
inline int CursesWindow::refresh()
|
||||
{
|
||||
return ::wrefresh(w);
|
||||
}
|
||||
|
||||
inline int CursesWindow::clearok(int bf)
|
||||
{
|
||||
return ::clearok(w,bf);
|
||||
}
|
||||
|
||||
inline int CursesWindow::leaveok(int bf)
|
||||
{
|
||||
return ::leaveok(w,bf);
|
||||
}
|
||||
|
||||
inline int CursesWindow::scrollok(int bf)
|
||||
{
|
||||
return ::scrollok(w,bf);
|
||||
}
|
||||
|
||||
#ifndef _no_flushok
|
||||
inline int CursesWindow::flushok(int bf)
|
||||
{
|
||||
return ::flushok(w, bf);
|
||||
}
|
||||
#endif
|
||||
|
||||
inline void CursesWindow::getyx(int& y, int& x)
|
||||
{
|
||||
::getyx(w, y, x);
|
||||
}
|
||||
|
||||
inline int CursesWindow::standout()
|
||||
{
|
||||
return ::wstandout(w);
|
||||
}
|
||||
|
||||
inline int CursesWindow::standend()
|
||||
{
|
||||
return ::wstandend(w);
|
||||
}
|
||||
|
||||
inline int CursesWindow::lines()
|
||||
{
|
||||
return LINES;
|
||||
}
|
||||
|
||||
inline int CursesWindow::cols()
|
||||
{
|
||||
return COLS;
|
||||
}
|
||||
|
||||
inline CursesWindow* CursesWindow::child()
|
||||
{
|
||||
return subwins;
|
||||
}
|
||||
|
||||
inline CursesWindow* CursesWindow::parent()
|
||||
{
|
||||
return par;
|
||||
}
|
||||
|
||||
inline CursesWindow* CursesWindow::sibling()
|
||||
{
|
||||
return sib;
|
||||
}
|
||||
|
||||
#endif /* _G_HAVE_CURSES */
|
||||
#endif
|
||||
|
|
@ -1,137 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Doug Lea (dl@rocky.oswego.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _DLList_h
|
||||
#ifdef __GNUG__
|
||||
//#pragma interface
|
||||
#endif
|
||||
#define _DLList_h 1
|
||||
|
||||
#include <Pix.h>
|
||||
|
||||
struct BaseDLNode {
|
||||
BaseDLNode *bk;
|
||||
BaseDLNode *fd;
|
||||
void *item() {return (void*)(this+1);} //Return ((DLNode<T>*)this)->hd
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class DLNode : public BaseDLNode
|
||||
{
|
||||
public:
|
||||
T hd;
|
||||
DLNode() { }
|
||||
DLNode(const T& h, DLNode* p = 0, DLNode* n = 0)
|
||||
: hd(h) { bk = p; fd = n; }
|
||||
~DLNode() { }
|
||||
};
|
||||
|
||||
class BaseDLList {
|
||||
protected:
|
||||
BaseDLNode *h;
|
||||
|
||||
BaseDLList() { h = 0; }
|
||||
void copy(const BaseDLList&);
|
||||
BaseDLList& operator= (const BaseDLList& a);
|
||||
virtual void delete_node(BaseDLNode*node) = 0;
|
||||
virtual BaseDLNode* copy_node(const void* datum) = 0;
|
||||
virtual void copy_item(void *dst, void *src) = 0;
|
||||
virtual ~BaseDLList() { }
|
||||
|
||||
Pix prepend(const void*);
|
||||
Pix append(const void*);
|
||||
Pix ins_after(Pix p, const void *datum);
|
||||
Pix ins_before(Pix p, const void *datum);
|
||||
void remove_front(void *dst);
|
||||
void remove_rear(void *dst);
|
||||
void join(BaseDLList&);
|
||||
|
||||
public:
|
||||
int empty() const { return h == 0; }
|
||||
int length() const;
|
||||
void clear();
|
||||
void error(const char* msg) const;
|
||||
int owns(Pix p) const;
|
||||
int OK() const;
|
||||
void del(Pix& p, int dir = 1);
|
||||
void del_after(Pix& p);
|
||||
void del_front();
|
||||
void del_rear();
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class DLList : public BaseDLList {
|
||||
//friend class <T>DLListTrav;
|
||||
|
||||
virtual void delete_node(BaseDLNode *node) { delete (DLNode<T>*)node; }
|
||||
virtual BaseDLNode* copy_node(const void *datum)
|
||||
{ return new DLNode<T>(*(const T*)datum); }
|
||||
virtual void copy_item(void *dst, void *src) { *(T*)dst = *(T*)src; }
|
||||
|
||||
public:
|
||||
DLList() : BaseDLList() { }
|
||||
DLList(const DLList<T>& a) : BaseDLList() { copy(a); }
|
||||
|
||||
DLList<T>& operator = (const DLList<T>& a)
|
||||
{ BaseDLList::operator=((const BaseDLList&) a); return *this; }
|
||||
virtual ~DLList() { clear(); }
|
||||
|
||||
Pix prepend(const T& item) {return BaseDLList::prepend(&item);}
|
||||
Pix append(const T& item) {return BaseDLList::append(&item);}
|
||||
|
||||
void join(DLList<T>& a) { BaseDLList::join(a); }
|
||||
|
||||
T& front() {
|
||||
if (h == 0) error("front: empty list");
|
||||
return ((DLNode<T>*)h)->hd; }
|
||||
T& rear() {
|
||||
if (h == 0) error("rear: empty list");
|
||||
return ((DLNode<T>*)h->bk)->hd;
|
||||
}
|
||||
const T& front() const {
|
||||
if (h == 0) error("front: empty list");
|
||||
return ((DLNode<T>*)h)->hd; }
|
||||
const T& rear() const {
|
||||
if (h == 0) error("rear: empty list");
|
||||
return ((DLNode<T>*)h->bk)->hd;
|
||||
}
|
||||
T remove_front() { T dst; BaseDLList::remove_front(&dst); return dst; }
|
||||
T remove_rear() { T dst; BaseDLList::remove_rear(&dst); return dst; }
|
||||
|
||||
T& operator () (Pix p) {
|
||||
if (p == 0) error("null Pix");
|
||||
return ((DLNode<T>*)p)->hd;
|
||||
}
|
||||
const T& operator () (Pix p) const {
|
||||
if (p == 0) error("null Pix");
|
||||
return ((DLNode<T>*)p)->hd;
|
||||
}
|
||||
Pix first() const { return Pix(h); }
|
||||
Pix last() const { return (h == 0) ? 0 : Pix(h->bk); }
|
||||
void next(Pix& p) const
|
||||
{ p = (p == 0 || p == h->bk)? 0 : Pix(((DLNode<T>*)p)->fd); }
|
||||
void prev(Pix& p) const
|
||||
{ p = (p == 0 || p == h)? 0 : Pix(((DLNode<T>*)p)->bk); }
|
||||
Pix ins_after(Pix p, const T& item)
|
||||
{return BaseDLList::ins_after(p, &item); }
|
||||
Pix ins_before(Pix p, const T& item)
|
||||
{return BaseDLList::ins_before(p, &item);}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Dirk Grunwald (grunwald@cs.uiuc.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifndef _DiscreteUniform_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define _DiscreteUniform_h 1
|
||||
|
||||
#include <Random.h>
|
||||
|
||||
//
|
||||
// The interval [lo..hi)
|
||||
//
|
||||
|
||||
class DiscreteUniform: public Random {
|
||||
long pLow;
|
||||
long pHigh;
|
||||
double delta;
|
||||
public:
|
||||
DiscreteUniform(long low, long high, RNG *gen);
|
||||
|
||||
long low();
|
||||
long low(long x);
|
||||
long high();
|
||||
long high(long x);
|
||||
|
||||
virtual double operator()();
|
||||
};
|
||||
|
||||
|
||||
inline DiscreteUniform::DiscreteUniform(long low, long high, RNG *gen)
|
||||
: Random(gen)
|
||||
{
|
||||
pLow = (low < high) ? low : high;
|
||||
pHigh = (low < high) ? high : low;
|
||||
delta = (pHigh - pLow) + 1;
|
||||
}
|
||||
|
||||
inline long DiscreteUniform::low() { return pLow; }
|
||||
|
||||
inline long DiscreteUniform::low(long x) {
|
||||
long tmp = pLow;
|
||||
pLow = x;
|
||||
delta = (pHigh - pLow) + 1;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
inline long DiscreteUniform::high() { return pHigh; }
|
||||
|
||||
inline long DiscreteUniform::high(long x) {
|
||||
long tmp = pHigh;
|
||||
pHigh = x;
|
||||
delta = (pHigh - pLow) + 1;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Dirk Grunwald (grunwald@cs.uiuc.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifndef _Erlang_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define _Erlang_h 1
|
||||
|
||||
#include <Random.h>
|
||||
|
||||
class Erlang: public Random {
|
||||
protected:
|
||||
double pMean;
|
||||
double pVariance;
|
||||
int k;
|
||||
double a;
|
||||
void setState();
|
||||
public:
|
||||
Erlang(double mean, double variance, RNG *gen);
|
||||
|
||||
double mean();
|
||||
double mean(double x);
|
||||
double variance();
|
||||
double variance(double x);
|
||||
|
||||
virtual double operator()();
|
||||
|
||||
};
|
||||
|
||||
|
||||
inline void Erlang::setState() {
|
||||
k = int( (pMean * pMean ) / pVariance + 0.5 );
|
||||
k = (k > 0) ? k : 1;
|
||||
a = k / pMean;
|
||||
}
|
||||
|
||||
inline Erlang::Erlang(double mean, double variance, RNG *gen) : Random(gen)
|
||||
{
|
||||
pMean = mean; pVariance = variance;
|
||||
setState();
|
||||
}
|
||||
|
||||
inline double Erlang::mean() { return pMean; }
|
||||
inline double Erlang::mean(double x) {
|
||||
double tmp = pMean; pMean = x; setState(); return tmp;
|
||||
};
|
||||
|
||||
inline double Erlang::variance() { return pVariance; }
|
||||
inline double Erlang::variance(double x) {
|
||||
double tmp = pVariance; pVariance = x; setState(); return tmp;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,513 +0,0 @@
|
|||
// -*- C++ -*-
|
||||
// Fix.h : variable length fixed point data type
|
||||
//
|
||||
|
||||
#ifndef _Fix_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define _Fix_h 1
|
||||
|
||||
#include <stream.h>
|
||||
#include <std.h>
|
||||
#include <stddef.h>
|
||||
#include <Integer.h>
|
||||
#include <builtin.h>
|
||||
|
||||
class Fix
|
||||
{
|
||||
struct Rep // internal Fix representation
|
||||
{
|
||||
_G_uint16_t len; // length in bits
|
||||
_G_uint16_t siz; // allocated storage
|
||||
_G_int16_t ref; // reference count
|
||||
_G_uint16_t s[1]; // start of ushort array represention
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
typedef void (*PEH)(Rep*);
|
||||
|
||||
private:
|
||||
|
||||
Rep* rep;
|
||||
|
||||
Fix(Rep*);
|
||||
Fix(int, const Rep*);
|
||||
|
||||
void unique();
|
||||
|
||||
static const _G_uint16_t min_length = 1;
|
||||
static const _G_uint16_t max_length = 65535;
|
||||
static const double min_value = -1.0;
|
||||
static const double max_value = 1.0;
|
||||
|
||||
static _G_uint16_t default_length;
|
||||
static int default_print_width;
|
||||
static Rep Rep_0;
|
||||
static Rep Rep_m1;
|
||||
static Rep Rep_quotient_bump;
|
||||
|
||||
// internal class functions
|
||||
static void mask(Rep*);
|
||||
static int compare(const Rep*, const Rep* = &Rep_0);
|
||||
|
||||
static Rep* new_Fix(_G_uint16_t);
|
||||
static Rep* new_Fix(_G_uint16_t, const Rep*);
|
||||
static Rep* new_Fix(_G_uint16_t, double);
|
||||
|
||||
static Rep* copy(const Rep*, Rep*);
|
||||
static Rep* negate(const Rep*, Rep* = NULL);
|
||||
static Rep* add(const Rep*, const Rep*, Rep* = NULL);
|
||||
static Rep* subtract(const Rep*, const Rep*, Rep* = NULL);
|
||||
static Rep* multiply(const Rep*, const Rep*, Rep* = NULL);
|
||||
static Rep* multiply(const Rep*, int, Rep* = NULL);
|
||||
static Rep* divide(const Rep*, const Rep*, Rep* = NULL,
|
||||
Rep* = NULL);
|
||||
static Rep* shift(const Rep*, int, Rep* = NULL);
|
||||
|
||||
static one_arg_error_handler_t error_handler;
|
||||
static one_arg_error_handler_t range_error_handler;
|
||||
|
||||
static PEH overflow_handler;
|
||||
|
||||
public:
|
||||
Fix();
|
||||
Fix(const Fix&);
|
||||
Fix(double);
|
||||
Fix(int);
|
||||
Fix(int, const Fix&);
|
||||
Fix(int, double);
|
||||
|
||||
~Fix();
|
||||
|
||||
Fix operator = (const Fix&);
|
||||
Fix operator = (double);
|
||||
|
||||
friend int operator == (const Fix&, const Fix&);
|
||||
friend int operator != (const Fix&, const Fix&);
|
||||
|
||||
friend int operator < (const Fix&, const Fix&);
|
||||
friend int operator <= (const Fix&, const Fix&);
|
||||
friend int operator > (const Fix&, const Fix&);
|
||||
friend int operator >= (const Fix&, const Fix&);
|
||||
|
||||
Fix& operator + ();
|
||||
Fix operator - ();
|
||||
|
||||
friend Fix operator + (const Fix&, const Fix&);
|
||||
friend Fix operator - (const Fix&, const Fix&);
|
||||
friend Fix operator * (const Fix&, const Fix&);
|
||||
friend Fix operator / (const Fix&, const Fix&);
|
||||
|
||||
friend Fix operator * (const Fix&, int);
|
||||
friend Fix operator * (int, const Fix&);
|
||||
friend Fix operator % (const Fix&, int);
|
||||
friend Fix operator << (const Fix&, int);
|
||||
friend Fix operator >> (const Fix&, int);
|
||||
|
||||
#if defined (__GNUG__) && ! defined (__STRICT_ANSI__)
|
||||
friend Fix operator <? (const Fix&, const Fix&); // min
|
||||
friend Fix operator >? (const Fix&, const Fix&); // max
|
||||
#endif
|
||||
|
||||
Fix operator += (const Fix&);
|
||||
Fix operator -= (const Fix&);
|
||||
Fix operator *= (const Fix&);
|
||||
Fix operator /= (const Fix&);
|
||||
|
||||
Fix operator *= (int);
|
||||
Fix operator %= (int);
|
||||
Fix operator <<=(int);
|
||||
Fix operator >>=(int);
|
||||
|
||||
friend char* Ftoa(const Fix&, int width = default_print_width);
|
||||
void printon(ostream&, int width = default_print_width) const;
|
||||
friend Fix atoF(const char*, int len = default_length);
|
||||
|
||||
friend istream& operator >> (istream&, Fix&);
|
||||
friend ostream& operator << (ostream&, const Fix&);
|
||||
|
||||
// built-in functions
|
||||
friend Fix abs(Fix); // absolute value
|
||||
friend int sgn(const Fix&); // -1, 0, +1
|
||||
friend Integer mantissa(const Fix&); // integer representation
|
||||
friend double value(const Fix&); // double value
|
||||
friend int length(const Fix&); // field length
|
||||
friend void show(const Fix&); // show contents
|
||||
|
||||
// error handlers
|
||||
static void error(const char* msg); // error handler
|
||||
static void range_error(const char* msg); // range error handler
|
||||
|
||||
static one_arg_error_handler_t set_error_handler(one_arg_error_handler_t f);
|
||||
static one_arg_error_handler_t
|
||||
set_range_error_handler(one_arg_error_handler_t f);
|
||||
|
||||
static void default_error_handler (const char *);
|
||||
static void default_range_error_handler (const char *);
|
||||
|
||||
// non-operator versions for user
|
||||
friend void negate(const Fix& x, Fix& r);
|
||||
friend void add(const Fix& x, const Fix& y, Fix& r);
|
||||
friend void subtract(const Fix& x, const Fix& y, Fix& r);
|
||||
friend void multiply(const Fix& x, const Fix& y, Fix& r);
|
||||
friend void divide(const Fix& x, const Fix& y, Fix& q, Fix& r);
|
||||
friend void shift(const Fix& x, int y, Fix& r);
|
||||
|
||||
// overflow handlers
|
||||
static void overflow_saturate(Fix::Rep*);
|
||||
static void overflow_wrap(Fix::Rep*);
|
||||
static void overflow_warning_saturate(Fix::Rep*);
|
||||
static void overflow_warning(Fix::Rep*);
|
||||
static void overflow_error(Fix::Rep*);
|
||||
|
||||
static PEH set_overflow_handler(PEH);
|
||||
|
||||
static int set_default_length(int);
|
||||
};
|
||||
|
||||
// function definitions
|
||||
|
||||
inline void
|
||||
Fix::unique()
|
||||
{
|
||||
if ( rep->ref > 1 )
|
||||
{
|
||||
rep->ref--;
|
||||
rep = new_Fix(rep->len,rep);
|
||||
}
|
||||
}
|
||||
|
||||
inline void
|
||||
Fix::mask (Fix::Rep* x)
|
||||
{
|
||||
int n = x->len & 0x0f;
|
||||
if ( n )
|
||||
x->s[x->siz - 1] &= 0xffff0000 >> n;
|
||||
}
|
||||
|
||||
inline Fix::Rep*
|
||||
Fix::copy(const Fix::Rep* from, Fix::Rep* to)
|
||||
{
|
||||
_G_uint16_t *ts = to->s;
|
||||
const _G_uint16_t *fs = from->s;
|
||||
int ilim = to->siz < from->siz ? to->siz : from->siz;
|
||||
for ( int i=0; i < ilim; i++ )
|
||||
*ts++ = *fs++;
|
||||
for ( ; i < to->siz; i++ )
|
||||
*ts++ = 0;
|
||||
mask(to);
|
||||
return to;
|
||||
}
|
||||
|
||||
inline
|
||||
Fix::Fix(Rep* f)
|
||||
{
|
||||
rep = f;
|
||||
}
|
||||
|
||||
inline
|
||||
Fix::Fix()
|
||||
{
|
||||
rep = new_Fix(default_length);
|
||||
}
|
||||
|
||||
inline
|
||||
Fix::Fix(int len)
|
||||
{
|
||||
if ( len < min_length || len > max_length )
|
||||
error("illegal length in declaration");
|
||||
rep = new_Fix((_G_uint16_t) len);
|
||||
}
|
||||
|
||||
inline
|
||||
Fix::Fix(double d)
|
||||
{
|
||||
rep = new_Fix(default_length,d);
|
||||
}
|
||||
|
||||
inline
|
||||
Fix::Fix(const Fix& y)
|
||||
{
|
||||
rep = y.rep; rep->ref++;
|
||||
}
|
||||
|
||||
inline
|
||||
Fix::Fix(int len, const Fix& y)
|
||||
{
|
||||
if ( len < Fix::min_length || len > Fix::max_length )
|
||||
error("illegal length in declaration");
|
||||
rep = new_Fix((_G_uint16_t) len,y.rep);
|
||||
}
|
||||
|
||||
inline
|
||||
Fix::Fix(int len, const Rep* fr)
|
||||
{
|
||||
if ( len < Fix::min_length || len > Fix::max_length )
|
||||
error("illegal length in declaration");
|
||||
rep = new_Fix((_G_uint16_t) len,fr);
|
||||
}
|
||||
|
||||
inline
|
||||
Fix::Fix(int len, double d)
|
||||
{
|
||||
if ( len < Fix::min_length || len > Fix::max_length )
|
||||
error("illegal length in declaration");
|
||||
rep = new_Fix((_G_uint16_t) len,d);
|
||||
}
|
||||
|
||||
inline
|
||||
Fix::~Fix()
|
||||
{
|
||||
if ( --rep->ref <= 0 ) delete rep;
|
||||
}
|
||||
|
||||
inline Fix
|
||||
Fix::operator = (const Fix& y)
|
||||
{
|
||||
if ( rep->len == y.rep->len ) {
|
||||
++y.rep->ref;
|
||||
if ( --rep->ref <= 0 ) delete rep;
|
||||
rep = y.rep;
|
||||
}
|
||||
else {
|
||||
unique();
|
||||
copy(y.rep,rep);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Fix
|
||||
Fix::operator = (double d)
|
||||
{
|
||||
int oldlen = rep->len;
|
||||
if ( --rep->ref <= 0 ) delete rep;
|
||||
rep = new_Fix(oldlen,d);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline int
|
||||
operator == (const Fix& x, const Fix& y)
|
||||
{
|
||||
return Fix::compare(x.rep, y.rep) == 0;
|
||||
}
|
||||
|
||||
inline int
|
||||
operator != (const Fix& x, const Fix& y)
|
||||
{
|
||||
return Fix::compare(x.rep, y.rep) != 0;
|
||||
}
|
||||
|
||||
inline int
|
||||
operator < (const Fix& x, const Fix& y)
|
||||
{
|
||||
return Fix::compare(x.rep, y.rep) < 0;
|
||||
}
|
||||
|
||||
inline int
|
||||
operator <= (const Fix& x, const Fix& y)
|
||||
{
|
||||
return Fix::compare(x.rep, y.rep) <= 0;
|
||||
}
|
||||
|
||||
inline int
|
||||
operator > (const Fix& x, const Fix& y)
|
||||
{
|
||||
return Fix::compare(x.rep, y.rep) > 0;
|
||||
}
|
||||
|
||||
inline int
|
||||
operator >= (const Fix& x, const Fix& y)
|
||||
{
|
||||
return Fix::compare(x.rep, y.rep) >= 0;
|
||||
}
|
||||
|
||||
inline Fix&
|
||||
Fix::operator + ()
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Fix
|
||||
Fix::operator - ()
|
||||
{
|
||||
Rep* r = negate(rep); return r;
|
||||
}
|
||||
|
||||
inline Fix
|
||||
operator + (const Fix& x, const Fix& y)
|
||||
{
|
||||
Fix::Rep* r = Fix::add(x.rep, y.rep); return r;
|
||||
}
|
||||
|
||||
inline Fix
|
||||
operator - (const Fix& x, const Fix& y)
|
||||
{
|
||||
Fix::Rep* r = Fix::subtract(x.rep, y.rep); return r;
|
||||
}
|
||||
|
||||
inline Fix
|
||||
operator * (const Fix& x, const Fix& y)
|
||||
{
|
||||
Fix::Rep* r = Fix::multiply(x.rep, y.rep); return r;
|
||||
}
|
||||
|
||||
inline Fix
|
||||
operator * (const Fix& x, int y)
|
||||
{
|
||||
Fix::Rep* r = Fix::multiply(x.rep, y); return r;
|
||||
}
|
||||
|
||||
inline Fix
|
||||
operator * (int y, const Fix& x)
|
||||
{
|
||||
Fix::Rep* r = Fix::multiply(x.rep, y); return r;
|
||||
}
|
||||
|
||||
inline Fix
|
||||
operator / (const Fix& x, const Fix& y)
|
||||
{
|
||||
Fix::Rep* r = Fix::divide(x.rep, y.rep); return r;
|
||||
}
|
||||
|
||||
inline Fix
|
||||
Fix::operator += (const Fix& y)
|
||||
{
|
||||
unique(); Fix::add(rep, y.rep, rep); return *this;
|
||||
}
|
||||
|
||||
inline Fix
|
||||
Fix::operator -= (const Fix& y)
|
||||
{
|
||||
unique(); Fix::subtract(rep, y.rep, rep); return *this;
|
||||
}
|
||||
|
||||
inline Fix
|
||||
Fix::operator *= (const Fix& y)
|
||||
{
|
||||
unique(); Fix::multiply(rep, y.rep, rep); return *this;
|
||||
}
|
||||
|
||||
inline Fix
|
||||
Fix::operator *= (int y)
|
||||
{
|
||||
unique(); Fix::multiply(rep, y, rep); return *this;
|
||||
}
|
||||
|
||||
inline Fix
|
||||
Fix::operator /= (const Fix& y)
|
||||
{
|
||||
unique(); Fix::divide(rep, y.rep, rep); return *this;
|
||||
}
|
||||
|
||||
inline Fix
|
||||
operator % (const Fix& x, int y)
|
||||
{
|
||||
Fix r((int) x.rep->len + y, x); return r;
|
||||
}
|
||||
|
||||
inline Fix
|
||||
operator << (const Fix& x, int y)
|
||||
{
|
||||
Fix::Rep* rep = Fix::shift(x.rep, y); return rep;
|
||||
}
|
||||
|
||||
inline Fix
|
||||
operator >> (const Fix& x, int y)
|
||||
{
|
||||
Fix::Rep* rep = Fix::shift(x.rep, -y); return rep;
|
||||
}
|
||||
|
||||
inline Fix
|
||||
Fix::operator <<= (int y)
|
||||
{
|
||||
unique(); Fix::shift(rep, y, rep); return *this;
|
||||
}
|
||||
|
||||
inline Fix
|
||||
Fix::operator >>= (int y)
|
||||
{
|
||||
unique(); Fix::shift(rep, -y, rep); return *this;
|
||||
}
|
||||
|
||||
#if defined (__GNUG__) && ! defined (__STRICT_ANSI__)
|
||||
inline Fix
|
||||
operator <? (const Fix& x, const Fix& y)
|
||||
{
|
||||
if ( Fix::compare(x.rep, y.rep) <= 0 ) return x; else return y;
|
||||
}
|
||||
|
||||
inline Fix
|
||||
operator >? (const Fix& x, const Fix& y)
|
||||
{
|
||||
if ( Fix::compare(x.rep, y.rep) >= 0 ) return x; else return y;
|
||||
}
|
||||
#endif
|
||||
|
||||
inline Fix
|
||||
abs(Fix x)
|
||||
{
|
||||
Fix::Rep* r = (Fix::compare(x.rep) >= 0 ? Fix::new_Fix(x.rep->len,x.rep) :
|
||||
Fix::negate(x.rep));
|
||||
return r;
|
||||
}
|
||||
|
||||
inline int
|
||||
sgn(const Fix& x)
|
||||
{
|
||||
int a = Fix::compare(x.rep);
|
||||
return a == 0 ? 0 : (a > 0 ? 1 : -1);
|
||||
}
|
||||
|
||||
inline int
|
||||
length(const Fix& x)
|
||||
{
|
||||
return x.rep->len;
|
||||
}
|
||||
|
||||
inline ostream&
|
||||
operator << (ostream& s, const Fix& y)
|
||||
{
|
||||
if (s.opfx())
|
||||
y.printon(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
inline void
|
||||
negate (const Fix& x, Fix& r)
|
||||
{
|
||||
Fix::negate(x.rep, r.rep);
|
||||
}
|
||||
|
||||
inline void
|
||||
add (const Fix& x, const Fix& y, Fix& r)
|
||||
{
|
||||
Fix::add(x.rep, y.rep, r.rep);
|
||||
}
|
||||
|
||||
inline void
|
||||
subtract (const Fix& x, const Fix& y, Fix& r)
|
||||
{
|
||||
Fix::subtract(x.rep, y.rep, r.rep);
|
||||
}
|
||||
|
||||
inline void
|
||||
multiply (const Fix& x, const Fix& y, Fix& r)
|
||||
{
|
||||
Fix::multiply(x.rep, y.rep, r.rep);
|
||||
}
|
||||
|
||||
inline void
|
||||
divide (const Fix& x, const Fix& y, Fix& q, Fix& r)
|
||||
{
|
||||
Fix::divide(x.rep, y.rep, q.rep, r.rep);
|
||||
}
|
||||
|
||||
inline void
|
||||
shift (const Fix& x, int y, Fix& r)
|
||||
{
|
||||
Fix::shift(x.rep, y, r.rep);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,648 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Kurt Baudendistel (gt-eedsp!baud@gatech.edu)
|
||||
adapted for libg++ by Doug Lea (dl@rocky.oswego.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef _Fix16_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define _Fix16_h 1
|
||||
|
||||
#include <stream.h>
|
||||
#include <std.h>
|
||||
|
||||
// constant definitions
|
||||
|
||||
#define Fix16_fs ((double)((unsigned)(1 << 15)))
|
||||
|
||||
#define Fix16_msb (1 << 15)
|
||||
#define Fix16_m_max ((1 << 15) - 1)
|
||||
#define Fix16_m_min ((short)(1 << 15))
|
||||
|
||||
#define Fix16_mult Fix16_fs
|
||||
#define Fix16_div (1./Fix16_fs)
|
||||
#define Fix16_max (1. - .5/Fix16_fs)
|
||||
#define Fix16_min (-1.)
|
||||
|
||||
|
||||
#define Fix32_fs ((double)((_G_uint32_t)(1 << 31)))
|
||||
|
||||
#define Fix32_msb ((_G_uint32_t)(1 << 31))
|
||||
#define Fix32_m_max ((_G_int32_t)((1 << 31) - 1))
|
||||
#define Fix32_m_min ((_G_int32_t)(1 << 31))
|
||||
|
||||
#define Fix32_mult Fix32_fs
|
||||
#define Fix32_div (1./Fix32_fs)
|
||||
#define Fix32_max (1. - .5/Fix32_fs)
|
||||
#define Fix32_min (-1.)
|
||||
|
||||
|
||||
//
|
||||
// Fix16 class: 16-bit Fixed point data type
|
||||
//
|
||||
// consists of a 16-bit mantissa (sign bit & 15 data bits).
|
||||
//
|
||||
|
||||
class Fix16
|
||||
{
|
||||
friend class Fix32;
|
||||
|
||||
short m;
|
||||
|
||||
short round(double d);
|
||||
short assign(double d);
|
||||
Fix16(short i);
|
||||
Fix16(int i);
|
||||
|
||||
operator double() const;
|
||||
|
||||
|
||||
public:
|
||||
Fix16();
|
||||
Fix16(const Fix16& f);
|
||||
Fix16(double d);
|
||||
Fix16(const Fix32& f);
|
||||
|
||||
~Fix16();
|
||||
|
||||
Fix16& operator=(const Fix16& f);
|
||||
Fix16& operator=(double d);
|
||||
Fix16& operator=(const Fix32& f);
|
||||
|
||||
friend short& mantissa(Fix16& f);
|
||||
friend const short& mantissa(const Fix16& f);
|
||||
friend double value(const Fix16& f);
|
||||
|
||||
Fix16 operator + () const;
|
||||
Fix16 operator - () const;
|
||||
|
||||
friend Fix16 operator + (const Fix16& f, const Fix16& g);
|
||||
friend Fix16 operator - (const Fix16& f, const Fix16& g);
|
||||
friend Fix32 operator * (const Fix16& f, const Fix16& g);
|
||||
friend Fix16 operator / (const Fix16& f, const Fix16& g);
|
||||
friend Fix16 operator << (const Fix16& f, int b);
|
||||
friend Fix16 operator >> (const Fix16& f, int b);
|
||||
|
||||
Fix16& operator += (const Fix16& f);
|
||||
Fix16& operator -= (const Fix16& f);
|
||||
Fix16& operator *= (const Fix16& );
|
||||
Fix16& operator /= (const Fix16& f);
|
||||
|
||||
Fix16& operator <<=(int b);
|
||||
Fix16& operator >>=(int b);
|
||||
|
||||
friend int operator == (const Fix16& f, const Fix16& g);
|
||||
friend int operator != (const Fix16& f, const Fix16& g);
|
||||
friend int operator >= (const Fix16& f, const Fix16& g);
|
||||
friend int operator <= (const Fix16& f, const Fix16& g);
|
||||
friend int operator > (const Fix16& f, const Fix16& g);
|
||||
friend int operator < (const Fix16& f, const Fix16& g);
|
||||
|
||||
friend istream& operator >> (istream& s, Fix16& f);
|
||||
friend ostream& operator << (ostream& s, const Fix16& f);
|
||||
|
||||
void overflow(short&) const;
|
||||
void range_error(short&) const;
|
||||
|
||||
friend Fix16 operator * (const Fix16& f, int g);
|
||||
friend Fix16 operator * (int g, const Fix16& f);
|
||||
Fix16& operator *= (int g);
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Fix32 class: 32-bit Fixed point data type
|
||||
//
|
||||
// consists of a 32-bit mantissa (sign bit & 31 data bits).
|
||||
//
|
||||
|
||||
class Fix32
|
||||
{
|
||||
friend class Fix16;
|
||||
|
||||
_G_int32_t m;
|
||||
|
||||
_G_int32_t round(double d);
|
||||
_G_int32_t assign(double d);
|
||||
|
||||
Fix32(_G_int32_t i);
|
||||
operator double() const;
|
||||
|
||||
|
||||
public:
|
||||
Fix32();
|
||||
Fix32(const Fix32& f);
|
||||
Fix32(const Fix16& f);
|
||||
Fix32(double d);
|
||||
~Fix32();
|
||||
|
||||
Fix32& operator = (const Fix32& f);
|
||||
Fix32& operator = (const Fix16& f);
|
||||
Fix32& operator = (double d);
|
||||
|
||||
friend _G_int32_t& mantissa(Fix32& f);
|
||||
friend const _G_int32_t& mantissa(const Fix32& f);
|
||||
friend double value(const Fix32& f);
|
||||
|
||||
Fix32 operator + () const;
|
||||
Fix32 operator - () const;
|
||||
|
||||
friend Fix32 operator + (const Fix32& f, const Fix32& g);
|
||||
friend Fix32 operator - (const Fix32& f, const Fix32& g);
|
||||
friend Fix32 operator * (const Fix32& f, const Fix32& g);
|
||||
friend Fix32 operator / (const Fix32& f, const Fix32& g);
|
||||
friend Fix32 operator << (const Fix32& f, int b);
|
||||
friend Fix32 operator >> (const Fix32& f, int b);
|
||||
|
||||
friend Fix32 operator * (const Fix16& f, const Fix16& g);
|
||||
|
||||
Fix32& operator += (const Fix32& f);
|
||||
Fix32& operator -= (const Fix32& f);
|
||||
Fix32& operator *= (const Fix32& f);
|
||||
Fix32& operator /= (const Fix32& f);
|
||||
Fix32& operator <<=(int b);
|
||||
Fix32& operator >>=(int b);
|
||||
|
||||
friend int operator == (const Fix32& f, const Fix32& g);
|
||||
friend int operator != (const Fix32& f, const Fix32& g);
|
||||
friend int operator >= (const Fix32& f, const Fix32& g);
|
||||
friend int operator <= (const Fix32& f, const Fix32& g);
|
||||
friend int operator > (const Fix32& f, const Fix32& g);
|
||||
friend int operator < (const Fix32& f, const Fix32& g);
|
||||
|
||||
friend istream& operator >> (istream& s, Fix32& f);
|
||||
friend ostream& operator << (ostream& s, const Fix32& f);
|
||||
|
||||
void overflow(_G_int32_t& i) const;
|
||||
void range_error(_G_int32_t& i) const;
|
||||
|
||||
friend Fix32 operator * (const Fix32& f, int g);
|
||||
friend Fix32 operator * (int g, const Fix32& f);
|
||||
Fix32& operator *= (int g);
|
||||
};
|
||||
|
||||
// active error handler declarations
|
||||
|
||||
typedef void (*Fix16_peh)(short&);
|
||||
typedef void (*Fix32_peh)(_G_int32_t&);
|
||||
|
||||
extern Fix16_peh Fix16_overflow_handler;
|
||||
extern Fix32_peh Fix32_overflow_handler;
|
||||
|
||||
extern Fix16_peh Fix16_range_error_handler;
|
||||
extern Fix32_peh Fix32_range_error_handler;
|
||||
|
||||
#if defined(SHORT_NAMES) || defined(VMS)
|
||||
#define set_overflow_handler sohndl
|
||||
#define set_range_error_handler srnghdl
|
||||
#endif
|
||||
|
||||
|
||||
// error handler declarations
|
||||
|
||||
extern Fix16_peh set_Fix16_overflow_handler(Fix16_peh);
|
||||
extern Fix32_peh set_Fix32_overflow_handler(Fix32_peh);
|
||||
extern void set_overflow_handler(Fix16_peh, Fix32_peh);
|
||||
|
||||
extern Fix16_peh set_Fix16_range_error_handler(Fix16_peh);
|
||||
extern Fix32_peh set_Fix32_range_error_handler(Fix32_peh);
|
||||
extern void set_range_error_handler(Fix16_peh, Fix32_peh);
|
||||
|
||||
extern void
|
||||
Fix16_ignore(short&),
|
||||
Fix16_overflow_saturate(short&),
|
||||
Fix16_overflow_warning_saturate(short&),
|
||||
Fix16_warning(short&),
|
||||
Fix16_abort(short&);
|
||||
|
||||
extern void
|
||||
Fix32_ignore(_G_int32_t&),
|
||||
Fix32_overflow_saturate(_G_int32_t&),
|
||||
Fix32_overflow_warning_saturate(_G_int32_t&),
|
||||
Fix32_warning(_G_int32_t&),
|
||||
Fix32_abort(_G_int32_t&);
|
||||
|
||||
|
||||
inline Fix16::~Fix16() {}
|
||||
|
||||
inline short Fix16::round(double d)
|
||||
{
|
||||
return short( (d >= 0)? d + 0.5 : d - 0.5);
|
||||
}
|
||||
|
||||
inline Fix16::Fix16(short i)
|
||||
{
|
||||
m = i;
|
||||
}
|
||||
|
||||
inline Fix16::Fix16(int i)
|
||||
{
|
||||
m = i;
|
||||
}
|
||||
|
||||
inline Fix16::operator double() const
|
||||
{
|
||||
return Fix16_div * m;
|
||||
}
|
||||
|
||||
inline Fix16::Fix16()
|
||||
{
|
||||
m = 0;
|
||||
}
|
||||
|
||||
inline Fix16::Fix16(const Fix16& f)
|
||||
{
|
||||
m = f.m;
|
||||
}
|
||||
|
||||
inline Fix16::Fix16(double d)
|
||||
{
|
||||
m = assign(d);
|
||||
}
|
||||
|
||||
|
||||
inline Fix16& Fix16::operator=(const Fix16& f)
|
||||
{
|
||||
m = f.m;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Fix16& Fix16::operator=(double d)
|
||||
{
|
||||
m = assign(d);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Fix32::Fix32()
|
||||
{
|
||||
m = 0;
|
||||
}
|
||||
|
||||
inline Fix32::Fix32(_G_int32_t i)
|
||||
{
|
||||
m = i;
|
||||
}
|
||||
|
||||
inline Fix32:: operator double() const
|
||||
{
|
||||
return Fix32_div * m;
|
||||
}
|
||||
|
||||
|
||||
inline Fix32::Fix32(const Fix32& f)
|
||||
{
|
||||
m = f.m;
|
||||
}
|
||||
|
||||
inline Fix32::Fix32(const Fix16& f)
|
||||
{
|
||||
m = _G_int32_t(f.m) << 16;
|
||||
}
|
||||
|
||||
inline Fix32::Fix32(double d)
|
||||
{
|
||||
m = assign(d);
|
||||
}
|
||||
|
||||
inline Fix16::Fix16(const Fix32& f)
|
||||
{
|
||||
m = f.m >> 16;
|
||||
}
|
||||
|
||||
|
||||
inline Fix16& Fix16::operator=(const Fix32& f)
|
||||
{
|
||||
m = f.m >> 16;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Fix32& Fix32::operator=(const Fix32& f)
|
||||
{
|
||||
m = f.m;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Fix32& Fix32::operator=(const Fix16& f)
|
||||
{
|
||||
m = _G_int32_t(f.m) << 16;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Fix32& Fix32::operator=(double d)
|
||||
{
|
||||
m = assign(d);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline short& mantissa(Fix16& f)
|
||||
{
|
||||
return f.m;
|
||||
}
|
||||
|
||||
inline const short& mantissa(const Fix16& f)
|
||||
{
|
||||
return f.m;
|
||||
}
|
||||
|
||||
inline double value(const Fix16& f)
|
||||
{
|
||||
return double(f);
|
||||
}
|
||||
|
||||
inline Fix16 Fix16::operator+() const
|
||||
{
|
||||
return m;
|
||||
}
|
||||
|
||||
inline Fix16 Fix16::operator-() const
|
||||
{
|
||||
return -m;
|
||||
}
|
||||
|
||||
inline Fix16 operator+(const Fix16& f, const Fix16& g)
|
||||
{
|
||||
short sum = f.m + g.m;
|
||||
if ( (f.m ^ sum) & (g.m ^ sum) & Fix16_msb )
|
||||
f.overflow(sum);
|
||||
return sum;
|
||||
}
|
||||
|
||||
inline Fix16 operator-(const Fix16& f, const Fix16& g)
|
||||
{
|
||||
short sum = f.m - g.m;
|
||||
if ( (f.m ^ sum) & (-g.m ^ sum) & Fix16_msb )
|
||||
f.overflow(sum);
|
||||
return sum;
|
||||
}
|
||||
|
||||
inline Fix32 operator*(const Fix16& f, const Fix16& g)
|
||||
{
|
||||
return Fix32( _G_int32_t( _G_int32_t(f.m) * _G_int32_t(g.m) << 1));
|
||||
}
|
||||
|
||||
inline Fix16 operator<<(const Fix16& a, int b)
|
||||
{
|
||||
return a.m << b;
|
||||
}
|
||||
|
||||
inline Fix16 operator>>(const Fix16& a, int b)
|
||||
{
|
||||
return a.m >> b;
|
||||
}
|
||||
|
||||
inline Fix16& Fix16:: operator+=(const Fix16& f)
|
||||
{
|
||||
return *this = *this + f;
|
||||
}
|
||||
|
||||
inline Fix16& Fix16:: operator-=(const Fix16& f)
|
||||
{
|
||||
return *this = *this - f;
|
||||
}
|
||||
|
||||
inline Fix16& Fix16::operator*=(const Fix16& f)
|
||||
{
|
||||
return *this = *this * f;
|
||||
}
|
||||
|
||||
inline Fix16& Fix16:: operator/=(const Fix16& f)
|
||||
{
|
||||
return *this = *this / f;
|
||||
}
|
||||
|
||||
inline Fix16& Fix16:: operator<<=(int b)
|
||||
{
|
||||
return *this = *this << b;
|
||||
}
|
||||
|
||||
inline Fix16& Fix16:: operator>>=(int b)
|
||||
{
|
||||
return *this = *this >> b;
|
||||
}
|
||||
|
||||
inline int operator==(const Fix16& f, const Fix16& g)
|
||||
{
|
||||
return f.m == g.m;
|
||||
}
|
||||
|
||||
inline int operator!=(const Fix16& f, const Fix16& g)
|
||||
{
|
||||
return f.m != g.m;
|
||||
}
|
||||
|
||||
inline int operator>=(const Fix16& f, const Fix16& g)
|
||||
{
|
||||
return f.m >= g.m;
|
||||
}
|
||||
|
||||
inline int operator<=(const Fix16& f, const Fix16& g)
|
||||
{
|
||||
return f.m <= g.m;
|
||||
}
|
||||
|
||||
inline int operator>(const Fix16& f, const Fix16& g)
|
||||
{
|
||||
return f.m > g.m;
|
||||
}
|
||||
|
||||
inline int operator<(const Fix16& f, const Fix16& g)
|
||||
{
|
||||
return f.m < g.m;
|
||||
}
|
||||
|
||||
inline istream& operator>>(istream& s, Fix16& f)
|
||||
{
|
||||
double d;
|
||||
s >> d;
|
||||
f = d;
|
||||
return s;
|
||||
}
|
||||
|
||||
inline ostream& operator<<(ostream& s, const Fix16& f)
|
||||
{
|
||||
return s << double(f);
|
||||
}
|
||||
|
||||
|
||||
inline Fix16 operator*(const Fix16& f, int g)
|
||||
{
|
||||
return Fix16(short(f.m * g));
|
||||
}
|
||||
|
||||
inline Fix16 operator*(int g, const Fix16& f)
|
||||
{
|
||||
return f * g;
|
||||
}
|
||||
|
||||
|
||||
inline Fix16& Fix16::operator*=(int g)
|
||||
{
|
||||
return *this = *this * g;
|
||||
}
|
||||
|
||||
inline Fix32::~Fix32() {}
|
||||
|
||||
inline _G_int32_t Fix32::round(double d)
|
||||
{
|
||||
return _G_int32_t( (d >= 0)? d + 0.5 : d - 0.5);
|
||||
}
|
||||
|
||||
inline _G_int32_t& mantissa(Fix32& f)
|
||||
{
|
||||
return f.m;
|
||||
}
|
||||
|
||||
inline const _G_int32_t& mantissa(const Fix32& f)
|
||||
{
|
||||
return f.m;
|
||||
}
|
||||
|
||||
inline double value(const Fix32& f)
|
||||
{
|
||||
return double(f);
|
||||
}
|
||||
|
||||
inline Fix32 Fix32::operator+() const
|
||||
{
|
||||
return m;
|
||||
}
|
||||
|
||||
inline Fix32 Fix32::operator-() const
|
||||
{
|
||||
return -m;
|
||||
}
|
||||
|
||||
inline Fix32 operator+(const Fix32& f, const Fix32& g)
|
||||
{
|
||||
_G_int32_t sum = f.m + g.m;
|
||||
if ( (f.m ^ sum) & (g.m ^ sum) & Fix32_msb )
|
||||
f.overflow(sum);
|
||||
return sum;
|
||||
}
|
||||
|
||||
inline Fix32 operator-(const Fix32& f, const Fix32& g)
|
||||
{
|
||||
_G_int32_t sum = f.m - g.m;
|
||||
if ( (f.m ^ sum) & (-g.m ^ sum) & Fix32_msb )
|
||||
f.overflow(sum);
|
||||
return sum;
|
||||
}
|
||||
|
||||
inline Fix32 operator<<(const Fix32& a, int b)
|
||||
{
|
||||
return a.m << b;
|
||||
}
|
||||
|
||||
inline Fix32 operator>>(const Fix32& a, int b)
|
||||
{
|
||||
return a.m >> b;
|
||||
}
|
||||
|
||||
inline Fix32& Fix32::operator+=(const Fix32& f)
|
||||
{
|
||||
return *this = *this + f;
|
||||
}
|
||||
|
||||
inline Fix32& Fix32::operator-=(const Fix32& f)
|
||||
{
|
||||
return *this = *this - f;
|
||||
}
|
||||
|
||||
inline Fix32& Fix32::operator*=(const Fix32& f)
|
||||
{
|
||||
return *this = *this * f;
|
||||
}
|
||||
|
||||
inline Fix32& Fix32::operator/=(const Fix32& f)
|
||||
{
|
||||
return *this = *this / f;
|
||||
}
|
||||
|
||||
|
||||
inline Fix32& Fix32::operator<<=(int b)
|
||||
{
|
||||
return *this = *this << b;
|
||||
}
|
||||
|
||||
inline Fix32& Fix32::operator>>=(int b)
|
||||
{
|
||||
return *this = *this >> b;
|
||||
}
|
||||
|
||||
inline int operator==(const Fix32& f, const Fix32& g)
|
||||
{
|
||||
return f.m == g.m;
|
||||
}
|
||||
|
||||
inline int operator!=(const Fix32& f, const Fix32& g)
|
||||
{
|
||||
return f.m != g.m;
|
||||
}
|
||||
|
||||
inline int operator>=(const Fix32& f, const Fix32& g)
|
||||
{
|
||||
return f.m >= g.m;
|
||||
}
|
||||
|
||||
inline int operator<=(const Fix32& f, const Fix32& g)
|
||||
{
|
||||
return f.m <= g.m;
|
||||
}
|
||||
|
||||
inline int operator>(const Fix32& f, const Fix32& g)
|
||||
{
|
||||
return f.m > g.m;
|
||||
}
|
||||
|
||||
inline int operator<(const Fix32& f, const Fix32& g)
|
||||
{
|
||||
return f.m < g.m;
|
||||
}
|
||||
|
||||
inline istream& operator>>(istream& s, Fix32& f)
|
||||
{
|
||||
double d;
|
||||
s >> d;
|
||||
f = d;
|
||||
return s;
|
||||
}
|
||||
|
||||
inline ostream& operator<<(ostream& s, const Fix32& f)
|
||||
{
|
||||
return s << double(f);
|
||||
}
|
||||
|
||||
inline Fix32 operator*(const Fix32& f, int g)
|
||||
{
|
||||
return Fix32(_G_int32_t(f.m * g));
|
||||
}
|
||||
|
||||
inline Fix32 operator*(int g, const Fix32& f)
|
||||
{
|
||||
return f * g;
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline Fix32& Fix32::operator*=(int g)
|
||||
{
|
||||
return *this = *this * g;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,597 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Kurt Baudendistel (gt-eedsp!baud@gatech.edu)
|
||||
adapted for libg++ by Doug Lea (dl@rocky.oswego.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef _Fix24_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define _Fix24_h 1
|
||||
|
||||
#include <stream.h>
|
||||
#include <std.h>
|
||||
|
||||
// extra type definitions
|
||||
|
||||
typedef struct {
|
||||
_G_int32_t u;
|
||||
_G_uint32_t l;
|
||||
} twolongs;
|
||||
|
||||
// constant definitions
|
||||
|
||||
static const int
|
||||
Fix24_shift = 31;
|
||||
|
||||
static const double
|
||||
Fix24_fs = 2147483648., // 2^Fix24_shift
|
||||
Fix24_mult = Fix24_fs,
|
||||
Fix24_div = 1./Fix24_fs,
|
||||
Fix24_max = 1. - .5/Fix24_fs,
|
||||
Fix24_min = -1.;
|
||||
|
||||
static const _G_uint32_t
|
||||
Fix24_msb = 0x80000000L,
|
||||
Fix24_lsb = 0x00000100L,
|
||||
Fix24_m_max = 0x7fffff00L,
|
||||
Fix24_m_min = 0x80000000L;
|
||||
|
||||
static const double
|
||||
Fix48_fs = 36028797018963968., // 2^(24+Fix24_shift)
|
||||
Fix48_max = 1. - .5/Fix48_fs,
|
||||
Fix48_min = -1.,
|
||||
Fix48_div_u = 1./Fix24_fs,
|
||||
Fix48_div_l = 1./Fix48_fs;
|
||||
|
||||
static const twolongs
|
||||
Fix48_msb = { 0x80000000L, 0L },
|
||||
Fix48_lsb = { 0L, 0x00000100L },
|
||||
Fix48_m_max = { 0x7fffff00L, 0xffffff00L },
|
||||
Fix48_m_min = { 0x80000000L, 0L };
|
||||
|
||||
//
|
||||
// Fix24 class: 24-bit Fixed point data type
|
||||
//
|
||||
// consists of a 24-bit mantissa (sign bit & 23 data bits).
|
||||
//
|
||||
|
||||
class Fix24
|
||||
{
|
||||
friend class Fix48;
|
||||
|
||||
_G_int32_t m;
|
||||
|
||||
_G_int32_t assign(double d);
|
||||
operator double() const;
|
||||
Fix24(long i);
|
||||
Fix24(int i);
|
||||
|
||||
|
||||
public:
|
||||
Fix24();
|
||||
Fix24(const Fix24& f);
|
||||
Fix24(double d);
|
||||
Fix24(const Fix48& f);
|
||||
|
||||
~Fix24();
|
||||
|
||||
Fix24& operator=(const Fix24& f);
|
||||
Fix24& operator=(double d);
|
||||
Fix24& operator=(const Fix48& f);
|
||||
|
||||
friend _G_int32_t& mantissa(Fix24& f);
|
||||
friend const _G_int32_t& mantissa(const Fix24& f);
|
||||
friend double value(const Fix24& f);
|
||||
|
||||
Fix24 operator + () const;
|
||||
Fix24 operator - () const;
|
||||
|
||||
friend Fix24 operator + (const Fix24& f, const Fix24& g);
|
||||
friend Fix24 operator - (const Fix24& f, const Fix24& g);
|
||||
friend Fix48 operator * (const Fix24& f, const Fix24& g);
|
||||
friend Fix24 operator * (const Fix24& f, int g);
|
||||
friend Fix24 operator * (int g, const Fix24& f);
|
||||
friend Fix24 operator / (const Fix24& f, const Fix24& g);
|
||||
friend Fix24 operator << (const Fix24& f, int b);
|
||||
friend Fix24 operator >> (const Fix24& f, int b);
|
||||
|
||||
Fix24& operator += (const Fix24& f);
|
||||
Fix24& operator -= (const Fix24& f);
|
||||
Fix24& operator *= (const Fix24& f);
|
||||
Fix24& operator *= (int b);
|
||||
Fix24& operator /= (const Fix24& f);
|
||||
|
||||
Fix24& operator <<=(int b);
|
||||
Fix24& operator >>=(int b);
|
||||
|
||||
friend int operator == (const Fix24& f, const Fix24& g);
|
||||
friend int operator != (const Fix24& f, const Fix24& g);
|
||||
friend int operator >= (const Fix24& f, const Fix24& g);
|
||||
friend int operator <= (const Fix24& f, const Fix24& g);
|
||||
friend int operator > (const Fix24& f, const Fix24& g);
|
||||
friend int operator < (const Fix24& f, const Fix24& g);
|
||||
|
||||
friend istream& operator >> (istream& s, Fix24& f);
|
||||
friend ostream& operator << (ostream& s, const Fix24& f);
|
||||
|
||||
void overflow(_G_int32_t&) const;
|
||||
void range_error(_G_int32_t&) const;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Fix48 class: 48-bit Fixed point data type
|
||||
//
|
||||
// consists of a 48-bit mantissa (sign bit & 47 data bits).
|
||||
//
|
||||
|
||||
class Fix48
|
||||
{
|
||||
friend class Fix24;
|
||||
|
||||
twolongs m;
|
||||
|
||||
twolongs assign(double d);
|
||||
operator double() const;
|
||||
Fix48(twolongs i);
|
||||
|
||||
public:
|
||||
Fix48();
|
||||
Fix48(const Fix48& f);
|
||||
Fix48(const Fix24& f);
|
||||
Fix48(double d);
|
||||
~Fix48();
|
||||
|
||||
Fix48& operator = (const Fix48& f);
|
||||
Fix48& operator = (const Fix24& f);
|
||||
Fix48& operator = (double d);
|
||||
|
||||
friend twolongs& mantissa(Fix48& f);
|
||||
friend const twolongs& mantissa(const Fix48& f);
|
||||
friend double value(const Fix48& f);
|
||||
|
||||
Fix48 operator + () const;
|
||||
Fix48 operator - () const;
|
||||
|
||||
friend Fix48 operator + (const Fix48& f, const Fix48& g);
|
||||
friend Fix48 operator - (const Fix48& f, const Fix48& g);
|
||||
friend Fix48 operator * (const Fix48& f, int g);
|
||||
friend Fix48 operator * (int g, const Fix48& f);
|
||||
friend Fix48 operator << (const Fix48& f, int b);
|
||||
friend Fix48 operator >> (const Fix48& f, int b);
|
||||
|
||||
friend Fix48 operator * (const Fix24& f, const Fix24& g);
|
||||
|
||||
Fix48& operator += (const Fix48& f);
|
||||
Fix48& operator -= (const Fix48& f);
|
||||
Fix48& operator *= (int b);
|
||||
Fix48& operator <<=(int b);
|
||||
Fix48& operator >>=(int b);
|
||||
|
||||
friend int operator == (const Fix48& f, const Fix48& g);
|
||||
friend int operator != (const Fix48& f, const Fix48& g);
|
||||
friend int operator >= (const Fix48& f, const Fix48& g);
|
||||
friend int operator <= (const Fix48& f, const Fix48& g);
|
||||
friend int operator > (const Fix48& f, const Fix48& g);
|
||||
friend int operator < (const Fix48& f, const Fix48& g);
|
||||
|
||||
friend istream& operator >> (istream& s, Fix48& f);
|
||||
friend ostream& operator << (ostream& s, const Fix48& f);
|
||||
|
||||
void overflow(twolongs& i) const;
|
||||
void range_error(twolongs& i) const;
|
||||
};
|
||||
|
||||
|
||||
// active error handler declarations
|
||||
|
||||
typedef void (*Fix24_peh)(_G_int32_t&);
|
||||
typedef void (*Fix48_peh)(twolongs&);
|
||||
|
||||
extern Fix24_peh Fix24_overflow_handler;
|
||||
extern Fix48_peh Fix48_overflow_handler;
|
||||
|
||||
extern Fix24_peh Fix24_range_error_handler;
|
||||
extern Fix48_peh Fix48_range_error_handler;
|
||||
|
||||
|
||||
// error handler declarations
|
||||
|
||||
#if defined(SHORT_NAMES) || defined(VMS)
|
||||
#define set_overflow_handler sohndl
|
||||
#define set_range_error_handler srnghdl
|
||||
#endif
|
||||
|
||||
extern Fix24_peh set_Fix24_overflow_handler(Fix24_peh);
|
||||
extern Fix48_peh set_Fix48_overflow_handler(Fix48_peh);
|
||||
extern void set_overflow_handler(Fix24_peh, Fix48_peh);
|
||||
|
||||
extern Fix24_peh set_Fix24_range_error_handler(Fix24_peh);
|
||||
extern Fix48_peh set_Fix48_range_error_handler(Fix48_peh);
|
||||
extern void set_range_error_handler(Fix24_peh, Fix48_peh);
|
||||
|
||||
extern void
|
||||
Fix24_ignore(_G_int32_t&),
|
||||
Fix24_overflow_saturate(_G_int32_t&),
|
||||
Fix24_overflow_warning_saturate(_G_int32_t&),
|
||||
Fix24_warning(_G_int32_t&),
|
||||
Fix24_abort(_G_int32_t&);
|
||||
|
||||
extern void
|
||||
Fix48_ignore(twolongs&),
|
||||
Fix48_overflow_saturate(twolongs&),
|
||||
Fix48_overflow_warning_saturate(twolongs&),
|
||||
Fix48_warning(twolongs&),
|
||||
Fix48_abort(twolongs&);
|
||||
|
||||
|
||||
inline Fix24::~Fix24() {}
|
||||
|
||||
inline Fix24::Fix24(long i)
|
||||
{
|
||||
m = i;
|
||||
}
|
||||
|
||||
inline Fix24::Fix24(int i)
|
||||
{
|
||||
m = i;
|
||||
}
|
||||
|
||||
inline Fix24::operator double() const
|
||||
{
|
||||
return Fix24_div * m;
|
||||
}
|
||||
|
||||
inline Fix24::Fix24()
|
||||
{
|
||||
m = 0;
|
||||
}
|
||||
|
||||
inline Fix24::Fix24(const Fix24& f)
|
||||
{
|
||||
m = f.m;
|
||||
}
|
||||
|
||||
inline Fix24::Fix24(double d)
|
||||
{
|
||||
m = assign(d);
|
||||
}
|
||||
|
||||
inline Fix24::Fix24(const Fix48& f)
|
||||
{
|
||||
m = f.m.u;
|
||||
}
|
||||
|
||||
inline Fix24& Fix24::operator=(const Fix24& f)
|
||||
{
|
||||
m = f.m;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Fix24& Fix24::operator=(double d)
|
||||
{
|
||||
m = assign(d);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Fix24& Fix24::operator=(const Fix48& f)
|
||||
{
|
||||
m = f.m.u;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline _G_int32_t& mantissa(Fix24& f)
|
||||
{
|
||||
return f.m;
|
||||
}
|
||||
|
||||
inline const _G_int32_t& mantissa(const Fix24& f)
|
||||
{
|
||||
return f.m;
|
||||
}
|
||||
|
||||
inline double value(const Fix24& f)
|
||||
{
|
||||
return double(f);
|
||||
}
|
||||
|
||||
inline Fix24 Fix24::operator+() const
|
||||
{
|
||||
return m;
|
||||
}
|
||||
|
||||
inline Fix24 Fix24::operator-() const
|
||||
{
|
||||
return -m;
|
||||
}
|
||||
|
||||
inline Fix24 operator+(const Fix24& f, const Fix24& g)
|
||||
{
|
||||
_G_int32_t sum = f.m + g.m;
|
||||
if ( (f.m ^ sum) & (g.m ^ sum) & Fix24_msb )
|
||||
f.overflow(sum);
|
||||
return sum;
|
||||
}
|
||||
|
||||
inline Fix24 operator-(const Fix24& f, const Fix24& g)
|
||||
{
|
||||
_G_int32_t sum = f.m - g.m;
|
||||
if ( (f.m ^ sum) & (-g.m ^ sum) & Fix24_msb )
|
||||
f.overflow(sum);
|
||||
return sum;
|
||||
}
|
||||
|
||||
inline Fix24 operator*(const Fix24& a, int b)
|
||||
{
|
||||
return a.m * b;
|
||||
}
|
||||
|
||||
inline Fix24 operator*(int b, const Fix24& a)
|
||||
{
|
||||
return a * b;
|
||||
}
|
||||
|
||||
inline Fix24 operator<<(const Fix24& a, int b)
|
||||
{
|
||||
return a.m << b;
|
||||
}
|
||||
|
||||
inline Fix24 operator>>(const Fix24& a, int b)
|
||||
{
|
||||
return (a.m >> b) & ~0xff;
|
||||
}
|
||||
|
||||
inline Fix24& Fix24:: operator+=(const Fix24& f)
|
||||
{
|
||||
return *this = *this + f;
|
||||
}
|
||||
|
||||
inline Fix24& Fix24:: operator-=(const Fix24& f)
|
||||
{
|
||||
return *this = *this - f;
|
||||
}
|
||||
|
||||
inline Fix24& Fix24::operator*=(const Fix24& f)
|
||||
{
|
||||
return *this = *this * f;
|
||||
}
|
||||
|
||||
inline Fix24& Fix24:: operator/=(const Fix24& f)
|
||||
{
|
||||
return *this = *this / f;
|
||||
}
|
||||
|
||||
inline Fix24& Fix24:: operator<<=(int b)
|
||||
{
|
||||
return *this = *this << b;
|
||||
}
|
||||
|
||||
inline Fix24& Fix24:: operator>>=(int b)
|
||||
{
|
||||
return *this = *this >> b;
|
||||
}
|
||||
|
||||
inline Fix24& Fix24::operator*=(int b)
|
||||
{
|
||||
return *this = *this * b;
|
||||
}
|
||||
|
||||
inline int operator==(const Fix24& f, const Fix24& g)
|
||||
{
|
||||
return f.m == g.m;
|
||||
}
|
||||
|
||||
inline int operator!=(const Fix24& f, const Fix24& g)
|
||||
{
|
||||
return f.m != g.m;
|
||||
}
|
||||
|
||||
inline int operator>=(const Fix24& f, const Fix24& g)
|
||||
{
|
||||
return f.m >= g.m;
|
||||
}
|
||||
|
||||
inline int operator<=(const Fix24& f, const Fix24& g)
|
||||
{
|
||||
return f.m <= g.m;
|
||||
}
|
||||
|
||||
inline int operator>(const Fix24& f, const Fix24& g)
|
||||
{
|
||||
return f.m > g.m;
|
||||
}
|
||||
|
||||
inline int operator<(const Fix24& f, const Fix24& g)
|
||||
{
|
||||
return f.m < g.m;
|
||||
}
|
||||
|
||||
inline istream& operator>>(istream& s, Fix24& f)
|
||||
{
|
||||
double d;
|
||||
s >> d;
|
||||
f = d;
|
||||
return s;
|
||||
}
|
||||
|
||||
inline ostream& operator<<(ostream& s, const Fix24& f)
|
||||
{
|
||||
return s << double(f);
|
||||
}
|
||||
|
||||
inline Fix48::~Fix48() {}
|
||||
|
||||
inline Fix48::Fix48(twolongs i)
|
||||
{
|
||||
m = i;
|
||||
}
|
||||
|
||||
inline Fix48:: operator double() const
|
||||
{
|
||||
/*
|
||||
* Note: can't simply do Fix48_div_u * m.u + Fix48_div_l * m.l, because
|
||||
* m.u is signed and m.l is unsigned.
|
||||
*/
|
||||
return (m.u >= 0)? Fix48_div_u * m.u + Fix48_div_l * m.l :
|
||||
(Fix48_div_u * ((_G_uint32_t)(m.u & 0xffffff00))
|
||||
+ Fix48_div_l * m.l) - 2;
|
||||
}
|
||||
|
||||
inline Fix48::Fix48()
|
||||
{
|
||||
m.u = 0;
|
||||
m.l = 0;
|
||||
}
|
||||
|
||||
inline Fix48::Fix48(const Fix48& f)
|
||||
{
|
||||
m = f.m;
|
||||
}
|
||||
|
||||
inline Fix48::Fix48(const Fix24& f)
|
||||
{
|
||||
m.u = f.m;
|
||||
m.l = 0;
|
||||
}
|
||||
|
||||
inline Fix48::Fix48(double d)
|
||||
{
|
||||
m = assign(d);
|
||||
}
|
||||
|
||||
inline Fix48& Fix48::operator=(const Fix48& f)
|
||||
{
|
||||
m = f.m;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Fix48& Fix48::operator=(const Fix24& f)
|
||||
{
|
||||
m.u = f.m;
|
||||
m.l = 0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Fix48& Fix48::operator=(double d)
|
||||
{
|
||||
m = assign(d);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline twolongs& mantissa(Fix48& f)
|
||||
{
|
||||
return f.m;
|
||||
}
|
||||
|
||||
inline const twolongs& mantissa(const Fix48& f)
|
||||
{
|
||||
return f.m;
|
||||
}
|
||||
|
||||
inline double value(const Fix48& f)
|
||||
{
|
||||
return double(f);
|
||||
}
|
||||
|
||||
inline Fix48 Fix48::operator+() const
|
||||
{
|
||||
return m;
|
||||
}
|
||||
|
||||
inline Fix48 Fix48::operator-() const
|
||||
{
|
||||
twolongs n;
|
||||
n.l = -m.l;
|
||||
n.u = ~m.u + ((n.l ^ m.l) & Fix24_msb ? 0 : Fix24_lsb);
|
||||
return Fix48(n);
|
||||
}
|
||||
|
||||
inline Fix48 operator*(int b, const Fix48& a)
|
||||
{
|
||||
return a * b;
|
||||
}
|
||||
|
||||
inline Fix48& Fix48::operator+=(const Fix48& f)
|
||||
{
|
||||
return *this = *this + f;
|
||||
}
|
||||
|
||||
inline Fix48& Fix48::operator-=(const Fix48& f)
|
||||
{
|
||||
return *this = *this - f;
|
||||
}
|
||||
|
||||
inline Fix48& Fix48::operator*=(int b)
|
||||
{
|
||||
return *this = *this * b;
|
||||
}
|
||||
|
||||
inline Fix48& Fix48::operator<<=(int b)
|
||||
{
|
||||
return *this = *this << b;
|
||||
}
|
||||
|
||||
inline Fix48& Fix48::operator>>=(int b)
|
||||
{
|
||||
return *this = *this >> b;
|
||||
}
|
||||
|
||||
inline int operator==(const Fix48& f, const Fix48& g)
|
||||
{
|
||||
return f.m.u == g.m.u && f.m.l == g.m.l;
|
||||
}
|
||||
|
||||
inline int operator!=(const Fix48& f, const Fix48& g)
|
||||
{
|
||||
return f.m.u != g.m.u || f.m.l != g.m.l;
|
||||
}
|
||||
|
||||
inline int operator>=(const Fix48& f, const Fix48& g)
|
||||
{
|
||||
return f.m.u >= g.m.u || (f.m.u == g.m.u && f.m.l >= g.m.l);
|
||||
}
|
||||
|
||||
inline int operator<=(const Fix48& f, const Fix48& g)
|
||||
{
|
||||
return f.m.u <= g.m.u || (f.m.u == g.m.u && f.m.l <= g.m.l);
|
||||
}
|
||||
|
||||
inline int operator>(const Fix48& f, const Fix48& g)
|
||||
{
|
||||
return f.m.u > g.m.u || (f.m.u == g.m.u && f.m.l > g.m.l);
|
||||
}
|
||||
|
||||
inline int operator<(const Fix48& f, const Fix48& g)
|
||||
{
|
||||
return f.m.u < g.m.u || (f.m.u == g.m.u && f.m.l < g.m.l);
|
||||
}
|
||||
|
||||
inline istream& operator>>(istream& s, Fix48& f)
|
||||
{
|
||||
double d;
|
||||
s >> d;
|
||||
f = d;
|
||||
return s;
|
||||
}
|
||||
|
||||
inline ostream& operator<<(ostream& s, const Fix48& f)
|
||||
{
|
||||
return s << double(f);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Dirk Grunwald (grunwald@cs.uiuc.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifndef _Geometric_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define _Geometric_h
|
||||
|
||||
#include <Random.h>
|
||||
|
||||
class Geometric: public Random {
|
||||
protected:
|
||||
double pMean;
|
||||
public:
|
||||
Geometric(double mean, RNG *gen);
|
||||
|
||||
double mean();
|
||||
double mean(double x);
|
||||
|
||||
virtual double operator()();
|
||||
|
||||
};
|
||||
|
||||
|
||||
inline Geometric::Geometric(double mean, RNG *gen) : Random(gen)
|
||||
{
|
||||
pMean = mean;
|
||||
}
|
||||
|
||||
|
||||
inline double Geometric::mean() { return pMean; }
|
||||
inline double Geometric::mean(double x) {
|
||||
double tmp = pMean; pMean = x; return tmp;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -1,129 +0,0 @@
|
|||
/* Getopt for GNU.
|
||||
Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
|
||||
(Modified by Douglas C. Schmidt for use with GNU G++.)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
|
||||
/* This version of `getopt' appears to the caller like standard Unix `getopt'
|
||||
but it behaves differently for the user, since it allows the user
|
||||
to intersperse the options with the other arguments.
|
||||
|
||||
As `getopt' works, it permutes the elements of `argv' so that,
|
||||
when it is done, all the options precede everything else. Thus
|
||||
all application programs are extended to handle flexible argument order.
|
||||
|
||||
Setting the environment variable _POSIX_OPTION_ORDER disables permutation.
|
||||
Then the behavior is completely standard.
|
||||
|
||||
GNU application programs can use a third alternative mode in which
|
||||
they can distinguish the relative order of options and other arguments. */
|
||||
|
||||
#ifndef GetOpt_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define GetOpt_h 1
|
||||
|
||||
#include <std.h>
|
||||
#include <stdio.h>
|
||||
|
||||
class GetOpt
|
||||
{
|
||||
private:
|
||||
/* The next char to be scanned in the option-element
|
||||
in which the last option character we returned was found.
|
||||
This allows us to pick up the scan where we left off.
|
||||
|
||||
If this is zero, or a null string, it means resume the scan
|
||||
by advancing to the next ARGV-element. */
|
||||
|
||||
static char *nextchar;
|
||||
|
||||
|
||||
/* Describe how to deal with options that follow non-option ARGV-elements.
|
||||
|
||||
UNSPECIFIED means the caller did not specify anything;
|
||||
the default is then REQUIRE_ORDER if the environment variable
|
||||
_OPTIONS_FIRST is defined, PERMUTE otherwise.
|
||||
|
||||
REQUIRE_ORDER means don't recognize them as options.
|
||||
Stop option processing when the first non-option is seen.
|
||||
This is what Unix does.
|
||||
|
||||
PERMUTE is the default. We permute the contents of `argv' as we scan,
|
||||
so that eventually all the options are at the end. This allows options
|
||||
to be given in any order, even with programs that were not written to
|
||||
expect this.
|
||||
|
||||
RETURN_IN_ORDER is an option available to programs that were written
|
||||
to expect options and other ARGV-elements in any order and that care about
|
||||
the ordering of the two. We describe each non-option ARGV-element
|
||||
as if it were the argument of an option with character code zero.
|
||||
Using `-' as the first character of the list of option characters
|
||||
requests this mode of operation.
|
||||
|
||||
The special argument `--' forces an end of option-scanning regardless
|
||||
of the value of `ordering'. In the case of RETURN_IN_ORDER, only
|
||||
`--' can cause `getopt' to return EOF with `optind' != ARGC. */
|
||||
|
||||
enum OrderingEnum { REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER };
|
||||
OrderingEnum ordering;
|
||||
|
||||
/* Handle permutation of arguments. */
|
||||
|
||||
/* Describe the part of ARGV that contains non-options that have
|
||||
been skipped. `first_nonopt' is the index in ARGV of the first of them;
|
||||
`last_nonopt' is the index after the last of them. */
|
||||
|
||||
static int first_nonopt;
|
||||
static int last_nonopt;
|
||||
|
||||
void exchange (char **argv);
|
||||
public:
|
||||
/* For communication from `getopt' to the caller.
|
||||
When `getopt' finds an option that takes an argument,
|
||||
the argument value is returned here.
|
||||
Also, when `ordering' is RETURN_IN_ORDER,
|
||||
each non-option ARGV-element is returned here. */
|
||||
|
||||
char *optarg;
|
||||
|
||||
/* Index in ARGV of the next element to be scanned.
|
||||
This is used for communication to and from the caller
|
||||
and for communication between successive calls to `getopt'.
|
||||
On entry to `getopt', zero means this is the first call; initialize.
|
||||
|
||||
When `getopt' returns EOF, this is the index of the first of the
|
||||
non-option elements that the caller should itself scan.
|
||||
|
||||
Otherwise, `optind' communicates from one call to the next
|
||||
how much of ARGV has been scanned so far. */
|
||||
|
||||
int optind;
|
||||
|
||||
/* Callers store zero here to inhibit the error message
|
||||
for unrecognized options. */
|
||||
|
||||
int opterr;
|
||||
|
||||
int nargc;
|
||||
char **nargv;
|
||||
const char *noptstring;
|
||||
|
||||
GetOpt (int argc, char **argv, const char *optstring);
|
||||
int operator () (void);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Dirk Grunwald (grunwald@cs.uiuc.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifndef _HyperGeometric_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define _HyperGeometric_h
|
||||
|
||||
#include <Random.h>
|
||||
|
||||
class HyperGeometric: public Random {
|
||||
protected:
|
||||
double pMean;
|
||||
double pVariance;
|
||||
double pP;
|
||||
void setState();
|
||||
|
||||
public:
|
||||
HyperGeometric(double mean, double variance, RNG *gen);
|
||||
|
||||
double mean();
|
||||
double mean(double x);
|
||||
double variance();
|
||||
double variance(double x);
|
||||
|
||||
virtual double operator()();
|
||||
};
|
||||
|
||||
|
||||
inline void HyperGeometric::setState() {
|
||||
double z = pVariance / (pMean * pMean);
|
||||
pP = 0.5 * (1.0 - sqrt((z - 1.0) / ( z + 1.0 )));
|
||||
}
|
||||
|
||||
inline HyperGeometric::HyperGeometric(double mean, double variance, RNG *gen)
|
||||
: Random(gen) {
|
||||
pMean = mean; pVariance = variance;
|
||||
setState();
|
||||
}
|
||||
|
||||
inline double HyperGeometric::mean() { return pMean; };
|
||||
|
||||
inline double HyperGeometric::mean(double x) {
|
||||
double t = pMean; pMean = x;
|
||||
setState(); return t;
|
||||
}
|
||||
|
||||
inline double HyperGeometric::variance() { return pVariance; }
|
||||
|
||||
inline double HyperGeometric::variance(double x) {
|
||||
double t = pVariance; pVariance = x;
|
||||
setState(); return t;
|
||||
}
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,30 +0,0 @@
|
|||
// Stuff used to implement the Integer class.
|
||||
// WARNING: Its internals WILL change!
|
||||
|
||||
/*
|
||||
Sizes of shifts for multiple-precision arithmetic.
|
||||
These should not be changed unless Integer representation
|
||||
as unsigned shorts is changed in the implementation files.
|
||||
*/
|
||||
|
||||
#define I_SHIFT (sizeof(short) * CHAR_BIT)
|
||||
#define I_RADIX ((unsigned long)(1L << I_SHIFT))
|
||||
#define I_MAXNUM ((unsigned long)((I_RADIX - 1)))
|
||||
#define I_MINNUM ((unsigned long)(I_RADIX >> 1))
|
||||
#define I_POSITIVE 1
|
||||
#define I_NEGATIVE 0
|
||||
|
||||
/* All routines assume SHORT_PER_LONG > 1 */
|
||||
#define SHORT_PER_LONG ((unsigned)(((sizeof(long) + sizeof(short) - 1) / sizeof(short))))
|
||||
#define CHAR_PER_LONG ((unsigned)sizeof(long))
|
||||
|
||||
/*
|
||||
minimum and maximum sizes for an IntRep
|
||||
*/
|
||||
|
||||
#define MINIntRep_SIZE 16
|
||||
#define MAXIntRep_SIZE I_MAXNUM
|
||||
|
||||
#ifndef MALLOC_MIN_OVERHEAD
|
||||
#define MALLOC_MIN_OVERHEAD 4
|
||||
#endif
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Dirk Grunwald (grunwald@cs.uiuc.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifndef _LogNormal_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define _LogNormal_h
|
||||
|
||||
#include <Normal.h>
|
||||
|
||||
class LogNormal: public Normal {
|
||||
protected:
|
||||
double logMean;
|
||||
double logVariance;
|
||||
void setState();
|
||||
public:
|
||||
LogNormal(double mean, double variance, RNG *gen);
|
||||
double mean();
|
||||
double mean(double x);
|
||||
double variance();
|
||||
double variance(double x);
|
||||
virtual double operator()();
|
||||
};
|
||||
|
||||
|
||||
inline void LogNormal::setState()
|
||||
{
|
||||
double m2 = logMean * logMean;
|
||||
pMean = log(m2 / sqrt(logVariance + m2) );
|
||||
// from ch@heike.informatik.uni-dortmund.de:
|
||||
// (was pVariance = log((sqrt(logVariance + m2)/m2 )); )
|
||||
pStdDev = sqrt(log((logVariance + m2)/m2 ));
|
||||
}
|
||||
|
||||
inline LogNormal::LogNormal(double mean, double variance, RNG *gen)
|
||||
: Normal(mean, variance, gen)
|
||||
{
|
||||
logMean = mean;
|
||||
logVariance = variance;
|
||||
setState();
|
||||
}
|
||||
|
||||
inline double LogNormal::mean() {
|
||||
return logMean;
|
||||
}
|
||||
|
||||
inline double LogNormal::mean(double x)
|
||||
{
|
||||
double t=logMean; logMean = x; setState();
|
||||
return t;
|
||||
}
|
||||
|
||||
inline double LogNormal::variance() {
|
||||
return logVariance;
|
||||
}
|
||||
|
||||
inline double LogNormal::variance(double x)
|
||||
{
|
||||
double t=logVariance; logVariance = x; setState();
|
||||
return t;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Dirk Grunwald (grunwald@cs.uiuc.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifndef _MLCG_h
|
||||
#define _MLCG_h 1
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include <RNG.h>
|
||||
#include <math.h>
|
||||
|
||||
//
|
||||
// Multiplicative Linear Conguential Generator
|
||||
//
|
||||
|
||||
class MLCG : public RNG {
|
||||
_G_int32_t initialSeedOne;
|
||||
_G_int32_t initialSeedTwo;
|
||||
_G_int32_t seedOne;
|
||||
_G_int32_t seedTwo;
|
||||
|
||||
protected:
|
||||
|
||||
public:
|
||||
MLCG(_G_int32_t seed1 = 0, _G_int32_t seed2 = 1);
|
||||
//
|
||||
// Return a long-words word of random bits
|
||||
//
|
||||
virtual _G_uint32_t asLong();
|
||||
virtual void reset();
|
||||
_G_int32_t seed1();
|
||||
void seed1(_G_int32_t);
|
||||
_G_int32_t seed2();
|
||||
void seed2(_G_int32_t);
|
||||
void reseed(_G_int32_t, _G_int32_t);
|
||||
};
|
||||
|
||||
inline _G_int32_t
|
||||
MLCG::seed1()
|
||||
{
|
||||
return(seedOne);
|
||||
}
|
||||
|
||||
inline void
|
||||
MLCG::seed1(_G_int32_t s)
|
||||
{
|
||||
initialSeedOne = s;
|
||||
reset();
|
||||
}
|
||||
|
||||
inline _G_int32_t
|
||||
MLCG::seed2()
|
||||
{
|
||||
return(seedTwo);
|
||||
}
|
||||
|
||||
inline void
|
||||
MLCG::seed2(_G_int32_t s)
|
||||
{
|
||||
initialSeedTwo = s;
|
||||
reset();
|
||||
}
|
||||
|
||||
inline void
|
||||
MLCG::reseed(_G_int32_t s1, _G_int32_t s2)
|
||||
{
|
||||
initialSeedOne = s1;
|
||||
initialSeedTwo = s2;
|
||||
reset();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Dirk Grunwald (grunwald@cs.uiuc.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifndef _NegativeExpntl_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define _NegativeExpntl_h 1
|
||||
|
||||
|
||||
//
|
||||
// Negative Exponential Random Numbers
|
||||
//
|
||||
//
|
||||
|
||||
#include <Random.h>
|
||||
|
||||
class NegativeExpntl: public Random {
|
||||
protected:
|
||||
double pMean;
|
||||
public:
|
||||
NegativeExpntl(double xmean, RNG *gen);
|
||||
double mean();
|
||||
double mean(double x);
|
||||
|
||||
virtual double operator()();
|
||||
};
|
||||
|
||||
|
||||
inline NegativeExpntl::NegativeExpntl(double xmean, RNG *gen)
|
||||
: Random(gen) {
|
||||
pMean = xmean;
|
||||
}
|
||||
|
||||
inline double NegativeExpntl::mean() { return pMean; }
|
||||
inline double NegativeExpntl::mean(double x) {
|
||||
double t = pMean; pMean = x;
|
||||
return t;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Dirk Grunwald (grunwald@cs.uiuc.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifndef _Normal_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define _Normal_h
|
||||
|
||||
#include <Random.h>
|
||||
|
||||
class Normal: public Random {
|
||||
char haveCachedNormal;
|
||||
double cachedNormal;
|
||||
|
||||
protected:
|
||||
double pMean;
|
||||
double pVariance;
|
||||
double pStdDev;
|
||||
|
||||
public:
|
||||
Normal(double xmean, double xvariance, RNG *gen);
|
||||
double mean();
|
||||
double mean(double x);
|
||||
double variance();
|
||||
double variance(double x);
|
||||
virtual double operator()();
|
||||
};
|
||||
|
||||
|
||||
inline Normal::Normal(double xmean, double xvariance, RNG *gen)
|
||||
: Random(gen) {
|
||||
pMean = xmean;
|
||||
pVariance = xvariance;
|
||||
pStdDev = sqrt(pVariance);
|
||||
haveCachedNormal = 0;
|
||||
}
|
||||
|
||||
inline double Normal::mean() { return pMean; };
|
||||
inline double Normal::mean(double x) {
|
||||
double t=pMean; pMean = x;
|
||||
return t;
|
||||
}
|
||||
|
||||
inline double Normal::variance() { return pVariance; }
|
||||
inline double Normal::variance(double x) {
|
||||
double t=pVariance; pVariance = x;
|
||||
pStdDev = sqrt(pVariance);
|
||||
return t;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,216 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Doug Lea (dl@rocky.oswego.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _Obstack_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define _Obstack_h 1
|
||||
|
||||
#include <std.h>
|
||||
|
||||
class Obstack
|
||||
{
|
||||
struct _obstack_chunk
|
||||
{
|
||||
char* limit;
|
||||
_obstack_chunk* prev;
|
||||
char contents[4];
|
||||
};
|
||||
|
||||
protected:
|
||||
long chunksize;
|
||||
_obstack_chunk* chunk;
|
||||
char* objectbase;
|
||||
char* nextfree;
|
||||
char* chunklimit;
|
||||
int alignmentmask;
|
||||
|
||||
void _free(void* obj);
|
||||
void newchunk(int size);
|
||||
|
||||
public:
|
||||
Obstack(int size = 4080, int alignment = 4); // 4080=4096-mallocslop
|
||||
|
||||
~Obstack();
|
||||
|
||||
void* base();
|
||||
void* next_free();
|
||||
int alignment_mask();
|
||||
int chunk_size();
|
||||
int size();
|
||||
int room();
|
||||
int contains(void* p); // does Obstack hold pointer p?
|
||||
|
||||
void grow(const void* data, int size);
|
||||
void grow(const void* data, int size, char terminator);
|
||||
void grow(const char* s);
|
||||
void grow(char c);
|
||||
void grow_fast(char c);
|
||||
void blank(int size);
|
||||
void blank_fast(int size);
|
||||
|
||||
void* finish();
|
||||
void* finish(char terminator);
|
||||
|
||||
void* copy(const void* data, int size);
|
||||
void* copy(const void* data, int size, char terminator);
|
||||
void* copy(const char* s);
|
||||
void* copy(char c);
|
||||
void* alloc(int size);
|
||||
|
||||
void free(void* obj);
|
||||
void shrink(int size = 1); // suggested by ken@cs.rochester.edu
|
||||
|
||||
int OK(); // rep invariant
|
||||
};
|
||||
|
||||
|
||||
inline Obstack::~Obstack()
|
||||
{
|
||||
_free(0);
|
||||
}
|
||||
|
||||
inline void* Obstack::base()
|
||||
{
|
||||
return objectbase;
|
||||
}
|
||||
|
||||
inline void* Obstack::next_free()
|
||||
{
|
||||
return nextfree;
|
||||
}
|
||||
|
||||
inline int Obstack::alignment_mask()
|
||||
{
|
||||
return alignmentmask;
|
||||
}
|
||||
|
||||
inline int Obstack::chunk_size()
|
||||
{
|
||||
return chunksize;
|
||||
}
|
||||
|
||||
inline int Obstack::size()
|
||||
{
|
||||
return nextfree - objectbase;
|
||||
}
|
||||
|
||||
inline int Obstack::room()
|
||||
{
|
||||
return chunklimit - nextfree;
|
||||
}
|
||||
|
||||
inline void Obstack:: grow(const void* data, int size)
|
||||
{
|
||||
if (nextfree+size > chunklimit)
|
||||
newchunk(size);
|
||||
memcpy(nextfree, data, size);
|
||||
nextfree += size;
|
||||
}
|
||||
|
||||
inline void Obstack:: grow(const void* data, int size, char terminator)
|
||||
{
|
||||
if (nextfree+size+1 > chunklimit)
|
||||
newchunk(size+1);
|
||||
memcpy(nextfree, data, size);
|
||||
nextfree += size;
|
||||
*(nextfree)++ = terminator;
|
||||
}
|
||||
|
||||
inline void Obstack:: grow(const char* s)
|
||||
{
|
||||
grow((const void*)s, strlen(s), 0);
|
||||
}
|
||||
|
||||
inline void Obstack:: grow(char c)
|
||||
{
|
||||
if (nextfree+1 > chunklimit)
|
||||
newchunk(1);
|
||||
*(nextfree)++ = c;
|
||||
}
|
||||
|
||||
inline void Obstack:: blank(int size)
|
||||
{
|
||||
if (nextfree+size > chunklimit)
|
||||
newchunk(size);
|
||||
nextfree += size;
|
||||
}
|
||||
|
||||
inline void* Obstack::finish(char terminator)
|
||||
{
|
||||
grow(terminator);
|
||||
return finish();
|
||||
}
|
||||
|
||||
inline void* Obstack::copy(const void* data, int size)
|
||||
{
|
||||
grow (data, size);
|
||||
return finish();
|
||||
}
|
||||
|
||||
inline void* Obstack::copy(const void* data, int size, char terminator)
|
||||
{
|
||||
grow(data, size, terminator);
|
||||
return finish();
|
||||
}
|
||||
|
||||
inline void* Obstack::copy(const char* s)
|
||||
{
|
||||
grow((const void*)s, strlen(s), 0);
|
||||
return finish();
|
||||
}
|
||||
|
||||
inline void* Obstack::copy(char c)
|
||||
{
|
||||
grow(c);
|
||||
return finish();
|
||||
}
|
||||
|
||||
inline void* Obstack::alloc(int size)
|
||||
{
|
||||
blank(size);
|
||||
return finish();
|
||||
}
|
||||
|
||||
inline void Obstack:: free(void* obj)
|
||||
{
|
||||
if (obj >= (void*)chunk && obj<(void*)chunklimit)
|
||||
nextfree = objectbase = (char *) obj;
|
||||
else
|
||||
_free(obj);
|
||||
}
|
||||
|
||||
inline void Obstack:: grow_fast(char c)
|
||||
{
|
||||
*(nextfree)++ = c;
|
||||
}
|
||||
|
||||
inline void Obstack:: blank_fast(int size)
|
||||
{
|
||||
nextfree += size;
|
||||
}
|
||||
|
||||
inline void Obstack:: shrink(int size) // from ken@cs.rochester.edu
|
||||
{
|
||||
if (nextfree >= objectbase + size)
|
||||
nextfree -= size;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
|
||||
#ifndef _Pix_h
|
||||
#define _Pix_h 1
|
||||
typedef void* Pix;
|
||||
#endif
|
||||
|
|
@ -1,121 +0,0 @@
|
|||
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
|
||||
Copyright (C) 1993 Free Software Foundation
|
||||
|
||||
This file is part of the GNU IO Library. This library 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, or (at your option)
|
||||
any later version.
|
||||
|
||||
This library 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 GNU CC; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
As a special exception, if you link this library with files
|
||||
compiled with a GNU compiler to produce an executable, this does not cause
|
||||
the resulting executable to be covered by the GNU General Public License.
|
||||
This exception does not however invalidate any other reasons why
|
||||
the executable file might be covered by the GNU General Public License. */
|
||||
|
||||
/*
|
||||
a very simple implementation of a class to output unix "plot"
|
||||
format plotter files. See corresponding unix man pages for
|
||||
more details.
|
||||
|
||||
written by Doug Lea (dl@rocky.oswego.edu)
|
||||
converted to use iostream library by Per Bothner (bothner@cygnus.com)
|
||||
*/
|
||||
|
||||
#ifndef _PlotFile_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define _PlotFile_h
|
||||
|
||||
#include <fstream.h>
|
||||
|
||||
/*
|
||||
Some plot libraries have the `box' command to draw boxes. Some don't.
|
||||
`box' is included here via moves & lines to allow both possiblilties.
|
||||
*/
|
||||
|
||||
|
||||
class PlotFile : public ofstream
|
||||
{
|
||||
protected:
|
||||
PlotFile& cmd(char c);
|
||||
PlotFile& operator << (const int x);
|
||||
PlotFile& operator << (const char *s);
|
||||
|
||||
public:
|
||||
|
||||
PlotFile() : ofstream() { }
|
||||
PlotFile(int fd) : ofstream(fd) { }
|
||||
PlotFile(const char *name, int mode=ios::out, int prot=0664)
|
||||
: ofstream(name, mode, prot) { }
|
||||
|
||||
// PlotFile& remove() { ofstream::remove(); return *this; }
|
||||
|
||||
// int filedesc() { return ofstream::filedesc(); }
|
||||
// const char* name() { return File::name(); }
|
||||
// void setname(const char* newname) { File::setname(newname); }
|
||||
// int iocount() { return File::iocount(); }
|
||||
|
||||
PlotFile& arc(const int xi, const int yi,
|
||||
const int x0, const int y0,
|
||||
const int x1, const int y1);
|
||||
PlotFile& box(const int x0, const int y0,
|
||||
const int x1, const int y1);
|
||||
PlotFile& circle(const int x, const int y, const int r);
|
||||
PlotFile& cont(const int xi, const int yi);
|
||||
PlotFile& dot(const int xi, const int yi, const int dx,
|
||||
int n, const int* pat);
|
||||
PlotFile& erase();
|
||||
PlotFile& label(const char* s);
|
||||
PlotFile& line(const int x0, const int y0,
|
||||
const int x1, const int y1);
|
||||
PlotFile& linemod(const char* s);
|
||||
PlotFile& move(const int xi, const int yi);
|
||||
PlotFile& point(const int xi, const int yi);
|
||||
PlotFile& space(const int x0, const int y0,
|
||||
const int x1, const int y1);
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Dirk Grunwald (grunwald@cs.uiuc.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifndef _Poisson_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define _Poisson_h
|
||||
|
||||
#include <Random.h>
|
||||
|
||||
class Poisson: public Random {
|
||||
protected:
|
||||
double pMean;
|
||||
public:
|
||||
Poisson(double mean, RNG *gen);
|
||||
|
||||
double mean();
|
||||
double mean(double x);
|
||||
|
||||
virtual double operator()();
|
||||
};
|
||||
|
||||
|
||||
inline Poisson::Poisson(double mean, RNG *gen)
|
||||
: Random(gen) {
|
||||
pMean = mean;
|
||||
}
|
||||
|
||||
inline double Poisson::mean() { return pMean; }
|
||||
inline double Poisson::mean(double x) {
|
||||
double t = pMean;
|
||||
pMean = x;
|
||||
return t;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Dirk Grunwald (grunwald@cs.uiuc.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifndef _RNG_h
|
||||
#define _RNG_h 1
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <_G_config.h>
|
||||
|
||||
union PrivateRNGSingleType { // used to access floats as unsigneds
|
||||
float s;
|
||||
_G_uint32_t u;
|
||||
};
|
||||
|
||||
union PrivateRNGDoubleType { // used to access doubles as unsigneds
|
||||
double d;
|
||||
_G_uint32_t u[2];
|
||||
};
|
||||
|
||||
//
|
||||
// Base class for Random Number Generators. See ACG and MLCG for instances.
|
||||
//
|
||||
class RNG {
|
||||
static PrivateRNGSingleType singleMantissa; // mantissa bit vector
|
||||
static PrivateRNGDoubleType doubleMantissa; // mantissa bit vector
|
||||
public:
|
||||
RNG();
|
||||
//
|
||||
// Return a long-words word of random bits
|
||||
//
|
||||
virtual _G_uint32_t asLong() = 0;
|
||||
virtual void reset() = 0;
|
||||
//
|
||||
// Return random bits converted to either a float or a double
|
||||
//
|
||||
float asFloat();
|
||||
double asDouble();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Dirk Grunwald (grunwald@cs.uiuc.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifndef _Random_h
|
||||
#define _Random_h 1
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
#include <RNG.h>
|
||||
|
||||
class Random {
|
||||
protected:
|
||||
RNG *pGenerator;
|
||||
public:
|
||||
Random(RNG *generator);
|
||||
virtual double operator()() = 0;
|
||||
|
||||
RNG *generator();
|
||||
void generator(RNG *p);
|
||||
};
|
||||
|
||||
|
||||
inline Random::Random(RNG *gen)
|
||||
{
|
||||
pGenerator = gen;
|
||||
}
|
||||
|
||||
inline RNG *Random::generator()
|
||||
{
|
||||
return(pGenerator);
|
||||
}
|
||||
|
||||
inline void Random::generator(RNG *p)
|
||||
{
|
||||
pGenerator = p;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,288 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Doug Lea (dl@rocky.oswego.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef _Rational_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define _Rational_h 1
|
||||
|
||||
#include <Integer.h>
|
||||
#include <math.h>
|
||||
|
||||
class Rational
|
||||
{
|
||||
protected:
|
||||
Integer num;
|
||||
Integer den;
|
||||
|
||||
void normalize();
|
||||
|
||||
public:
|
||||
Rational();
|
||||
Rational(double);
|
||||
Rational(int n);
|
||||
Rational(long n);
|
||||
Rational(int n, int d);
|
||||
Rational(long n, long d);
|
||||
Rational(long n, unsigned long d);
|
||||
Rational(unsigned long n, long d);
|
||||
Rational(unsigned long n, unsigned long d);
|
||||
Rational(const Integer& n);
|
||||
Rational(const Integer& n, const Integer& d);
|
||||
Rational(const Rational&);
|
||||
|
||||
~Rational();
|
||||
|
||||
Rational& operator = (const Rational& y);
|
||||
|
||||
friend int operator == (const Rational& x, const Rational& y);
|
||||
friend int operator != (const Rational& x, const Rational& y);
|
||||
friend int operator < (const Rational& x, const Rational& y);
|
||||
friend int operator <= (const Rational& x, const Rational& y);
|
||||
friend int operator > (const Rational& x, const Rational& y);
|
||||
friend int operator >= (const Rational& x, const Rational& y);
|
||||
|
||||
friend Rational operator + (const Rational& x, const Rational& y);
|
||||
friend Rational operator - (const Rational& x, const Rational& y);
|
||||
friend Rational operator * (const Rational& x, const Rational& y);
|
||||
friend Rational operator / (const Rational& x, const Rational& y);
|
||||
|
||||
Rational& operator += (const Rational& y);
|
||||
Rational& operator -= (const Rational& y);
|
||||
Rational& operator *= (const Rational& y);
|
||||
Rational& operator /= (const Rational& y);
|
||||
|
||||
#if defined (__GNUG__) && ! defined (__STRICT_ANSI__)
|
||||
friend Rational operator <? (const Rational& x, const Rational& y); // min
|
||||
friend Rational operator >? (const Rational& x, const Rational& y); // max
|
||||
#endif
|
||||
|
||||
friend Rational operator - (const Rational& x);
|
||||
|
||||
|
||||
// builtin Rational functions
|
||||
|
||||
|
||||
void negate(); // x = -x
|
||||
void invert(); // x = 1/x
|
||||
|
||||
friend int sign(const Rational& x); // -1, 0, or +1
|
||||
friend Rational abs(const Rational& x); // absolute value
|
||||
friend Rational sqr(const Rational& x); // square
|
||||
friend Rational pow(const Rational& x, long y);
|
||||
friend Rational pow(const Rational& x, const Integer& y);
|
||||
const Integer& numerator() const;
|
||||
const Integer& denominator() const;
|
||||
|
||||
// coercion & conversion
|
||||
|
||||
operator double() const;
|
||||
friend Integer floor(const Rational& x);
|
||||
friend Integer ceil(const Rational& x);
|
||||
friend Integer trunc(const Rational& x);
|
||||
friend Integer round(const Rational& x);
|
||||
|
||||
friend istream& operator >> (istream& s, Rational& y);
|
||||
friend ostream& operator << (ostream& s, const Rational& y);
|
||||
|
||||
int fits_in_float() const;
|
||||
int fits_in_double() const;
|
||||
|
||||
// procedural versions of operators
|
||||
|
||||
friend int compare(const Rational& x, const Rational& y);
|
||||
friend void add(const Rational& x, const Rational& y, Rational& dest);
|
||||
friend void sub(const Rational& x, const Rational& y, Rational& dest);
|
||||
friend void mul(const Rational& x, const Rational& y, Rational& dest);
|
||||
friend void div(const Rational& x, const Rational& y, Rational& dest);
|
||||
|
||||
// error detection
|
||||
|
||||
void error(const char* msg) const;
|
||||
int OK() const;
|
||||
|
||||
};
|
||||
|
||||
typedef Rational RatTmp; // backwards compatibility
|
||||
|
||||
inline Rational::Rational() : num(&_ZeroRep), den(&_OneRep) {}
|
||||
inline Rational::~Rational() {}
|
||||
|
||||
inline Rational::Rational(const Rational& y) :num(y.num), den(y.den) {}
|
||||
|
||||
inline Rational::Rational(const Integer& n) :num(n), den(&_OneRep) {}
|
||||
|
||||
inline Rational::Rational(const Integer& n, const Integer& d) :num(n),den(d)
|
||||
{
|
||||
normalize();
|
||||
}
|
||||
|
||||
inline Rational::Rational(long n) :num(n), den(&_OneRep) { }
|
||||
|
||||
inline Rational::Rational(int n) :num(n), den(&_OneRep) { }
|
||||
|
||||
inline Rational::Rational(long n, long d) :num(n), den(d) { normalize(); }
|
||||
inline Rational::Rational(int n, int d) :num(n), den(d) { normalize(); }
|
||||
inline Rational::Rational(long n, unsigned long d) :num(n), den(d)
|
||||
{
|
||||
normalize();
|
||||
}
|
||||
inline Rational::Rational(unsigned long n, long d) :num(n), den(d)
|
||||
{
|
||||
normalize();
|
||||
}
|
||||
inline Rational::Rational(unsigned long n, unsigned long d) :num(n), den(d)
|
||||
{
|
||||
normalize();
|
||||
}
|
||||
|
||||
inline Rational& Rational::operator = (const Rational& y)
|
||||
{
|
||||
num = y.num; den = y.den;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline int operator == (const Rational& x, const Rational& y)
|
||||
{
|
||||
return compare(x.num, y.num) == 0 && compare(x.den, y.den) == 0;
|
||||
}
|
||||
|
||||
inline int operator != (const Rational& x, const Rational& y)
|
||||
{
|
||||
return compare(x.num, y.num) != 0 || compare(x.den, y.den) != 0;
|
||||
}
|
||||
|
||||
inline int operator < (const Rational& x, const Rational& y)
|
||||
{
|
||||
return compare(x, y) < 0;
|
||||
}
|
||||
|
||||
inline int operator <= (const Rational& x, const Rational& y)
|
||||
{
|
||||
return compare(x, y) <= 0;
|
||||
}
|
||||
|
||||
inline int operator > (const Rational& x, const Rational& y)
|
||||
{
|
||||
return compare(x, y) > 0;
|
||||
}
|
||||
|
||||
inline int operator >= (const Rational& x, const Rational& y)
|
||||
{
|
||||
return compare(x, y) >= 0;
|
||||
}
|
||||
|
||||
inline int sign(const Rational& x)
|
||||
{
|
||||
return sign(x.num);
|
||||
}
|
||||
|
||||
inline void Rational::negate()
|
||||
{
|
||||
num.negate();
|
||||
}
|
||||
|
||||
|
||||
inline Rational& Rational::operator += (const Rational& y)
|
||||
{
|
||||
add(*this, y, *this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Rational& Rational::operator -= (const Rational& y)
|
||||
{
|
||||
sub(*this, y, *this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Rational& Rational::operator *= (const Rational& y)
|
||||
{
|
||||
mul(*this, y, *this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Rational& Rational::operator /= (const Rational& y)
|
||||
{
|
||||
div(*this, y, *this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline const Integer& Rational::numerator() const { return num; }
|
||||
inline const Integer& Rational::denominator() const { return den; }
|
||||
inline Rational::operator double() const { return ratio(num, den); }
|
||||
|
||||
#if defined (__GNUG__) && ! defined (__STRICT_ANSI__)
|
||||
inline Rational operator <? (const Rational& x, const Rational& y)
|
||||
{
|
||||
if (compare(x, y) <= 0) return x; else return y;
|
||||
}
|
||||
|
||||
inline Rational operator >? (const Rational& x, const Rational& y)
|
||||
{
|
||||
if (compare(x, y) >= 0) return x; else return y;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__GNUG__) && !defined(_G_NO_NRV)
|
||||
|
||||
inline Rational operator + (const Rational& x, const Rational& y) return r
|
||||
{
|
||||
add(x, y, r);
|
||||
}
|
||||
|
||||
inline Rational operator - (const Rational& x, const Rational& y) return r
|
||||
{
|
||||
sub(x, y, r);
|
||||
}
|
||||
|
||||
inline Rational operator * (const Rational& x, const Rational& y) return r
|
||||
{
|
||||
mul(x, y, r);
|
||||
}
|
||||
|
||||
inline Rational operator / (const Rational& x, const Rational& y) return r
|
||||
{
|
||||
div(x, y, r);
|
||||
}
|
||||
|
||||
#else /* NO_NRV */
|
||||
|
||||
inline Rational operator + (const Rational& x, const Rational& y)
|
||||
{
|
||||
Rational r; add(x, y, r); return r;
|
||||
}
|
||||
|
||||
inline Rational operator - (const Rational& x, const Rational& y)
|
||||
{
|
||||
Rational r; sub(x, y, r); return r;
|
||||
}
|
||||
|
||||
inline Rational operator * (const Rational& x, const Rational& y)
|
||||
{
|
||||
Rational r; mul(x, y, r); return r;
|
||||
}
|
||||
|
||||
inline Rational operator / (const Rational& x, const Rational& y)
|
||||
{
|
||||
Rational r; div(x, y, r); return r;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Doug Lea (dl@rocky.oswego.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _Regex_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define _Regex_h 1
|
||||
|
||||
#if defined(SHORT_NAMES) || defined(VMS)
|
||||
#define re_compile_pattern recmppat
|
||||
#define re_pattern_buffer repatbuf
|
||||
#define re_registers reregs
|
||||
#endif
|
||||
|
||||
struct re_pattern_buffer; // defined elsewhere
|
||||
struct re_registers;
|
||||
|
||||
class Regex
|
||||
{
|
||||
private:
|
||||
|
||||
Regex(const Regex&) {} // no X(X&)
|
||||
void operator = (const Regex&) {} // no assignment
|
||||
|
||||
protected:
|
||||
re_pattern_buffer* buf;
|
||||
re_registers* reg;
|
||||
|
||||
public:
|
||||
Regex(const char* t,
|
||||
int fast = 0,
|
||||
int bufsize = 40,
|
||||
const char* transtable = 0);
|
||||
|
||||
~Regex();
|
||||
|
||||
int match(const char* s, int len, int pos = 0) const;
|
||||
int search(const char* s, int len,
|
||||
int& matchlen, int startpos = 0) const;
|
||||
int match_info(int& start, int& length, int nth = 0) const;
|
||||
|
||||
int OK() const; // representation invariant
|
||||
};
|
||||
|
||||
// some built in regular expressions
|
||||
|
||||
extern const Regex RXwhite; // = "[ \n\t\r\v\f]+"
|
||||
extern const Regex RXint; // = "-?[0-9]+"
|
||||
extern const Regex RXdouble; // = "-?\\(\\([0-9]+\\.[0-9]*\\)\\|
|
||||
// \\([0-9]+\\)\\|\\(\\.[0-9]+\\)\\)
|
||||
// \\([eE][---+]?[0-9]+\\)?"
|
||||
extern const Regex RXalpha; // = "[A-Za-z]+"
|
||||
extern const Regex RXlowercase; // = "[a-z]+"
|
||||
extern const Regex RXuppercase; // = "[A-Z]+"
|
||||
extern const Regex RXalphanum; // = "[0-9A-Za-z]+"
|
||||
extern const Regex RXidentifier; // = "[A-Za-z_][A-Za-z0-9_]*"
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -1,175 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1990 Free Software Foundation
|
||||
adapted from a submission from John Reidl <riedl@cs.purdue.edu>
|
||||
|
||||
|
||||
GNU CC is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY. No author or distributor
|
||||
accepts responsibility to anyone for the consequences of using it
|
||||
or for whether it serves any particular purpose or works at all,
|
||||
unless he says so in writing. Refer to the GNU CC General Public
|
||||
License for full details.
|
||||
|
||||
Everyone is granted permission to copy, modify and redistribute
|
||||
GNU CC, but only under the conditions described in the
|
||||
GNU CC General Public License. A copy of this license is
|
||||
supposed to have been given to you along with GNU CC so you
|
||||
can know your rights and responsibilities. It should be in a
|
||||
file named COPYING. Among other things, the copyright notice
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef _RandomInteger_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define _RandomInteger_h 1
|
||||
|
||||
// RandomInteger uses a random number generator to generate an integer
|
||||
// in a specified range. By default the range is 0..1. Since in my
|
||||
// experience random numbers are often needed for a wide variety of
|
||||
// ranges in the same program, this generator accepts a new low or high value
|
||||
// as an argument to the asLong and operator() methods to temporarily
|
||||
// override stored values
|
||||
|
||||
#include <math.h>
|
||||
#include <RNG.h>
|
||||
|
||||
class RandomInteger
|
||||
{
|
||||
protected:
|
||||
RNG *pGenerator;
|
||||
long pLow;
|
||||
long pHigh;
|
||||
|
||||
long _asLong(long, long);
|
||||
|
||||
public:
|
||||
|
||||
RandomInteger(long low, long high, RNG *gen);
|
||||
RandomInteger(long high, RNG *gen);
|
||||
RandomInteger(RNG *gen);
|
||||
|
||||
// read params
|
||||
|
||||
long low() const;
|
||||
long high() const;
|
||||
RNG* generator() const;
|
||||
|
||||
// change params
|
||||
|
||||
long low(long x);
|
||||
long high(long x);
|
||||
RNG* generator(RNG *gen);
|
||||
|
||||
// get a random number
|
||||
|
||||
long asLong();
|
||||
long operator()(); // synonym for asLong
|
||||
int asInt(); // (possibly) truncate as int
|
||||
|
||||
// override params for one shot
|
||||
|
||||
long asLong(long high);
|
||||
long asLong(long low, long high);
|
||||
|
||||
long operator () (long high); // synonyms
|
||||
long operator () (long low, long high);
|
||||
|
||||
};
|
||||
|
||||
|
||||
inline RandomInteger::RandomInteger(long low, long high, RNG *gen)
|
||||
: pLow((low < high) ? low : high),
|
||||
pHigh((low < high) ? high : low),
|
||||
pGenerator(gen)
|
||||
{}
|
||||
|
||||
inline RandomInteger::RandomInteger(long high, RNG *gen)
|
||||
: pLow((0 < high) ? 0 : high),
|
||||
pHigh((0 < high) ? high : 0),
|
||||
pGenerator(gen)
|
||||
{}
|
||||
|
||||
|
||||
inline RandomInteger::RandomInteger(RNG *gen)
|
||||
: pLow(0),
|
||||
pHigh(1),
|
||||
pGenerator(gen)
|
||||
{}
|
||||
|
||||
inline RNG* RandomInteger::generator() const { return pGenerator;}
|
||||
inline long RandomInteger::low() const { return pLow; }
|
||||
inline long RandomInteger::high() const { return pHigh; }
|
||||
|
||||
inline RNG* RandomInteger::generator(RNG *gen)
|
||||
{
|
||||
RNG *tmp = pGenerator; pGenerator = gen; return tmp;
|
||||
}
|
||||
|
||||
inline long RandomInteger::low(long x)
|
||||
{
|
||||
long tmp = pLow; pLow = x; return tmp;
|
||||
}
|
||||
|
||||
inline long RandomInteger:: high(long x)
|
||||
{
|
||||
long tmp = pHigh; pHigh = x; return tmp;
|
||||
}
|
||||
|
||||
inline long RandomInteger:: _asLong(long low, long high)
|
||||
{
|
||||
return (pGenerator->asLong() % (high-low+1)) + low;
|
||||
}
|
||||
|
||||
|
||||
inline long RandomInteger:: asLong()
|
||||
{
|
||||
return _asLong(pLow, pHigh);
|
||||
}
|
||||
|
||||
inline long RandomInteger:: asLong(long high)
|
||||
{
|
||||
return _asLong(pLow, high);
|
||||
}
|
||||
|
||||
inline long RandomInteger:: asLong(long low, long high)
|
||||
{
|
||||
return _asLong(low, high);
|
||||
}
|
||||
|
||||
inline long RandomInteger:: operator () ()
|
||||
{
|
||||
return _asLong(pLow, pHigh);
|
||||
}
|
||||
|
||||
inline long RandomInteger:: operator () (long high)
|
||||
{
|
||||
return _asLong(pLow, high);
|
||||
}
|
||||
|
||||
inline long RandomInteger:: operator () (long low, long high)
|
||||
{
|
||||
return _asLong(low, high);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
inline int RandomInteger:: asInt()
|
||||
{
|
||||
return int(asLong());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
|
||||
Copyright (C) 1988, 1992, 1993 Free Software Foundation
|
||||
written by Doug Lea (dl@rocky.oswego.edu)
|
||||
|
||||
This file is part of the GNU IO Library. This library 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, or (at your option)
|
||||
any later version.
|
||||
|
||||
This library 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 GNU CC; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
As a special exception, if you link this library with files
|
||||
compiled with a GNU compiler to produce an executable, this does not cause
|
||||
the resulting executable to be covered by the GNU General Public License.
|
||||
This exception does not however invalidate any other reasons why
|
||||
the executable file might be covered by the GNU General Public License. */
|
||||
|
||||
#ifndef _SFile_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define _SFile_h 1
|
||||
|
||||
#include <fstream.h>
|
||||
|
||||
class SFile: public fstream
|
||||
{
|
||||
protected:
|
||||
int sz; // unit size for structured binary IO
|
||||
|
||||
public:
|
||||
SFile() : fstream() { }
|
||||
SFile(int fd, int size);
|
||||
SFile(const char *name, int size, int mode, int prot=0664);
|
||||
void open(const char *name, int size, int mode, int prot=0664);
|
||||
|
||||
int size() { return sz; }
|
||||
int setsize(int s) { int old = sz; sz = s; return old; }
|
||||
|
||||
SFile& get(void* x);
|
||||
SFile& put(void* x);
|
||||
SFile& operator[](long i);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,124 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988, 1992 Free Software Foundation
|
||||
written by Doug Lea (dl@rocky.oswego.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef _SLList_h
|
||||
#ifdef __GNUG__
|
||||
//#pragma interface
|
||||
#endif
|
||||
#define _SLList_h 1
|
||||
|
||||
#include <Pix.h>
|
||||
|
||||
struct BaseSLNode
|
||||
{
|
||||
BaseSLNode *tl;
|
||||
void *item() {return (void*)(this+1);} // Return ((SLNode<T>*)this)->hd
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class SLNode : public BaseSLNode
|
||||
{
|
||||
public:
|
||||
T hd; // Data part of node
|
||||
SLNode() { }
|
||||
SLNode(const T& h, SLNode* t = 0)
|
||||
: hd(h) { tl = t; }
|
||||
~SLNode() { }
|
||||
};
|
||||
|
||||
extern int __SLListLength(BaseSLNode *ptr);
|
||||
|
||||
class BaseSLList {
|
||||
protected:
|
||||
BaseSLNode *last;
|
||||
virtual void delete_node(BaseSLNode*node) = 0;
|
||||
virtual BaseSLNode* copy_node(const void* datum) = 0;
|
||||
virtual void copy_item(void *dst, void *src) = 0;
|
||||
virtual ~BaseSLList() { }
|
||||
BaseSLList() { last = 0; }
|
||||
void copy(const BaseSLList&);
|
||||
BaseSLList& operator = (const BaseSLList& a);
|
||||
Pix ins_after(Pix p, const void *datum);
|
||||
Pix prepend(const void *datum);
|
||||
Pix append(const void *datum);
|
||||
int remove_front(void *dst, int signal_error = 0);
|
||||
void join(BaseSLList&);
|
||||
public:
|
||||
int length() const;
|
||||
int empty() const { return last == 0; }
|
||||
void clear();
|
||||
Pix prepend(BaseSLNode*);
|
||||
Pix append(BaseSLNode*);
|
||||
int OK() const;
|
||||
void error(const char* msg) const;
|
||||
void del_after(Pix p);
|
||||
int owns(Pix p) const;
|
||||
void del_front();
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class SLList : public BaseSLList
|
||||
{
|
||||
private:
|
||||
virtual void delete_node(BaseSLNode *node) { delete (SLNode<T>*)node; }
|
||||
virtual BaseSLNode* copy_node(const void *datum)
|
||||
{ return new SLNode<T>(*(const T*)datum); }
|
||||
virtual void copy_item(void *dst, void *src) { *(T*)dst = *(T*)src; }
|
||||
|
||||
public:
|
||||
SLList() : BaseSLList() { }
|
||||
SLList(const SLList<T>& a) : BaseSLList() { copy(a); }
|
||||
SLList<T>& operator = (const SLList<T>& a)
|
||||
{ BaseSLList::operator=((const BaseSLList&) a); return *this; }
|
||||
virtual ~SLList() { clear(); }
|
||||
|
||||
Pix prepend(const T& item) {return BaseSLList::prepend(&item);}
|
||||
Pix append(const T& item) {return BaseSLList::append(&item);}
|
||||
Pix prepend(SLNode<T>* node) {return BaseSLList::prepend(node);}
|
||||
Pix append(SLNode<T>* node) {return BaseSLList::append(node);}
|
||||
|
||||
T& operator () (Pix p) {
|
||||
if (p == 0) error("null Pix");
|
||||
return ((SLNode<T>*)(p))->hd; }
|
||||
const T& operator () (Pix p) const {
|
||||
if (p == 0) error("null Pix");
|
||||
return ((SLNode<T>*)(p))->hd; }
|
||||
inline Pix first() const { return (last == 0) ? 0 : Pix(last->tl); }
|
||||
void next(Pix& p) const
|
||||
{ p = (p == 0 || p == last) ? 0 : Pix(((SLNode<T>*)(p))->tl); }
|
||||
Pix ins_after(Pix p, const T& item)
|
||||
{ return BaseSLList::ins_after(p, &item); }
|
||||
void join(SLList<T>& a) { BaseSLList::join(a); }
|
||||
|
||||
T& front() {
|
||||
if (last == 0) error("front: empty list");
|
||||
return ((SLNode<T>*)last->tl)->hd; }
|
||||
T& rear() {
|
||||
if (last == 0) error("rear: empty list");
|
||||
return ((SLNode<T>*)last)->hd; }
|
||||
const T& front() const {
|
||||
if (last == 0) error("front: empty list");
|
||||
return ((SLNode<T>*)last->tl)->hd; }
|
||||
const T& rear() const {
|
||||
if (last == 0) error("rear: empty list");
|
||||
return ((SLNode<T>*)last)->hd; }
|
||||
int remove_front(T& x) { return BaseSLList::remove_front(&x); }
|
||||
T remove_front() { T dst; BaseSLList::remove_front(&dst, 1); return dst; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Dirk Grunwald (grunwald@cs.uiuc.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef SampleHistogram_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define SampleHistogram_h 1
|
||||
|
||||
#include <iostream.h>
|
||||
#include <SmplStat.h>
|
||||
|
||||
extern const int SampleHistogramMinimum;
|
||||
extern const int SampleHistogramMaximum;
|
||||
|
||||
class SampleHistogram : public SampleStatistic
|
||||
{
|
||||
protected:
|
||||
short howManyBuckets;
|
||||
int *bucketCount;
|
||||
double *bucketLimit;
|
||||
|
||||
public:
|
||||
|
||||
SampleHistogram(double low, double hi, double bucketWidth = -1.0);
|
||||
|
||||
~SampleHistogram();
|
||||
|
||||
virtual void reset();
|
||||
virtual void operator+=(double);
|
||||
|
||||
int similarSamples(double);
|
||||
|
||||
int buckets();
|
||||
|
||||
double bucketThreshold(int i);
|
||||
int inBucket(int i);
|
||||
void printBuckets(ostream&);
|
||||
|
||||
};
|
||||
|
||||
|
||||
inline int SampleHistogram:: buckets() { return(howManyBuckets); };
|
||||
|
||||
inline double SampleHistogram:: bucketThreshold(int i) {
|
||||
if (i < 0 || i >= howManyBuckets)
|
||||
error("invalid bucket access");
|
||||
return(bucketLimit[i]);
|
||||
}
|
||||
|
||||
inline int SampleHistogram:: inBucket(int i) {
|
||||
if (i < 0 || i >= howManyBuckets)
|
||||
error("invalid bucket access");
|
||||
return(bucketCount[i]);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Dirk Grunwald (grunwald@cs.uiuc.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifndef SampleStatistic_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define SampleStatistic_h 1
|
||||
|
||||
#include <builtin.h>
|
||||
|
||||
class SampleStatistic {
|
||||
protected:
|
||||
int n;
|
||||
double x;
|
||||
double x2;
|
||||
double minValue, maxValue;
|
||||
|
||||
public :
|
||||
|
||||
SampleStatistic();
|
||||
virtual ~SampleStatistic();
|
||||
virtual void reset();
|
||||
|
||||
virtual void operator+=(double);
|
||||
int samples();
|
||||
double mean();
|
||||
double stdDev();
|
||||
double var();
|
||||
double min();
|
||||
double max();
|
||||
double confidence(int p_percentage);
|
||||
double confidence(double p_value);
|
||||
|
||||
void error(const char* msg);
|
||||
};
|
||||
|
||||
// error handlers
|
||||
|
||||
extern void default_SampleStatistic_error_handler(const char*);
|
||||
extern one_arg_error_handler_t SampleStatistic_error_handler;
|
||||
|
||||
extern one_arg_error_handler_t
|
||||
set_SampleStatistic_error_handler(one_arg_error_handler_t f);
|
||||
|
||||
inline SampleStatistic:: SampleStatistic(){ reset();}
|
||||
inline int SampleStatistic:: samples() {return(n);}
|
||||
inline double SampleStatistic:: min() {return(minValue);}
|
||||
inline double SampleStatistic:: max() {return(maxValue);}
|
||||
inline SampleStatistic::~SampleStatistic() {}
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,71 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Dirk Grunwald (grunwald@cs.uiuc.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifndef _Uniform_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define _Uniform_h 1
|
||||
|
||||
#include <Random.h>
|
||||
|
||||
//
|
||||
// The interval [lo..hi]
|
||||
//
|
||||
|
||||
class Uniform: public Random {
|
||||
double pLow;
|
||||
double pHigh;
|
||||
double delta;
|
||||
public:
|
||||
Uniform(double low, double high, RNG *gen);
|
||||
|
||||
double low();
|
||||
double low(double x);
|
||||
double high();
|
||||
double high(double x);
|
||||
|
||||
virtual double operator()();
|
||||
};
|
||||
|
||||
|
||||
inline Uniform::Uniform(double low, double high, RNG *gen) : Random(gen)
|
||||
{
|
||||
pLow = (low < high) ? low : high;
|
||||
pHigh = (low < high) ? high : low;
|
||||
delta = pHigh - pLow;
|
||||
}
|
||||
|
||||
inline double Uniform::low() { return pLow; }
|
||||
|
||||
inline double Uniform::low(double x) {
|
||||
double tmp = pLow;
|
||||
pLow = x;
|
||||
delta = pHigh - pLow;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
inline double Uniform::high() { return pHigh; }
|
||||
|
||||
inline double Uniform::high(double x) {
|
||||
double tmp = pHigh;
|
||||
pHigh = x;
|
||||
delta = pHigh - pLow;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Dirk Grunwald (grunwald@cs.uiuc.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifndef _Weibull_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define _Weibull_h
|
||||
|
||||
#include <Random.h>
|
||||
|
||||
class Weibull: public Random {
|
||||
protected:
|
||||
double pAlpha;
|
||||
double pInvAlpha;
|
||||
double pBeta;
|
||||
|
||||
void setState();
|
||||
|
||||
public:
|
||||
Weibull(double alpha, double beta, RNG *gen);
|
||||
|
||||
double alpha();
|
||||
double alpha(double x);
|
||||
|
||||
double beta();
|
||||
double beta(double x);
|
||||
|
||||
virtual double operator()();
|
||||
};
|
||||
|
||||
|
||||
inline void Weibull::setState() {
|
||||
pInvAlpha = 1.0 / pAlpha;
|
||||
}
|
||||
|
||||
inline Weibull::Weibull(double alpha, double beta, RNG *gen) : Random(gen)
|
||||
{
|
||||
pAlpha = alpha;
|
||||
pBeta = beta;
|
||||
setState();
|
||||
}
|
||||
|
||||
inline double Weibull::alpha() { return pAlpha; }
|
||||
|
||||
inline double Weibull::alpha(double x) {
|
||||
double tmp = pAlpha;
|
||||
pAlpha = x;
|
||||
setState();
|
||||
return tmp;
|
||||
}
|
||||
|
||||
inline double Weibull::beta() { return pBeta; };
|
||||
inline double Weibull::beta(double x) {
|
||||
double tmp = pBeta;
|
||||
pBeta = x;
|
||||
return tmp;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
/* AUTOMATICALLY GENERATED; DO NOT EDIT! */
|
||||
#include <sys/types.h>
|
||||
#ifndef _G_config_h
|
||||
#define _G_config_h
|
||||
#define _G_LIB_VERSION "0.66"
|
||||
#define _G_NAMES_HAVE_UNDERSCORE 1
|
||||
#define _G_VTABLE_LABEL_HAS_LENGTH 1
|
||||
#define _G_VTABLE_LABEL_PREFIX "__vt$"
|
||||
#define _G_HAVE_ST_BLKSIZE 1
|
||||
typedef unsigned long _G_clock_t;
|
||||
typedef unsigned long _G_dev_t;
|
||||
typedef quad_t _G_fpos_t;
|
||||
typedef unsigned long _G_gid_t;
|
||||
typedef unsigned long _G_ino_t;
|
||||
typedef unsigned short _G_mode_t;
|
||||
typedef unsigned short _G_nlink_t;
|
||||
typedef long long _G_off_t;
|
||||
typedef long _G_pid_t;
|
||||
#ifndef __PTRDIFF_TYPE__
|
||||
#define __PTRDIFF_TYPE__ int
|
||||
#endif
|
||||
typedef __PTRDIFF_TYPE__ _G_ptrdiff_t;
|
||||
typedef unsigned int _G_sigset_t;
|
||||
#ifndef __SIZE_TYPE__
|
||||
#define __SIZE_TYPE__ unsigned int
|
||||
#endif
|
||||
typedef __SIZE_TYPE__ _G_size_t;
|
||||
typedef long _G_time_t;
|
||||
typedef unsigned long _G_uid_t;
|
||||
#ifndef __WCHAR_TYPE__
|
||||
#define __WCHAR_TYPE__ int
|
||||
#endif
|
||||
typedef __WCHAR_TYPE__ _G_wchar_t;
|
||||
typedef int _G_ssize_t;
|
||||
typedef int /* default */ _G_wint_t;
|
||||
typedef char* /* default */ _G_va_list;
|
||||
#define _G_signal_return_type void
|
||||
#define _G_sprintf_return_type int
|
||||
#ifdef __STDC__
|
||||
typedef signed char _G_int8_t;
|
||||
#endif
|
||||
typedef unsigned char _G_uint8_t;
|
||||
typedef short _G_int16_t;
|
||||
typedef unsigned short _G_uint16_t;
|
||||
typedef int _G_int32_t;
|
||||
typedef unsigned long _G_uint32_t;
|
||||
#define HAVE_INT64
|
||||
typedef long long _G_int64_t;
|
||||
typedef unsigned _G_uint64_t;
|
||||
#define _G_BUFSIZ 1024
|
||||
#define _G_FOPEN_MAX 20
|
||||
#define _G_FILENAME_MAX 1024
|
||||
#define _G_NULL 0 /* default */
|
||||
#if defined (__cplusplus) || defined (__STDC__)
|
||||
#define _G_ARGS(ARGLIST) ARGLIST
|
||||
#else
|
||||
#define _G_ARGS(ARGLIST) ()
|
||||
#endif
|
||||
#if !defined (__GNUG__) || defined (__STRICT_ANSI__)
|
||||
#define _G_NO_NRV
|
||||
#endif
|
||||
#if !defined (__GNUG__)
|
||||
#define _G_NO_EXTERN_TEMPLATES
|
||||
#endif
|
||||
#define _G_HAVE_ATEXIT 1
|
||||
#define _G_HAVE_SYS_RESOURCE 1
|
||||
#define _G_HAVE_SYS_SOCKET 1
|
||||
#define _G_HAVE_SYS_WAIT 1
|
||||
#define _G_HAVE_UNISTD 1
|
||||
#define _G_HAVE_DIRENT 1
|
||||
#define _G_HAVE_CURSES 1
|
||||
#define _G_MATH_H_INLINES 0
|
||||
#define _G_HAVE_BOOL 1
|
||||
#endif /* !_G_config_h */
|
||||
|
|
@ -1,141 +0,0 @@
|
|||
/* ANSI and traditional C compatability macros
|
||||
Copyright 1991, 1992 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
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. */
|
||||
|
||||
/* ANSI and traditional C compatibility macros
|
||||
|
||||
ANSI C is assumed if __STDC__ is #defined.
|
||||
|
||||
Macro ANSI C definition Traditional C definition
|
||||
----- ---- - ---------- ----------- - ----------
|
||||
PTR `void *' `char *'
|
||||
LONG_DOUBLE `long double' `double'
|
||||
VOLATILE `volatile' `'
|
||||
SIGNED `signed' `'
|
||||
PTRCONST `void *const' `char *'
|
||||
ANSI_PROTOTYPES 1 not defined
|
||||
|
||||
CONST is also defined, but is obsolete. Just use const.
|
||||
|
||||
DEFUN (name, arglist, args)
|
||||
|
||||
Defines function NAME.
|
||||
|
||||
ARGLIST lists the arguments, separated by commas and enclosed in
|
||||
parentheses. ARGLIST becomes the argument list in traditional C.
|
||||
|
||||
ARGS list the arguments with their types. It becomes a prototype in
|
||||
ANSI C, and the type declarations in traditional C. Arguments should
|
||||
be separated with `AND'. For functions with a variable number of
|
||||
arguments, the last thing listed should be `DOTS'.
|
||||
|
||||
DEFUN_VOID (name)
|
||||
|
||||
Defines a function NAME, which takes no arguments.
|
||||
|
||||
obsolete -- EXFUN (name, (prototype)) -- obsolete.
|
||||
|
||||
Replaced by PARAMS. Do not use; will disappear someday soon.
|
||||
Was used in external function declarations.
|
||||
In ANSI C it is `NAME PROTOTYPE' (so PROTOTYPE should be enclosed in
|
||||
parentheses). In traditional C it is `NAME()'.
|
||||
For a function that takes no arguments, PROTOTYPE should be `(void)'.
|
||||
|
||||
PARAMS ((args))
|
||||
|
||||
We could use the EXFUN macro to handle prototype declarations, but
|
||||
the name is misleading and the result is ugly. So we just define a
|
||||
simple macro to handle the parameter lists, as in:
|
||||
|
||||
static int foo PARAMS ((int, char));
|
||||
|
||||
This produces: `static int foo();' or `static int foo (int, char);'
|
||||
|
||||
EXFUN would have done it like this:
|
||||
|
||||
static int EXFUN (foo, (int, char));
|
||||
|
||||
but the function is not external...and it's hard to visually parse
|
||||
the function name out of the mess. EXFUN should be considered
|
||||
obsolete; new code should be written to use PARAMS.
|
||||
|
||||
For example:
|
||||
extern int printf PARAMS ((CONST char *format DOTS));
|
||||
int DEFUN(fprintf, (stream, format),
|
||||
FILE *stream AND CONST char *format DOTS) { ... }
|
||||
void DEFUN_VOID(abort) { ... }
|
||||
*/
|
||||
|
||||
#ifndef _ANSIDECL_H
|
||||
|
||||
#define _ANSIDECL_H 1
|
||||
|
||||
|
||||
/* Every source file includes this file,
|
||||
so they will all get the switch for lint. */
|
||||
/* LINTLIBRARY */
|
||||
|
||||
|
||||
#if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4))
|
||||
/* All known AIX compilers implement these things (but don't always
|
||||
define __STDC__). The RISC/OS MIPS compiler defines these things
|
||||
in SVR4 mode, but does not define __STDC__. */
|
||||
|
||||
#define PTR void *
|
||||
#define PTRCONST void *CONST
|
||||
#define LONG_DOUBLE long double
|
||||
|
||||
#define AND ,
|
||||
#define NOARGS void
|
||||
#define CONST const
|
||||
#define VOLATILE volatile
|
||||
#define SIGNED signed
|
||||
#define DOTS , ...
|
||||
|
||||
#define EXFUN(name, proto) name proto
|
||||
#define DEFUN(name, arglist, args) name(args)
|
||||
#define DEFUN_VOID(name) name(void)
|
||||
|
||||
#define PROTO(type, name, arglist) type name arglist
|
||||
#define PARAMS(paramlist) paramlist
|
||||
#define ANSI_PROTOTYPES 1
|
||||
|
||||
#else /* Not ANSI C. */
|
||||
|
||||
#define PTR char *
|
||||
#define PTRCONST PTR
|
||||
#define LONG_DOUBLE double
|
||||
|
||||
#define AND ;
|
||||
#define NOARGS
|
||||
#define CONST
|
||||
#ifndef const /* some systems define it in header files for non-ansi mode */
|
||||
#define const
|
||||
#endif
|
||||
#define VOLATILE
|
||||
#define SIGNED
|
||||
#define DOTS
|
||||
|
||||
#define EXFUN(name, proto) name()
|
||||
#define DEFUN(name, arglist, args) name arglist args;
|
||||
#define DEFUN_VOID(name) name()
|
||||
#define PROTO(type, name, arglist) type name ()
|
||||
#define PARAMS(paramlist) ()
|
||||
|
||||
#endif /* ANSI C. */
|
||||
|
||||
#endif /* ansidecl.h */
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
#ifndef ONES
|
||||
#define ONES ((_BS_word)(~0L))
|
||||
#endif
|
||||
register int nwords;
|
||||
register _BS_word mask;
|
||||
if (offset == 0)
|
||||
;
|
||||
else if (offset + length >= _BS_BITS_PER_WORD)
|
||||
{
|
||||
mask = ONES _BS_RIGHT offset;
|
||||
DOIT(*ptr++, mask);
|
||||
length -= _BS_BITS_PER_WORD - offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
mask = (ONES _BS_RIGHT (_BS_BITS_PER_WORD - length))
|
||||
_BS_LEFT (_BS_BITS_PER_WORD - length - offset);
|
||||
DOIT(*ptr, mask);
|
||||
goto done;
|
||||
}
|
||||
nwords = _BS_INDEX(length);
|
||||
while (--nwords >= 0)
|
||||
{
|
||||
DOIT(*ptr++, ONES);
|
||||
}
|
||||
length = _BS_POS (length);
|
||||
if (length)
|
||||
{
|
||||
mask = ONES _BS_LEFT (_BS_BITS_PER_WORD - length);
|
||||
DOIT(*ptr, mask);
|
||||
}
|
||||
done: ;
|
||||
|
|
@ -1,184 +0,0 @@
|
|||
#ifndef ONES
|
||||
#define ONES ((_BS_word)(~0L))
|
||||
#endif
|
||||
|
||||
#ifndef DOIT_SOLID
|
||||
#ifdef DOIT
|
||||
#define DOIT_SOLID(dst, src) DOIT(dst, src, (_BS_word)(~0))
|
||||
#else
|
||||
#define DOIT_SOLID(dst, src) (dst) = (COMBINE(dst, src))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef DOIT
|
||||
#define DOIT(dst, src, mask) \
|
||||
(dst) = ((COMBINE(dst, src)) & (mask)) | ((dst) & ~(mask))
|
||||
#endif
|
||||
|
||||
_BS_word word0, mask;
|
||||
int shift0, shift1;
|
||||
|
||||
if (length == 0)
|
||||
goto done;
|
||||
|
||||
shift0 = srcbit - dstbit;
|
||||
|
||||
/* First handle the case that only one destination word is touched. */
|
||||
if (length + dstbit <= _BS_BITS_PER_WORD)
|
||||
{
|
||||
_BS_word mask
|
||||
= (ONES _BS_LEFT (_BS_BITS_PER_WORD - length)) _BS_RIGHT dstbit;
|
||||
_BS_word word0 = *psrc++;
|
||||
if (shift0 <= 0) /* dstbit >= srcbit */
|
||||
{
|
||||
word0 = word0 _BS_RIGHT (-shift0);
|
||||
}
|
||||
else
|
||||
{
|
||||
word0 = word0 _BS_LEFT shift0;
|
||||
if (length + srcbit > _BS_BITS_PER_WORD)
|
||||
word0 = word0 | (*psrc _BS_RIGHT (_BS_BITS_PER_WORD - shift0));
|
||||
}
|
||||
DOIT(*pdst, word0, mask);
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Next optimize the case that the source and destination are aligned. */
|
||||
if (shift0 == 0)
|
||||
{
|
||||
_BS_word mask;
|
||||
if (psrc > pdst)
|
||||
{
|
||||
if (srcbit)
|
||||
{
|
||||
mask = ONES _BS_RIGHT srcbit;
|
||||
DOIT(*pdst, *psrc, mask);
|
||||
pdst++; psrc++;
|
||||
length -= _BS_BITS_PER_WORD - srcbit;
|
||||
}
|
||||
for (; length >= _BS_BITS_PER_WORD; length -= _BS_BITS_PER_WORD)
|
||||
{
|
||||
DOIT_SOLID(*pdst, *psrc);
|
||||
pdst++; psrc++;
|
||||
}
|
||||
if (length)
|
||||
{
|
||||
mask = ONES _BS_LEFT (_BS_BITS_PER_WORD - length);
|
||||
DOIT(*pdst, *psrc, mask);
|
||||
}
|
||||
}
|
||||
else if (psrc < pdst)
|
||||
{
|
||||
_BS_size_t span = srcbit + length;
|
||||
pdst += span / (_BS_size_t)_BS_BITS_PER_WORD;
|
||||
psrc += span / (_BS_size_t)_BS_BITS_PER_WORD;
|
||||
span %= (_BS_size_t)_BS_BITS_PER_WORD;
|
||||
if (span)
|
||||
{
|
||||
mask = ONES _BS_LEFT (_BS_BITS_PER_WORD - span);
|
||||
DOIT(*pdst, *psrc, mask);
|
||||
length -= span;
|
||||
}
|
||||
pdst--; psrc--;
|
||||
for (; length >= _BS_BITS_PER_WORD; length -= _BS_BITS_PER_WORD)
|
||||
{
|
||||
DOIT_SOLID(*pdst, *psrc);
|
||||
pdst--; psrc--;
|
||||
}
|
||||
if (srcbit)
|
||||
{
|
||||
mask = ONES _BS_RIGHT srcbit;
|
||||
DOIT(*pdst, *psrc, mask);
|
||||
}
|
||||
}
|
||||
/* else if (psrc == pdst) --nothing to do--; */
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Now we assume shift!=0, and more than on destination word is changed. */
|
||||
if (psrc >= pdst) /* Do the updates in forward direction. */
|
||||
{
|
||||
_BS_word word0 = *psrc++;
|
||||
_BS_word mask = ONES _BS_RIGHT dstbit;
|
||||
if (shift0 > 0)
|
||||
{
|
||||
_BS_word word1 = *psrc++;
|
||||
shift1 = _BS_BITS_PER_WORD - shift0;
|
||||
DOIT(*pdst, (word0 _BS_LEFT shift0) | (word1 _BS_RIGHT shift1), mask);
|
||||
word0 = word1;
|
||||
}
|
||||
else /* dstbit > srcbit */
|
||||
{
|
||||
shift1 = -shift0;
|
||||
shift0 += _BS_BITS_PER_WORD;
|
||||
DOIT(*pdst, word0 _BS_RIGHT shift1, mask);
|
||||
}
|
||||
pdst++;
|
||||
length -= _BS_BITS_PER_WORD - dstbit;
|
||||
|
||||
for ( ; length >= _BS_BITS_PER_WORD; length -= _BS_BITS_PER_WORD)
|
||||
{
|
||||
register _BS_word word1 = *psrc++;
|
||||
DOIT_SOLID(*pdst,
|
||||
(word0 _BS_LEFT shift0) | (word1 _BS_RIGHT shift1));
|
||||
pdst++;
|
||||
word0 = word1;
|
||||
}
|
||||
if (length > 0)
|
||||
{
|
||||
_BS_size_t mask = ONES _BS_LEFT (_BS_BITS_PER_WORD - length);
|
||||
word0 = word0 _BS_LEFT shift0;
|
||||
if (length > shift1)
|
||||
word0 = word0 | (*psrc _BS_RIGHT shift1) ;
|
||||
DOIT (*pdst, word0, mask);
|
||||
}
|
||||
}
|
||||
else /* Do the updates in backward direction. */
|
||||
{
|
||||
_BS_word word0;
|
||||
|
||||
/* Make (psrc, srcbit) and (pdst, dstbit) point to *last* bit. */
|
||||
psrc += (srcbit + length - 1) / _BS_BITS_PER_WORD;
|
||||
srcbit = (srcbit + length - 1) % _BS_BITS_PER_WORD;
|
||||
pdst += (dstbit + length - 1) / _BS_BITS_PER_WORD;
|
||||
dstbit = (dstbit + length - 1) % _BS_BITS_PER_WORD;
|
||||
|
||||
shift0 = srcbit - dstbit;
|
||||
|
||||
word0 = *psrc--;
|
||||
mask = ONES _BS_LEFT (_BS_BITS_PER_WORD - 1 - dstbit);
|
||||
if (shift0 < 0)
|
||||
{
|
||||
_BS_word word1 = *psrc--;
|
||||
shift1 = -shift0;
|
||||
shift0 += _BS_BITS_PER_WORD;
|
||||
DOIT (*pdst, (word0 _BS_RIGHT shift1) | (word1 _BS_LEFT shift0),
|
||||
mask);
|
||||
word0 = word1;
|
||||
}
|
||||
else
|
||||
{
|
||||
shift1 = _BS_BITS_PER_WORD - shift0;
|
||||
DOIT(*pdst, word0 _BS_LEFT shift0, mask);
|
||||
}
|
||||
pdst--;
|
||||
length -= dstbit + 1;
|
||||
|
||||
for ( ; length >= _BS_BITS_PER_WORD; length -= _BS_BITS_PER_WORD)
|
||||
{
|
||||
register _BS_word word1 = *psrc--;
|
||||
DOIT_SOLID(*pdst,
|
||||
(word0 _BS_RIGHT shift1) | (word1 _BS_LEFT shift0));
|
||||
pdst--;
|
||||
word0 = word1;
|
||||
}
|
||||
if (length > 0)
|
||||
{
|
||||
_BS_size_t mask = ONES _BS_RIGHT (_BS_BITS_PER_WORD - length);
|
||||
word0 = word0 _BS_RIGHT shift1;
|
||||
if (length > shift0)
|
||||
word0 = word0 | (*psrc _BS_LEFT shift0) ;
|
||||
DOIT (*pdst, word0, mask);
|
||||
}
|
||||
}
|
||||
done: ;
|
||||
|
|
@ -1,125 +0,0 @@
|
|||
#ifndef _BS_PRIMS
|
||||
#define _BS_PRIMS
|
||||
|
||||
/* For now, use unsigned short for compatibility with old libg++ code.
|
||||
Later, change to unsigned long as the default. */
|
||||
typedef unsigned long _BS_word;
|
||||
|
||||
#define _BS_CHAR_BIT 8
|
||||
#define _BS_BITS_PER_WORD (_BS_CHAR_BIT*sizeof(_BS_word))
|
||||
#define _BS_WORDS_NEEDED(NBITS) ((NBITS+_BS_BITS_PER_WORD-1)/_BS_BITS_PER_WORD)
|
||||
|
||||
/* For now, we number the bits in a _BS_word in little-endian order.
|
||||
Later, might use machine order. */
|
||||
#ifdef CHILL_LIB
|
||||
#ifndef BITS_BIG_ENDIAN
|
||||
#include "config.h"
|
||||
#endif
|
||||
#define _BS_BIGENDIAN BITS_BIG_ENDIAN
|
||||
#else
|
||||
#define _BS_BIGENDIAN 0
|
||||
#endif
|
||||
|
||||
/* By "left" we mean where bit number 0 is.
|
||||
Hence, so left shift is << if we're numbering the bits in big-endian oder,
|
||||
and >> if we're numbering the bits in little-endian order.
|
||||
Currently, we always use little-endian order.
|
||||
Later, we might use machine-endian order. */
|
||||
#if _BS_BIGENDIAN
|
||||
#define _BS_LEFT <<
|
||||
#define _BS_RIGHT >>
|
||||
#else
|
||||
#define _BS_LEFT >>
|
||||
#define _BS_RIGHT <<
|
||||
#endif
|
||||
|
||||
#if _BS_BIGENDIAN
|
||||
#define _BS_BITMASK(BITNO) (1 << (_BS_BITS_PER_WORD - 1 - (BITNO)))
|
||||
#else
|
||||
#define _BS_BITMASK(BITNO) (1 << (BITNO))
|
||||
#endif
|
||||
|
||||
/* Given a PTR which may not be aligned on a _BS_word boundary,
|
||||
set NEW_PTR to point to (the beginning of) the corresponding _BS_word.
|
||||
Adjust the bit-offset OFFSET to compensate for the difference. */
|
||||
#define _BS_ADJUST_ALIGNED(NEW_PTR, PTR, OFFSET) \
|
||||
( (NEW_PTR) = (_BS_word*)(((char*)(PTR)-(char*)0) & ~(sizeof(_BS_word)-1)), \
|
||||
(OFFSET) += (char*)(PTR) - (char*)(NEW_PTR) )
|
||||
|
||||
/* Given a bit point (PTR, OFFSET) normalize it so that
|
||||
OFFSET < _BS_BITS_PER_WORD. */
|
||||
#define _BS_NORMALIZE(PTR, OFFSET) \
|
||||
{ _BS_size_t __tmp_ind = _BS_INDEX (OFFSET); \
|
||||
(PTR) += __tmp_ind; \
|
||||
(OFFSET) -= __tmp_ind * _BS_BITS_PER_WORD; }
|
||||
|
||||
#define _BS_INDEX(I) ((unsigned)(I) / _BS_BITS_PER_WORD)
|
||||
#define _BS_POS(I) ((I) & (_BS_BITS_PER_WORD -1 ))
|
||||
|
||||
#ifndef _BS_size_t
|
||||
#ifdef __GNUC__
|
||||
#define _BS_size_t __SIZE_TYPE__
|
||||
#else
|
||||
#define _BS_size_t unsigned long
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef __P
|
||||
#ifdef __STDC__
|
||||
#define __P(paramlist) paramlist
|
||||
#else
|
||||
#define __P(paramlist) ()
|
||||
#endif
|
||||
#endif /*!__P*/
|
||||
#if !defined(__STDC__) && !defined(const)
|
||||
#define const
|
||||
#endif
|
||||
#if !defined(__STDC__) && !defined(void)
|
||||
#define void int
|
||||
#endif
|
||||
|
||||
/* The 16 2-operand raster-ops:
|
||||
These match the correspodning GX codes in X11. */
|
||||
enum _BS_alu {
|
||||
_BS_alu_clear = 0 /* 0 */,
|
||||
_BS_alu_and = 1 /* src & dst */,
|
||||
_BS_alu_andReverse = 2 /* src & ~dst */,
|
||||
_BS_alu_copy = 3 /* src */,
|
||||
_BS_alu_andInverted = 4 /* ~src & dst */,
|
||||
_BS_alu_noop = 5 /* dst */,
|
||||
_BS_alu_xor = 6 /* src ^ dst */,
|
||||
_BS_alu_or = 7 /* src | dst */,
|
||||
_BS_alu_nor = 8 /* ~src & ~dst */,
|
||||
_BS_alu_equiv = 9 /* ~(src ^ dst) */,
|
||||
_BS_alu_invert = 10 /* ~dst */,
|
||||
_BS_alu_orReverse = 11 /* src | ~dst */,
|
||||
_BS_alu_copyInverted = 12 /* ~src */,
|
||||
_BS_alu_orInverted = 13 /* ~src | dst */,
|
||||
_BS_alu_nand = 14 /* ~src | d~st */,
|
||||
_BS_alu_set = 15 /* ~src | dst */
|
||||
};
|
||||
#define _BS
|
||||
#define _BS
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void _BS_and __P((_BS_word*,int, const _BS_word*, int, _BS_size_t));
|
||||
extern void _BS_blt __P((enum _BS_alu,
|
||||
_BS_word*,int, const _BS_word*,int, _BS_size_t));
|
||||
extern void _BS_copy __P((_BS_word*,int, const _BS_word*,int, _BS_size_t));
|
||||
#define _BS_copy_0(DS, SS, LENGTH) _BS_copy(DS, 0, SS, 0, LENGTH)
|
||||
extern int _BS_count __P((const _BS_word*, int, _BS_size_t));
|
||||
extern int _BS_any __P((const _BS_word*, int, _BS_size_t));
|
||||
extern void _BS_clear __P((_BS_word*, int, _BS_size_t));
|
||||
extern void _BS_set __P((_BS_word*, int, _BS_size_t));
|
||||
extern void _BS_invert __P((_BS_word*, int, _BS_size_t));
|
||||
int _BS_lcompare_0 __P((_BS_word*, _BS_size_t, _BS_word*, _BS_size_t));
|
||||
extern void _BS_xor __P((_BS_word*,int, const _BS_word*,int, _BS_size_t));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !_BS_PRIMS */
|
||||
|
|
@ -1,144 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
|
||||
/*
|
||||
Copyright (C) 1988, 1992 Free Software Foundation
|
||||
written by Doug Lea (dl@rocky.oswego.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
arithmetic, etc. functions on built in types
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _builtin_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define _builtin_h 1
|
||||
|
||||
#include <stddef.h>
|
||||
#include <std.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef __GNUG__
|
||||
#define _VOLATILE_VOID volatile void
|
||||
#else
|
||||
#define _VOLATILE_VOID void
|
||||
#endif
|
||||
|
||||
typedef void (*one_arg_error_handler_t)(const char*);
|
||||
typedef void (*two_arg_error_handler_t)(const char*, const char*);
|
||||
|
||||
long gcd(long, long);
|
||||
long lg(unsigned long);
|
||||
double pow(double, long);
|
||||
long pow(long, long);
|
||||
|
||||
extern "C" double start_timer();
|
||||
extern "C" double return_elapsed_time(double last_time = 0.0);
|
||||
|
||||
char* dtoa(double x, char cvt = 'g', int width = 0, int prec = 6);
|
||||
|
||||
unsigned int hashpjw(const char*);
|
||||
unsigned int multiplicativehash(int);
|
||||
unsigned int foldhash(double);
|
||||
|
||||
extern _VOLATILE_VOID default_one_arg_error_handler(const char*);
|
||||
extern _VOLATILE_VOID default_two_arg_error_handler(const char*, const char*);
|
||||
|
||||
extern two_arg_error_handler_t lib_error_handler;
|
||||
|
||||
extern two_arg_error_handler_t
|
||||
set_lib_error_handler(two_arg_error_handler_t f);
|
||||
|
||||
|
||||
#if !defined(IV)
|
||||
|
||||
#if ! _G_MATH_H_INLINES /* hpux and SCO define this in math.h */
|
||||
inline double abs(double arg)
|
||||
{
|
||||
return (arg < 0.0)? -arg : arg;
|
||||
}
|
||||
#endif
|
||||
|
||||
inline float abs(float arg)
|
||||
{
|
||||
return (arg < 0.0)? -arg : arg;
|
||||
}
|
||||
|
||||
inline short abs(short arg)
|
||||
{
|
||||
return (arg < 0)? -arg : arg;
|
||||
}
|
||||
|
||||
inline long abs(long arg)
|
||||
{
|
||||
return (arg < 0)? -arg : arg;
|
||||
}
|
||||
|
||||
inline int sign(long arg)
|
||||
{
|
||||
return (arg == 0) ? 0 : ( (arg > 0) ? 1 : -1 );
|
||||
}
|
||||
|
||||
inline int sign(double arg)
|
||||
{
|
||||
return (arg == 0.0) ? 0 : ( (arg > 0.0) ? 1 : -1 );
|
||||
}
|
||||
|
||||
inline long sqr(long arg)
|
||||
{
|
||||
return arg * arg;
|
||||
}
|
||||
|
||||
#if ! _G_MATH_H_INLINES /* hpux and SCO define this in math.h */
|
||||
inline double sqr(double arg)
|
||||
{
|
||||
return arg * arg;
|
||||
}
|
||||
#endif
|
||||
|
||||
inline int even(long arg)
|
||||
{
|
||||
return !(arg & 1);
|
||||
}
|
||||
|
||||
inline int odd(long arg)
|
||||
{
|
||||
return (arg & 1);
|
||||
}
|
||||
|
||||
inline long lcm(long x, long y)
|
||||
{
|
||||
return x / gcd(x, y) * y;
|
||||
}
|
||||
|
||||
inline void (setbit)(long& x, long b)
|
||||
{
|
||||
x |= (1 << b);
|
||||
}
|
||||
|
||||
inline void clearbit(long& x, long b)
|
||||
{
|
||||
x &= ~(1 << b);
|
||||
}
|
||||
|
||||
inline int testbit(long x, long b)
|
||||
{
|
||||
return ((x & (1 << b)) != 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 1993 Free Software Foundation
|
||||
|
||||
This file is part of the GNU IO Library. This library 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, or (at your option)
|
||||
any later version.
|
||||
|
||||
This library 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 GNU CC; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
As a special exception, if you link this library with files
|
||||
compiled with a GNU compiler to produce an executable, this does not cause
|
||||
the resulting executable to be covered by the GNU General Public License.
|
||||
This exception does not however invalidate any other reasons why
|
||||
the executable file might be covered by the GNU General Public License. */
|
||||
|
||||
#ifndef _BUILTINBUF_H
|
||||
#define _BUILTINBUF_H
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include <streambuf.h>
|
||||
|
||||
// A builtinbuf a a streambuf where all the virtual operations
|
||||
// call the _IO_jump_t table.
|
||||
|
||||
class builtinbuf : public streambuf {
|
||||
friend ios;
|
||||
virtual int overflow(int);
|
||||
virtual int underflow();
|
||||
virtual streamsize xsgetn(char *, streamsize);
|
||||
virtual streamsize xsputn(const char *, streamsize);
|
||||
virtual streambuf* setbuf(char*, int);
|
||||
virtual int doallocate();
|
||||
virtual ~builtinbuf();
|
||||
virtual int sync();
|
||||
|
||||
virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
|
||||
virtual streampos seekpos(streampos pos, int mode = ios::in|ios::out);
|
||||
virtual int pbackfail(int c);
|
||||
virtual streamsize sys_read(char* buf, streamsize size);
|
||||
virtual streampos sys_seek(streamoff, _seek_dir);
|
||||
virtual streamsize sys_write(const char*, streamsize);
|
||||
virtual int sys_stat(void*); // Actually, a (struct stat*)
|
||||
virtual int sys_close();
|
||||
#if 0
|
||||
virtual int get_column();
|
||||
virtual int set_column(int);
|
||||
#endif
|
||||
private:
|
||||
builtinbuf() { }
|
||||
};
|
||||
#endif /* _BUILTINBUF_H */
|
||||
|
|
@ -1,91 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Doug Lea (dl@rocky.oswego.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef _compare_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define _compare_h 1
|
||||
|
||||
#include <builtin.h>
|
||||
|
||||
int compare(int a, int b);
|
||||
int compare(short a, short b);
|
||||
int compare(unsigned long a, unsigned long b);
|
||||
int compare(unsigned int a, unsigned int b);
|
||||
int compare(unsigned short a, unsigned short b);
|
||||
int compare(unsigned char a, unsigned char b);
|
||||
int compare(signed char a, signed char b);
|
||||
int compare(float a, float b);
|
||||
int compare(double a, double b);
|
||||
int compare(const char* a, const char* b);
|
||||
|
||||
|
||||
inline int compare(int a, int b)
|
||||
{
|
||||
return a - b;
|
||||
}
|
||||
|
||||
inline int compare(short a, short b)
|
||||
{
|
||||
return a - b;
|
||||
}
|
||||
|
||||
|
||||
inline int compare(signed char a, signed char b)
|
||||
{
|
||||
return a - b;
|
||||
}
|
||||
|
||||
inline int compare(unsigned long a, unsigned long b)
|
||||
{
|
||||
return (a < b)? -1 : (a > b)? 1 : 0;
|
||||
}
|
||||
|
||||
inline int compare(unsigned int a, unsigned int b)
|
||||
{
|
||||
return (a < b)? -1 : (a > b)? 1 : 0;
|
||||
}
|
||||
|
||||
inline int compare(unsigned short a, unsigned short b)
|
||||
{
|
||||
return (a < b)? -1 : (a > b)? 1 : 0;
|
||||
}
|
||||
|
||||
inline int compare(unsigned char a, unsigned char b)
|
||||
{
|
||||
return (a < b)? -1 : (a > b)? 1 : 0;
|
||||
}
|
||||
|
||||
inline int compare(float a, float b)
|
||||
{
|
||||
return (a < b)? -1 : (a > b)? 1 : 0;
|
||||
}
|
||||
|
||||
inline int compare(double a, double b)
|
||||
{
|
||||
return (a < b)? -1 : (a > b)? 1 : 0;
|
||||
}
|
||||
|
||||
inline int compare(const char* a, const char* b)
|
||||
{
|
||||
return strcmp(a,b);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
#ifndef _complex_h
|
||||
#define _complex_h
|
||||
#define __ATT_complex__
|
||||
#include <Complex.h>
|
||||
typedef class Complex complex;
|
||||
#endif
|
||||
|
|
@ -1 +0,0 @@
|
|||
/* !Automatically generated from ./functions.def - DO NOT EDIT! */
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1994 Free Software Foundation
|
||||
written by Jason Merrill (jason@cygnus.com)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef _defines_h
|
||||
#define _defines_h
|
||||
|
||||
#include <_G_config.h>
|
||||
#include <stddef.h>
|
||||
|
||||
const size_t NPOS = (size_t)(-1);
|
||||
typedef void fvoid_t();
|
||||
|
||||
#ifndef _WINT_T
|
||||
#define _WINT_T
|
||||
typedef _G_wint_t wint_t;
|
||||
#endif
|
||||
|
||||
enum capacity { default_size, reserve };
|
||||
|
||||
#endif
|
||||
|
|
@ -1,183 +0,0 @@
|
|||
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
|
||||
Copyright (C) 1993 Free Software Foundation
|
||||
|
||||
This file is part of the GNU IO Library. This library 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, or (at your option)
|
||||
any later version.
|
||||
|
||||
This library 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 GNU CC; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
As a special exception, if you link this library with files
|
||||
compiled with a GNU compiler to produce an executable, this does not cause
|
||||
the resulting executable to be covered by the GNU General Public License.
|
||||
This exception does not however invalidate any other reasons why
|
||||
the executable file might be covered by the GNU General Public License.
|
||||
|
||||
Written by Per Bothner (bothner@cygnus.com). */
|
||||
|
||||
#ifndef _EDITBUF_H
|
||||
#define _EDITBUF_H
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <fstream.h>
|
||||
|
||||
typedef unsigned long mark_pointer;
|
||||
// At some point, it might be nice to parameterize this code
|
||||
// in terms of buf_char.
|
||||
typedef /*unsigned*/ char buf_char;
|
||||
|
||||
// Logical pos from start of buffer (does not count gap).
|
||||
typedef long buf_index;
|
||||
|
||||
// Pos from start of buffer, possibly including gap_size.
|
||||
typedef long buf_offset;
|
||||
|
||||
#if 0
|
||||
struct buf_cookie {
|
||||
FILE *file;
|
||||
struct edit_string *str;
|
||||
struct buf_cookie *next;
|
||||
buf_index tell();
|
||||
};
|
||||
#endif
|
||||
|
||||
struct edit_buffer;
|
||||
struct edit_mark;
|
||||
|
||||
// A edit_string is defined as the region between the 'start' and 'end' marks.
|
||||
// Normally (always?) 'start->insert_before()' should be false,
|
||||
// and 'end->insert_before()' should be true.
|
||||
|
||||
struct edit_string {
|
||||
struct edit_buffer *buffer; // buffer that 'start' and 'end' belong to
|
||||
struct edit_mark *start, *end;
|
||||
int length() const; // count of buf_chars currently in string
|
||||
edit_string(struct edit_buffer *b,
|
||||
struct edit_mark *ms, struct edit_mark *me)
|
||||
{ buffer = b; start = ms; end = me; }
|
||||
/* Make a fresh, contiguous copy of the data in STR.
|
||||
Assign length of STR to *LENP.
|
||||
(Output has extra NUL at out[*LENP].) */
|
||||
buf_char *copy_bytes(int *lenp) const;
|
||||
// FILE *open_file(char *mode);
|
||||
void assign(struct edit_string *src); // copy bytes from src to this
|
||||
};
|
||||
|
||||
struct edit_streambuf : public streambuf {
|
||||
friend edit_buffer;
|
||||
edit_string *str;
|
||||
edit_streambuf* next; // Chain of edit_streambuf's for a edit_buffer.
|
||||
short _mode;
|
||||
edit_streambuf(edit_string* bstr, int mode);
|
||||
~edit_streambuf();
|
||||
virtual int underflow();
|
||||
virtual int overflow(int c = EOF);
|
||||
virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
|
||||
void flush_to_buffer();
|
||||
void flush_to_buffer(edit_buffer* buffer);
|
||||
int _inserting;
|
||||
int inserting() { return _inserting; }
|
||||
void inserting(int i) { _inserting = i; }
|
||||
// int delete_chars(int count, char* cut_buf); Not implemented.
|
||||
int truncate();
|
||||
int is_reading() { return gptr() != NULL; }
|
||||
buf_char* current() { return is_reading() ? gptr() : pptr(); }
|
||||
void set_current(char *p, int is_reading);
|
||||
protected:
|
||||
void disconnect_gap_from_file(edit_buffer* buffer);
|
||||
};
|
||||
|
||||
// A 'edit_mark' indicates a position in a buffer.
|
||||
// It is "attached" the text (rather than the offset).
|
||||
// There are two kinds of mark, which have different behavior
|
||||
// when text is inserted at the mark:
|
||||
// If 'insert_before()' is true the mark will be adjusted to be
|
||||
// *after* the new text.
|
||||
|
||||
struct edit_mark {
|
||||
struct edit_mark *chain;
|
||||
mark_pointer _pos;
|
||||
inline int insert_before() { return _pos & 1; }
|
||||
inline unsigned long index_in_buffer(struct edit_buffer *buffer)
|
||||
{ return _pos >> 1; }
|
||||
inline buf_char *ptr(struct edit_buffer *buf);
|
||||
buf_index tell();
|
||||
edit_mark() { }
|
||||
edit_mark(struct edit_string *str, long delta);
|
||||
edit_buffer *buffer();
|
||||
~edit_mark();
|
||||
};
|
||||
|
||||
// A 'edit_buffer' consists of a sequence of buf_chars (the data),
|
||||
// a list of edit_marks pointing into the data, and a list of FILEs
|
||||
// also pointing into the data.
|
||||
// A 'edit_buffer' coerced to a edit_string is the string of
|
||||
// all the buf_chars in the buffer.
|
||||
|
||||
// This implementation uses a conventional buffer gap (as in Emacs).
|
||||
// The gap start is defined by de-referencing a (buf_char**).
|
||||
// This is because sometimes a FILE is inserting into the buffer,
|
||||
// so rather than having each putc adjust the gap, we use indirection
|
||||
// to have the gap be defined as the write pointer of the FILE.
|
||||
// (This assumes that putc adjusts a pointer (as in GNU's libc), not an index.)
|
||||
|
||||
struct edit_buffer {
|
||||
buf_char *data; /* == emacs buffer_text.p1+1 */
|
||||
buf_char *_gap_start;
|
||||
edit_streambuf* _writer; // If non-NULL, currently writing stream
|
||||
inline buf_char *gap_start()
|
||||
{ return _writer ? _writer->pptr() : _gap_start; }
|
||||
buf_offset __gap_end_pos; // size of part 1 + size of gap
|
||||
/* int gap; implicit: buf_size - size1 - size2 */
|
||||
int buf_size;
|
||||
struct edit_streambuf *files;
|
||||
struct edit_mark start_mark;
|
||||
struct edit_mark end_mark;
|
||||
edit_buffer();
|
||||
inline buf_offset gap_end_pos() { return __gap_end_pos; }
|
||||
inline struct edit_mark *start_marker() { return &start_mark; }
|
||||
inline struct edit_mark *end_marker() { return &end_mark; }
|
||||
/* these should be protected, ultimately */
|
||||
buf_index tell(edit_mark*);
|
||||
buf_index tell(buf_char*);
|
||||
inline buf_char *gap_end() { return data + gap_end_pos(); }
|
||||
inline int gap_size() { return gap_end() - gap_start(); }
|
||||
inline int size1() { return gap_start() - data; }
|
||||
inline int size2() { return buf_size - gap_end_pos(); }
|
||||
inline struct edit_mark * mark_list() { return &start_mark; }
|
||||
void make_gap (buf_offset);
|
||||
void move_gap (buf_offset pos);
|
||||
void move_gap (buf_char *pos) { move_gap(pos - data); }
|
||||
void gap_left (int pos);
|
||||
void gap_right (int pos);
|
||||
void adjust_markers(mark_pointer low, mark_pointer high,
|
||||
int amount, buf_char *old_data);
|
||||
void delete_range(buf_index from, buf_index to);
|
||||
void delete_range(struct edit_mark *start, struct edit_mark *end);
|
||||
};
|
||||
|
||||
extern buf_char * bstr_copy(struct edit_string *str, int *lenp);
|
||||
|
||||
// Convert a edit_mark to a (buf_char*)
|
||||
|
||||
inline buf_char *edit_mark::ptr(struct edit_buffer *buf)
|
||||
{ return buf->data + index_in_buffer(buf); }
|
||||
|
||||
inline void edit_streambuf::flush_to_buffer()
|
||||
{
|
||||
edit_buffer* buffer = str->buffer;
|
||||
if (buffer->_writer == this) flush_to_buffer(buffer);
|
||||
}
|
||||
#endif /* !_EDITBUF_H*/
|
||||
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 1993 Free Software Foundation
|
||||
|
||||
This file is part of the GNU IO Library. This library 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, or (at your option)
|
||||
any later version.
|
||||
|
||||
This library 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 GNU CC; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
As a special exception, if you link this library with files
|
||||
compiled with a GNU compiler to produce an executable, this does not cause
|
||||
the resulting executable to be covered by the GNU General Public License.
|
||||
This exception does not however invalidate any other reasons why
|
||||
the executable file might be covered by the GNU General Public License. */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1990 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by the University of California, Berkeley. The name of the
|
||||
* University may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* %W% (Berkeley) %G%
|
||||
*/
|
||||
|
||||
/*
|
||||
* Floating point scanf/printf (input/output) definitions.
|
||||
*/
|
||||
|
||||
/* 11-bit exponent (VAX G floating point) is 308 decimal digits */
|
||||
#define MAXEXP 308
|
||||
/* 128 bit fraction takes up 39 decimal digits; max reasonable precision */
|
||||
#define MAXFRACT 39
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
|
||||
Copyright (C) 1993 Free Software Foundation
|
||||
|
||||
This file is part of the GNU IO Library. This library 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, or (at your option)
|
||||
any later version.
|
||||
|
||||
This library 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 GNU CC; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
As a special exception, if you link this library with files
|
||||
compiled with a GNU compiler to produce an executable, this does not cause
|
||||
the resulting executable to be covered by the GNU General Public License.
|
||||
This exception does not however invalidate any other reasons why
|
||||
the executable file might be covered by the GNU General Public License. */
|
||||
|
||||
#ifndef _FSTREAM_H
|
||||
#define _FSTREAM_H
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#include <iostream.h>
|
||||
|
||||
class fstreambase : virtual public ios {
|
||||
public:
|
||||
fstreambase();
|
||||
fstreambase(int fd);
|
||||
fstreambase(int fd, char *p, int l); /* Deprecated */
|
||||
fstreambase(const char *name, int mode, int prot=0664);
|
||||
void close();
|
||||
filebuf* rdbuf() const { return (filebuf*) ios::rdbuf(); }
|
||||
void open(const char *name, int mode, int prot=0664);
|
||||
int is_open() const { return rdbuf()->is_open(); }
|
||||
void setbuf(char *ptr, int len) { rdbuf()->setbuf(ptr, len); }
|
||||
#ifdef _STREAM_COMPAT
|
||||
int filedesc() { return rdbuf()->fd(); }
|
||||
fstreambase& raw() { rdbuf()->setbuf(NULL, 0); return *this; }
|
||||
#endif
|
||||
};
|
||||
|
||||
class ifstream : public fstreambase, public istream {
|
||||
public:
|
||||
ifstream() : fstreambase() { }
|
||||
ifstream(int fd) : fstreambase(fd) { }
|
||||
ifstream(int fd, char *p, int l) : fstreambase(fd, p, l) { } /*Deprecated*/
|
||||
ifstream(const char *name, int mode=ios::in, int prot=0664)
|
||||
: fstreambase(name, mode, prot) { }
|
||||
void open(const char *name, int mode=ios::in, int prot=0664)
|
||||
{ fstreambase::open(name, mode, prot); }
|
||||
};
|
||||
|
||||
class ofstream : public fstreambase, public ostream {
|
||||
public:
|
||||
ofstream() : fstreambase() { }
|
||||
ofstream(int fd) : fstreambase(fd) { }
|
||||
ofstream(int fd, char *p, int l) : fstreambase(fd, p, l) { } /*Deprecated*/
|
||||
ofstream(const char *name, int mode=ios::out, int prot=0664)
|
||||
: fstreambase(name, mode, prot) { }
|
||||
void open(const char *name, int mode=ios::out, int prot=0664)
|
||||
{ fstreambase::open(name, mode, prot); }
|
||||
};
|
||||
|
||||
class fstream : public fstreambase, public iostream {
|
||||
public:
|
||||
fstream() : fstreambase() { }
|
||||
fstream(int fd) : fstreambase(fd) { }
|
||||
fstream(const char *name, int mode, int prot=0664)
|
||||
: fstreambase(name, mode, prot) { }
|
||||
fstream(int fd, char *p, int l) : fstreambase(fd, p, l) { } /*Deprecated*/
|
||||
void open(const char *name, int mode, int prot=0664)
|
||||
{ fstreambase::open(name, mode, prot); }
|
||||
};
|
||||
#endif /*!_FSTREAM_H*/
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
|
||||
Copyright (C) 1993 Free Software Foundation
|
||||
|
||||
This file is part of the GNU IO Library. This library 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, or (at your option)
|
||||
any later version.
|
||||
|
||||
This library 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 GNU CC; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
As a special exception, if you link this library with files
|
||||
compiled with a GNU compiler to produce an executable, this does not cause
|
||||
the resulting executable to be covered by the GNU General Public License.
|
||||
This exception does not however invalidate any other reasons why
|
||||
the executable file might be covered by the GNU General Public License.
|
||||
|
||||
Written by Per Bothner (bothner@cygnus.com). */
|
||||
|
||||
#ifndef _INDSTREAM_H
|
||||
#define _INDSTREAM_H
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include <iostream.h>
|
||||
|
||||
// An indirectbuf is one that forwards all of its I/O requests
|
||||
// to another streambuf.
|
||||
// All get-related requests are sent to get_stream().
|
||||
// All put-related requests are sent to put_stream().
|
||||
|
||||
// An indirectbuf can be used to implement Common Lisp
|
||||
// synonym-streams and two-way-streams.
|
||||
//
|
||||
// class synonymbuf : public indirectbuf {
|
||||
// Symbol *sym;
|
||||
// synonymbuf(Symbol *s) { sym = s; }
|
||||
// virtual streambuf *lookup_stream(int mode) {
|
||||
// return coerce_to_streambuf(lookup_value(sym)); }
|
||||
// };
|
||||
|
||||
class indirectbuf : public streambuf {
|
||||
protected:
|
||||
streambuf *_get_stream; // Optional cache for get_stream().
|
||||
streambuf *_put_stream; // Optional cache for put_stream().
|
||||
int _delete_flags;
|
||||
public:
|
||||
streambuf *get_stream()
|
||||
{ return _get_stream ? _get_stream : lookup_stream(ios::in); }
|
||||
streambuf *put_stream()
|
||||
{ return _put_stream ? _put_stream : lookup_stream(ios::out); }
|
||||
virtual streambuf *lookup_stream(int/*mode*/) { return NULL; } // ERROR!
|
||||
indirectbuf(streambuf *get=NULL, streambuf *put=NULL, int delete_mode=0);
|
||||
virtual ~indirectbuf();
|
||||
virtual int xsputn(const char* s, int n);
|
||||
virtual int xsgetn(char* s, int n);
|
||||
virtual int underflow();
|
||||
virtual int overflow(int c = EOF);
|
||||
virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
|
||||
virtual streampos seekpos(streampos pos, int mode = ios::in|ios::out);
|
||||
virtual int sync();
|
||||
virtual int pbackfail(int c);
|
||||
};
|
||||
|
||||
#endif /* !_INDSTREAM_H */
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
#include "libio.h"
|
||||
|
||||
/* These emulate stdio functionality, but with a different name
|
||||
(_IO_ungetc instead of ungetc), and using _IO_FILE instead of FILE. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int _IO_fclose __P((_IO_FILE*));
|
||||
extern _IO_FILE *_IO_fdopen __P((int, const char*));
|
||||
extern int _IO_fflush __P((_IO_FILE*));
|
||||
extern int _IO_fgetpos __P((_IO_FILE*, _IO_fpos_t*));
|
||||
extern char* _IO_fgets __P((char*, int, _IO_FILE*));
|
||||
extern _IO_FILE *_IO_fopen __P((const char*, const char*));
|
||||
extern int _IO_fprintf __P((_IO_FILE*, const char*, ...));
|
||||
extern int _IO_fputs __P((const char*, _IO_FILE*));
|
||||
extern int _IO_fsetpos __P((_IO_FILE*, const _IO_fpos_t *));
|
||||
extern long int _IO_ftell __P((_IO_FILE*));
|
||||
extern _IO_size_t _IO_fwrite __P((const void*,
|
||||
_IO_size_t, _IO_size_t, _IO_FILE*));
|
||||
extern char* _IO_gets __P((char*));
|
||||
extern void _IO_perror __P((const char*));
|
||||
extern int _IO_printf __P((const char*, ...));
|
||||
extern int _IO_puts __P((const char*));
|
||||
extern int _IO_scanf __P((const char*, ...));
|
||||
extern void _IO_setbuffer __P((_IO_FILE *, char*, _IO_size_t));
|
||||
extern int _IO_setvbuf __P((_IO_FILE*, char*, int, _IO_size_t));
|
||||
extern int _IO_sscanf __P((const char*, const char*, ...));
|
||||
extern int _IO_sprintf __P((char *, const char*, ...));
|
||||
extern int _IO_ungetc __P((int, _IO_FILE*));
|
||||
extern int _IO_vsscanf __P((const char *, const char *, _IO_va_list));
|
||||
extern int _IO_vsprintf __P((char*, const char*, _IO_va_list));
|
||||
#ifndef _IO_pos_BAD
|
||||
#define _IO_pos_BAD ((_IO_fpos_t)(-1))
|
||||
#endif
|
||||
#define _IO_clearerr(FP) ((FP)->_flags &= ~(_IO_ERR_SEEN|_IO_EOF_SEEN))
|
||||
#define _IO_fseek(__fp, __offset, __whence) \
|
||||
(_IO_seekoff(__fp, __offset, (_IO_off_t)(__whence)) == _IO_pos_BAD ? EOF : 0)
|
||||
#define _IO_rewind(FILE) (void)_IO_seekoff(FILE, 0, 0)
|
||||
#define _IO_vprintf(FORMAT, ARGS) _IO_vfprintf(_IO_stdout, FORMAT, ARGS)
|
||||
#define _IO_freopen(FILENAME, MODE, FP) \
|
||||
(_IO_file_close_it(FP), _IO_file_fopen(FP, FILENAME, MODE))
|
||||
#define _IO_fileno(FP) ((FP)->_fileno)
|
||||
extern _IO_FILE* _IO_popen __P((const char*, const char*));
|
||||
#define _IO_pclose _IO_fclose
|
||||
#define _IO_setbuf(_FP, _BUF) _IO_setbuffer(_FP, _BUF, _IO_BUFSIZ)
|
||||
#define _IO_setlinebuf(_FP) _IO_setvbuf(_FP, NULL, 1, 0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,159 +0,0 @@
|
|||
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
|
||||
Copyright (C) 1993 Free Software Foundation
|
||||
|
||||
This file is part of the GNU IO Library. This library 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, or (at your option)
|
||||
any later version.
|
||||
|
||||
This library 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 GNU CC; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
As a special exception, if you link this library with files
|
||||
compiled with a GNU compiler to produce an executable, this does not cause
|
||||
the resulting executable to be covered by the GNU General Public License.
|
||||
This exception does not however invalidate any other reasons why
|
||||
the executable file might be covered by the GNU General Public License. */
|
||||
|
||||
#ifndef _IOMANIP_H
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define _IOMANIP_H
|
||||
|
||||
#include <iostream.h>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Parametrized Manipulators as specified by ANSI draft
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Stream Manipulators
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
template<class TP> class smanip; // TP = Type Param
|
||||
|
||||
template<class TP> class sapp {
|
||||
ios& (*_f)(ios&, TP);
|
||||
public:
|
||||
sapp(ios& (*f)(ios&, TP)) : _f(f) {}
|
||||
//
|
||||
smanip<TP> operator()(TP a)
|
||||
{ return smanip<TP>(_f, a); }
|
||||
};
|
||||
|
||||
template <class TP> class smanip {
|
||||
ios& (*_f)(ios&, TP);
|
||||
TP _a;
|
||||
public:
|
||||
smanip(ios& (*f)(ios&, TP), TP a) : _f(f), _a(a) {}
|
||||
//
|
||||
friend
|
||||
istream& operator>>(istream& i, const smanip<TP>& m);
|
||||
friend
|
||||
ostream& operator<<(ostream& o, const smanip<TP>& m);
|
||||
};
|
||||
|
||||
#ifdef __GNUG__
|
||||
extern template class smanip<int>;
|
||||
extern template class smanip<ios::fmtflags>;
|
||||
#endif
|
||||
|
||||
template<class TP>
|
||||
inline istream& operator>>(istream& i, const smanip<TP>& m)
|
||||
{ (*m._f)(i, m._a); return i; }
|
||||
|
||||
template<class TP>
|
||||
inline ostream& operator<<(ostream& o, const smanip<TP>& m)
|
||||
{ (*m._f)(o, m._a); return o;}
|
||||
|
||||
#ifdef __GNUG__
|
||||
extern template istream& operator>>(istream&, const smanip<int>&);
|
||||
extern template istream& operator>>(istream&, const smanip<ios::fmtflags>&);
|
||||
extern template ostream& operator<<(ostream&, const smanip<int>&);
|
||||
extern template ostream& operator<<(ostream&, const smanip<ios::fmtflags>&);
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Input-Stream Manipulators
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
template<class TP> class imanip;
|
||||
|
||||
template<class TP> class iapp {
|
||||
istream& (*_f)(istream&, TP);
|
||||
public:
|
||||
iapp(istream& (*f)(istream&,TP)) : _f(f) {}
|
||||
//
|
||||
imanip<TP> operator()(TP a)
|
||||
{ return imanip<TP>(_f, a); }
|
||||
};
|
||||
|
||||
template <class TP> class imanip {
|
||||
istream& (*_f)(istream&, TP);
|
||||
TP _a;
|
||||
public:
|
||||
imanip(istream& (*f)(istream&, TP), TP a) : _f(f), _a(a) {}
|
||||
//
|
||||
friend
|
||||
istream& operator>>(istream& i, const imanip<TP>& m)
|
||||
{ return (*m._f)( i, m._a); }
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Output-Stream Manipulators
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
template<class TP> class omanip;
|
||||
|
||||
template<class TP> class oapp {
|
||||
ostream& (*_f)(ostream&, TP);
|
||||
public:
|
||||
oapp(ostream& (*f)(ostream&,TP)) : _f(f) {}
|
||||
//
|
||||
omanip<TP> operator()(TP a)
|
||||
{ return omanip<TP>(_f, a); }
|
||||
};
|
||||
|
||||
template <class TP> class omanip {
|
||||
ostream& (*_f)(ostream&, TP);
|
||||
TP _a;
|
||||
public:
|
||||
omanip(ostream& (*f)(ostream&, TP), TP a) : _f(f), _a(a) {}
|
||||
//
|
||||
friend
|
||||
ostream& operator<<(ostream& o, const omanip<TP>& m)
|
||||
{ return (*m._f)(o, m._a); }
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Available Manipulators
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//
|
||||
// Macro to define an iomanip function, with one argument
|
||||
// The underlying function is `__iomanip_<name>'
|
||||
//
|
||||
#define __DEFINE_IOMANIP_FN1(type,param,function) \
|
||||
extern ios& __iomanip_##function (ios&, param); \
|
||||
inline type<param> function (param n) \
|
||||
{ return type<param> (__iomanip_##function, n); }
|
||||
|
||||
__DEFINE_IOMANIP_FN1( smanip, int, setbase)
|
||||
__DEFINE_IOMANIP_FN1( smanip, int, setfill)
|
||||
__DEFINE_IOMANIP_FN1( smanip, int, setprecision)
|
||||
__DEFINE_IOMANIP_FN1( smanip, int, setw)
|
||||
|
||||
__DEFINE_IOMANIP_FN1( smanip, ios::fmtflags, resetiosflags)
|
||||
__DEFINE_IOMANIP_FN1( smanip, ios::fmtflags, setiosflags)
|
||||
|
||||
#endif /*!_IOMANIP_H*/
|
||||
|
|
@ -1,239 +0,0 @@
|
|||
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
|
||||
Copyright (C) 1993 Free Software Foundation
|
||||
|
||||
This file is part of the GNU IO Library. This library 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, or (at your option)
|
||||
any later version.
|
||||
|
||||
This library 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 GNU CC; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
As a special exception, if you link this library with files
|
||||
compiled with a GNU compiler to produce an executable, this does not cause
|
||||
the resulting executable to be covered by the GNU General Public License.
|
||||
This exception does not however invalidate any other reasons why
|
||||
the executable file might be covered by the GNU General Public License. */
|
||||
|
||||
#ifndef _IOSTREAM_H
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define _IOSTREAM_H
|
||||
|
||||
#include <streambuf.h>
|
||||
|
||||
class istream; class ostream;
|
||||
typedef ios& (*__manip)(ios&);
|
||||
typedef istream& (*__imanip)(istream&);
|
||||
typedef ostream& (*__omanip)(ostream&);
|
||||
|
||||
extern istream& ws(istream& ins);
|
||||
extern ostream& flush(ostream& outs);
|
||||
extern ostream& endl(ostream& outs);
|
||||
extern ostream& ends(ostream& outs);
|
||||
|
||||
class ostream : virtual public ios
|
||||
{
|
||||
// NOTE: If fields are changed, you must fix _fake_ostream in stdstreams.C!
|
||||
void do_osfx();
|
||||
public:
|
||||
ostream() { }
|
||||
ostream(streambuf* sb, ostream* tied=NULL);
|
||||
int opfx() {
|
||||
if (!good()) return 0; else { if (_tie) _tie->flush(); return 1;} }
|
||||
void osfx() { if (flags() & (ios::unitbuf|ios::stdio))
|
||||
do_osfx(); }
|
||||
ostream& flush();
|
||||
ostream& put(char c) { _strbuf->sputc(c); return *this; }
|
||||
#ifdef _STREAM_COMPAT
|
||||
/* Temporary binary compatibility. REMOVE IN NEXT RELEASE. */
|
||||
ostream& put(unsigned char c) { return put((char)c); }
|
||||
ostream& put(signed char c) { return put((char)c); }
|
||||
#endif
|
||||
ostream& write(const char *s, int n);
|
||||
ostream& write(const unsigned char *s, int n) { return write((const char*)s, n);}
|
||||
ostream& write(const signed char *s, int n) { return write((const char*)s, n);}
|
||||
ostream& write(const void *s, int n) { return write((const char*)s, n);}
|
||||
ostream& seekp(streampos);
|
||||
ostream& seekp(streamoff, _seek_dir);
|
||||
streampos tellp();
|
||||
ostream& form(const char *format ...);
|
||||
ostream& vform(const char *format, _IO_va_list args);
|
||||
|
||||
ostream& operator<<(char c);
|
||||
ostream& operator<<(unsigned char c) { return (*this) << (char)c; }
|
||||
ostream& operator<<(signed char c) { return (*this) << (char)c; }
|
||||
ostream& operator<<(const char *s);
|
||||
ostream& operator<<(const unsigned char *s)
|
||||
{ return (*this) << (const char*)s; }
|
||||
ostream& operator<<(const signed char *s)
|
||||
{ return (*this) << (const char*)s; }
|
||||
ostream& operator<<(const void *p);
|
||||
ostream& operator<<(int n);
|
||||
ostream& operator<<(unsigned int n);
|
||||
ostream& operator<<(long n);
|
||||
ostream& operator<<(unsigned long n);
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||
ostream& operator<<(long long n);
|
||||
ostream& operator<<(unsigned long long n);
|
||||
#endif
|
||||
ostream& operator<<(short n) {return operator<<((int)n);}
|
||||
ostream& operator<<(unsigned short n) {return operator<<((unsigned int)n);}
|
||||
#if _G_HAVE_BOOL
|
||||
ostream& operator<<(bool b) { return operator<<((int)b); }
|
||||
#endif
|
||||
ostream& operator<<(double n);
|
||||
ostream& operator<<(float n) { return operator<<((double)n); }
|
||||
ostream& operator<<(long double n) { return operator<<((double)n); }
|
||||
ostream& operator<<(__omanip func) { return (*func)(*this); }
|
||||
ostream& operator<<(__manip func) {(*func)(*this); return *this;}
|
||||
ostream& operator<<(streambuf*);
|
||||
#ifdef _STREAM_COMPAT
|
||||
streambuf* ostreambuf() const { return _strbuf; }
|
||||
#endif
|
||||
};
|
||||
|
||||
class istream : virtual public ios
|
||||
{
|
||||
// NOTE: If fields are changed, you must fix _fake_istream in stdstreams.C!
|
||||
protected:
|
||||
_IO_size_t _gcount;
|
||||
|
||||
int _skip_ws();
|
||||
public:
|
||||
istream() { _gcount = 0; }
|
||||
istream(streambuf* sb, ostream*tied=NULL);
|
||||
istream& get(char* ptr, int len, char delim = '\n');
|
||||
istream& get(unsigned char* ptr, int len, char delim = '\n')
|
||||
{ return get((char*)ptr, len, delim); }
|
||||
istream& get(char& c);
|
||||
istream& get(unsigned char& c) { return get((char&)c); }
|
||||
istream& getline(char* ptr, int len, char delim = '\n');
|
||||
istream& getline(unsigned char* ptr, int len, char delim = '\n')
|
||||
{ return getline((char*)ptr, len, delim); }
|
||||
istream& get(signed char& c) { return get((char&)c); }
|
||||
istream& get(signed char* ptr, int len, char delim = '\n')
|
||||
{ return get((char*)ptr, len, delim); }
|
||||
istream& getline(signed char* ptr, int len, char delim = '\n')
|
||||
{ return getline((char*)ptr, len, delim); }
|
||||
istream& read(char *ptr, int n);
|
||||
istream& read(unsigned char *ptr, int n) { return read((char*)ptr, n); }
|
||||
istream& read(signed char *ptr, int n) { return read((char*)ptr, n); }
|
||||
istream& read(void *ptr, int n) { return read((char*)ptr, n); }
|
||||
istream& get(streambuf& sb, char delim = '\n');
|
||||
istream& gets(char **s, char delim = '\n');
|
||||
int ipfx(int need) {
|
||||
if (!good()) { set(ios::failbit); return 0; }
|
||||
else {
|
||||
if (_tie && (need == 0 || rdbuf()->in_avail() < need)) _tie->flush();
|
||||
if (!need && (flags() & ios::skipws)) return _skip_ws();
|
||||
else return 1;
|
||||
}
|
||||
}
|
||||
int ipfx0() { // Optimized version of ipfx(0).
|
||||
if (!good()) { set(ios::failbit); return 0; }
|
||||
else {
|
||||
if (_tie) _tie->flush();
|
||||
if (flags() & ios::skipws) return _skip_ws();
|
||||
else return 1;
|
||||
}
|
||||
}
|
||||
int ipfx1() { // Optimized version of ipfx(1).
|
||||
if (!good()) { set(ios::failbit); return 0; }
|
||||
else {
|
||||
if (_tie && rdbuf()->in_avail() == 0) _tie->flush();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
void isfx() { }
|
||||
int get() { if (!ipfx1()) return EOF;
|
||||
else { int ch = _strbuf->sbumpc();
|
||||
if (ch == EOF) set(ios::eofbit);
|
||||
return ch;
|
||||
} }
|
||||
int peek();
|
||||
_IO_size_t gcount() { return _gcount; }
|
||||
istream& ignore(int n=1, int delim = EOF);
|
||||
istream& seekg(streampos);
|
||||
istream& seekg(streamoff, _seek_dir);
|
||||
streampos tellg();
|
||||
istream& putback(char ch) {
|
||||
if (good() && _strbuf->sputbackc(ch) == EOF) clear(ios::badbit);
|
||||
return *this;}
|
||||
istream& unget() {
|
||||
if (good() && _strbuf->sungetc() == EOF) clear(ios::badbit);
|
||||
return *this;}
|
||||
istream& scan(const char *format ...);
|
||||
istream& vscan(const char *format, _IO_va_list args);
|
||||
#ifdef _STREAM_COMPAT
|
||||
istream& unget(char ch) { return putback(ch); }
|
||||
int skip(int i);
|
||||
streambuf* istreambuf() const { return _strbuf; }
|
||||
#endif
|
||||
|
||||
istream& operator>>(char*);
|
||||
istream& operator>>(unsigned char* p) { return operator>>((char*)p); }
|
||||
istream& operator>>(signed char*p) { return operator>>((char*)p); }
|
||||
istream& operator>>(char& c);
|
||||
istream& operator>>(unsigned char& c) {return operator>>((char&)c);}
|
||||
istream& operator>>(signed char& c) {return operator>>((char&)c);}
|
||||
istream& operator>>(int&);
|
||||
istream& operator>>(long&);
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||
istream& operator>>(long long&);
|
||||
istream& operator>>(unsigned long long&);
|
||||
#endif
|
||||
istream& operator>>(short&);
|
||||
istream& operator>>(unsigned int&);
|
||||
istream& operator>>(unsigned long&);
|
||||
istream& operator>>(unsigned short&);
|
||||
#if _G_HAVE_BOOL
|
||||
istream& operator>>(bool&);
|
||||
#endif
|
||||
istream& operator>>(float&);
|
||||
istream& operator>>(double&);
|
||||
istream& operator>>(long double&);
|
||||
istream& operator>>( __manip func) {(*func)(*this); return *this;}
|
||||
istream& operator>>(__imanip func) { return (*func)(*this); }
|
||||
istream& operator>>(streambuf*);
|
||||
};
|
||||
|
||||
class iostream : public istream, public ostream
|
||||
{
|
||||
public:
|
||||
iostream() { }
|
||||
iostream(streambuf* sb, ostream*tied=NULL);
|
||||
};
|
||||
|
||||
class _IO_istream_withassign : public istream {
|
||||
public:
|
||||
_IO_istream_withassign& operator=(istream&);
|
||||
};
|
||||
|
||||
class _IO_ostream_withassign : public ostream {
|
||||
public:
|
||||
_IO_ostream_withassign& operator=(ostream&);
|
||||
};
|
||||
|
||||
extern _IO_istream_withassign cin;
|
||||
// clog->rdbuf() == cerr->rdbuf()
|
||||
extern _IO_ostream_withassign cout, cerr, clog;
|
||||
|
||||
struct Iostream_init { } ; // Compatibility hack for AT&T library.
|
||||
|
||||
inline ios& dec(ios& i)
|
||||
{ i.setf(ios::dec, ios::dec|ios::hex|ios::oct); return i; }
|
||||
inline ios& hex(ios& i)
|
||||
{ i.setf(ios::hex, ios::dec|ios::hex|ios::oct); return i; }
|
||||
inline ios& oct(ios& i)
|
||||
{ i.setf(ios::oct, ios::dec|ios::hex|ios::oct); return i; }
|
||||
|
||||
#endif /*!_IOSTREAM_H*/
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 1993 Free Software Foundation
|
||||
|
||||
This file is part of the GNU IO Library. This library 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, or (at your option)
|
||||
any later version.
|
||||
|
||||
This library 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 GNU CC; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
As a special exception, if you link this library with files
|
||||
compiled with a GNU compiler to produce an executable, this does not cause
|
||||
the resulting executable to be covered by the GNU General Public License.
|
||||
This exception does not however invalidate any other reasons why
|
||||
the executable file might be covered by the GNU General Public License. */
|
||||
|
||||
#include "streambuf.h"
|
||||
#include "libioP.h"
|
||||
|
||||
inline _IO_seekflags
|
||||
convert_to_seekflags(int dir, int mode)
|
||||
{
|
||||
return (_IO_seekflags)((int)dir
|
||||
| (mode & ios::in ? _IO_seek_set : _IO_seek_not_in)
|
||||
| (mode & ios::out ? _IO_seek_set : _IO_seek_not_out));
|
||||
}
|
||||
|
|
@ -1,114 +0,0 @@
|
|||
/* Function declarations for libiberty.
|
||||
Written by Cygnus Support, 1994.
|
||||
|
||||
The libiberty library provides a number of functions which are
|
||||
missing on some operating systems. We do not declare those here,
|
||||
to avoid conflicts with the system header files on operating
|
||||
systems that do support those functions. In this file we only
|
||||
declare those functions which are specific to libiberty. */
|
||||
|
||||
#ifndef LIBIBERTY_H
|
||||
#define LIBIBERTY_H
|
||||
|
||||
#include "ansidecl.h"
|
||||
|
||||
/* Build an argument vector from a string. Allocates memory using
|
||||
malloc. Use freeargv to free the vector. */
|
||||
|
||||
extern char **buildargv PARAMS ((char *));
|
||||
|
||||
/* Free a vector returned by buildargv. */
|
||||
|
||||
extern void freeargv PARAMS ((char **));
|
||||
|
||||
/* Return the last component of a path name. */
|
||||
|
||||
extern char *basename PARAMS ((char *));
|
||||
|
||||
/* Concatenate an arbitrary number of strings, up to (char *) NULL.
|
||||
Allocates memory using xmalloc. */
|
||||
|
||||
extern char *concat PARAMS ((const char *, ...));
|
||||
|
||||
/* Check whether two file descriptors refer to the same file. */
|
||||
|
||||
extern int fdmatch PARAMS ((int fd1, int fd2));
|
||||
|
||||
/* Get the amount of time the process has run, in microseconds. */
|
||||
|
||||
extern long get_run_time PARAMS ((void));
|
||||
|
||||
/* Allocate memory filled with spaces. Allocates using malloc. */
|
||||
|
||||
extern const char *spaces PARAMS ((int count));
|
||||
|
||||
/* Return the maximum error number for which strerror will return a
|
||||
string. */
|
||||
|
||||
extern int errno_max PARAMS ((void));
|
||||
|
||||
/* Return the name of an errno value (e.g., strerrno (EINVAL) returns
|
||||
"EINVAL"). */
|
||||
|
||||
extern const char *strerrno PARAMS ((int));
|
||||
|
||||
/* Given the name of an errno value, return the value. */
|
||||
|
||||
extern int strtoerrno PARAMS ((const char *));
|
||||
|
||||
/* Return the maximum signal number for which strsignal will return a
|
||||
string. */
|
||||
|
||||
extern int signo_max PARAMS ((void));
|
||||
|
||||
/* Return a signal message string for a signal number
|
||||
(e.g., strsignal (SIGHUP) returns something like "Hangup"). */
|
||||
/* This is commented out as it can conflict with one in system headers.
|
||||
We still document its existence though. */
|
||||
|
||||
/*extern const char *strsignal PARAMS ((int));*/
|
||||
|
||||
/* Return the name of a signal number (e.g., strsigno (SIGHUP) returns
|
||||
"SIGHUP"). */
|
||||
|
||||
extern const char *strsigno PARAMS ((int));
|
||||
|
||||
/* Given the name of a signal, return its number. */
|
||||
|
||||
extern int strtosigno PARAMS ((const char *));
|
||||
|
||||
/* Register a function to be run by xexit. Returns 0 on success. */
|
||||
|
||||
extern int xatexit PARAMS ((void (*fn) (void)));
|
||||
|
||||
/* Exit, calling all the functions registered with xatexit. */
|
||||
|
||||
#ifndef __GNUC__
|
||||
extern void xexit PARAMS ((int status));
|
||||
#else
|
||||
typedef void libiberty_voidfn PARAMS ((int status));
|
||||
__volatile__ libiberty_voidfn xexit;
|
||||
#endif
|
||||
|
||||
/* Set the program name used by xmalloc. */
|
||||
|
||||
extern void xmalloc_set_program_name PARAMS ((const char *));
|
||||
|
||||
/* Allocate memory without fail. If malloc fails, this will print a
|
||||
message to stderr (using the name set by xmalloc_set_program_name,
|
||||
if any) and then call xexit.
|
||||
|
||||
FIXME: We do not declare the parameter type (size_t) in order to
|
||||
avoid conflicts with other declarations of xmalloc that exist in
|
||||
programs which use libiberty. */
|
||||
|
||||
extern PTR xmalloc ();
|
||||
|
||||
/* Reallocate memory without fail. This works like xmalloc.
|
||||
|
||||
FIXME: We do not declare the parameter types for the same reason as
|
||||
xmalloc. */
|
||||
|
||||
extern PTR xrealloc ();
|
||||
|
||||
#endif /* ! defined (LIBIBERTY_H) */
|
||||
|
|
@ -1,257 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 1993 Free Software Foundation
|
||||
|
||||
This file is part of the GNU IO Library. This library 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, or (at your option)
|
||||
any later version.
|
||||
|
||||
This library 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 GNU CC; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
As a special exception, if you link this library with files
|
||||
compiled with a GNU compiler to produce an executable, this does not cause
|
||||
the resulting executable to be covered by the GNU General Public License.
|
||||
This exception does not however invalidate any other reasons why
|
||||
the executable file might be covered by the GNU General Public License. */
|
||||
|
||||
/* This is part of the iostream library.
|
||||
Copyright (C) 1991, 1992 Per Bothner. */
|
||||
|
||||
#ifndef _IO_STDIO_H
|
||||
#define _IO_STDIO_H
|
||||
|
||||
#if 1
|
||||
#include <_G_config.h>
|
||||
#define _IO_pos_t _G_fpos_t /* obsolete */
|
||||
#define _IO_fpos_t _G_fpos_t
|
||||
#define _IO_size_t _G_size_t
|
||||
#define _IO_ssize_t _G_ssize_t
|
||||
#define _IO_off_t _G_off_t
|
||||
#define _IO_pid_t _G_pid_t
|
||||
#define _IO_uid_t _G_uid_t
|
||||
#define _IO_HAVE_SYS_WAIT _G_HAVE_SYS_WAIT
|
||||
#define _IO_HAVE_ST_BLKSIZE _G_HAVE_ST_BLKSIZE
|
||||
#define _IO_BUFSIZ _G_BUFSIZ
|
||||
#define _IO_va_list _G_va_list
|
||||
|
||||
#ifdef _G_NEED_STDARG_H
|
||||
/* This define avoids name pollution if we're using GNU stdarg.h */
|
||||
#define __need___va_list
|
||||
#include <stdarg.h>
|
||||
#ifdef __GNUC_VA_LIST
|
||||
#undef _IO_va_list
|
||||
#define _IO_va_list __gnuc_va_list
|
||||
#endif /* __GNUC_VA_LIST */
|
||||
#endif
|
||||
|
||||
#else
|
||||
#include <_IO_config.h>
|
||||
typedef _IO_fpos_t _IO_pos_t;
|
||||
#endif
|
||||
|
||||
#ifndef __P
|
||||
#ifdef __STDC__
|
||||
#define __P(paramlist) paramlist
|
||||
#else
|
||||
#define __P(paramlist) ()
|
||||
#endif
|
||||
#endif /*!__P*/
|
||||
|
||||
/* For backward compatibility */
|
||||
#ifndef _PARAMS
|
||||
#define _PARAMS(paramlist) __P(paramlist)
|
||||
#endif /*!_PARAMS*/
|
||||
|
||||
#ifndef __STDC__
|
||||
#define const
|
||||
#endif
|
||||
#define _IO_USE_DTOA
|
||||
|
||||
#if 0
|
||||
#ifdef _IO_NEED_STDARG_H
|
||||
#include <stdarg.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef EOF
|
||||
#define EOF (-1)
|
||||
#endif
|
||||
#ifndef NULL
|
||||
#if !defined(__cplusplus) || defined(__GNUC__)
|
||||
#define NULL ((void*)0)
|
||||
#else
|
||||
#define NULL (0)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define _IOS_INPUT 1
|
||||
#define _IOS_OUTPUT 2
|
||||
#define _IOS_ATEND 4
|
||||
#define _IOS_APPEND 8
|
||||
#define _IOS_TRUNC 16
|
||||
#define _IOS_NOCREATE 32
|
||||
#define _IOS_NOREPLACE 64
|
||||
#define _IOS_BIN 128
|
||||
|
||||
/* Magic numbers and bits for the _flags field.
|
||||
The magic numbers use the high-order bits of _flags;
|
||||
the remaining bits are abailable for variable flags.
|
||||
Note: The magic numbers must all be negative if stdio
|
||||
emulation is desired. */
|
||||
|
||||
#define _IO_MAGIC 0xFBAD0000 /* Magic number */
|
||||
#define _OLD_STDIO_MAGIC 0xFABC0000 /* Emulate old stdio. */
|
||||
#define _IO_MAGIC_MASK 0xFFFF0000
|
||||
#define _IO_USER_BUF 1 /* User owns buffer; don't delete it on close. */
|
||||
#define _IO_UNBUFFERED 2
|
||||
#define _IO_NO_READS 4 /* Reading not allowed */
|
||||
#define _IO_NO_WRITES 8 /* Writing not allowd */
|
||||
#define _IO_EOF_SEEN 0x10
|
||||
#define _IO_ERR_SEEN 0x20
|
||||
#define _IO_DELETE_DONT_CLOSE 0x40
|
||||
#define _IO_LINKED 0x80 /* Set if linked (using _chain) to streambuf::_list_all.*/
|
||||
#define _IO_IN_BACKUP 0x100
|
||||
#define _IO_LINE_BUF 0x200
|
||||
#define _IO_TIED_PUT_GET 0x400 /* Set if put and get pointer logicly tied. */
|
||||
#define _IO_CURRENTLY_PUTTING 0x800
|
||||
#define _IO_IS_APPENDING 0x1000
|
||||
#define _IO_IS_FILEBUF 0x2000
|
||||
|
||||
/* These are "formatting flags" matching the iostream fmtflags enum values. */
|
||||
#define _IO_SKIPWS 01
|
||||
#define _IO_LEFT 02
|
||||
#define _IO_RIGHT 04
|
||||
#define _IO_INTERNAL 010
|
||||
#define _IO_DEC 020
|
||||
#define _IO_OCT 040
|
||||
#define _IO_HEX 0100
|
||||
#define _IO_SHOWBASE 0200
|
||||
#define _IO_SHOWPOINT 0400
|
||||
#define _IO_UPPERCASE 01000
|
||||
#define _IO_SHOWPOS 02000
|
||||
#define _IO_SCIENTIFIC 04000
|
||||
#define _IO_FIXED 010000
|
||||
#define _IO_UNITBUF 020000
|
||||
#define _IO_STDIO 040000
|
||||
#define _IO_DONT_CLOSE 0100000
|
||||
|
||||
/* A streammarker remembers a position in a buffer. */
|
||||
|
||||
struct _IO_jump_t; struct _IO_FILE;
|
||||
|
||||
struct _IO_marker {
|
||||
struct _IO_marker *_next;
|
||||
struct _IO_FILE *_sbuf;
|
||||
/* If _pos >= 0
|
||||
it points to _buf->Gbase()+_pos. FIXME comment */
|
||||
/* if _pos < 0, it points to _buf->eBptr()+_pos. FIXME comment */
|
||||
int _pos;
|
||||
#if 0
|
||||
void set_streampos(streampos sp) { _spos = sp; }
|
||||
void set_offset(int offset) { _pos = offset; _spos = (streampos)(-2); }
|
||||
public:
|
||||
streammarker(streambuf *sb);
|
||||
~streammarker();
|
||||
int saving() { return _spos == -2; }
|
||||
int delta(streammarker&);
|
||||
int delta();
|
||||
#endif
|
||||
};
|
||||
|
||||
struct _IO_FILE {
|
||||
int _flags; /* High-order word is _IO_MAGIC; rest is flags. */
|
||||
#define _IO_file_flags _flags
|
||||
|
||||
/* The following pointers correspond to the C++ streambuf protocol. */
|
||||
char* _IO_read_ptr; /* Current read pointer */
|
||||
char* _IO_read_end; /* End of get area. */
|
||||
char* _IO_read_base; /* Start of putback+get area. */
|
||||
char* _IO_write_base; /* Start of put area. */
|
||||
char* _IO_write_ptr; /* Current put pointer. */
|
||||
char* _IO_write_end; /* End of put area. */
|
||||
char* _IO_buf_base; /* Start of reserve area. */
|
||||
char* _IO_buf_end; /* End of reserve area. */
|
||||
/* The following fields are used to support backing up and undo. */
|
||||
char *_IO_save_base; /* Pointer to start of non-current get area. */
|
||||
char *_IO_backup_base; /* Pointer to first valid character of backup area */
|
||||
char *_IO_save_end; /* Pointer to end of non-current get area. */
|
||||
|
||||
struct _IO_marker *_markers;
|
||||
|
||||
struct _IO_FILE *_chain;
|
||||
|
||||
struct _IO_jump_t *_jumps; /* Jump table */
|
||||
|
||||
int _fileno;
|
||||
int _blksize;
|
||||
_IO_off_t _offset;
|
||||
|
||||
#define __HAVE_COLUMN /* temporary */
|
||||
/* 1+column number of pbase(); 0 is unknown. */
|
||||
unsigned short _cur_column;
|
||||
char _unused;
|
||||
char _shortbuf[1];
|
||||
|
||||
/* char* _save_gptr; char* _save_egptr; */
|
||||
};
|
||||
|
||||
#ifndef __cplusplus
|
||||
typedef struct _IO_FILE _IO_FILE;
|
||||
#endif
|
||||
|
||||
struct _IO_FILE_plus;
|
||||
extern struct _IO_FILE_plus _IO_stdin_, _IO_stdout_, _IO_stderr_;
|
||||
#define _IO_stdin ((_IO_FILE*)(&_IO_stdin_))
|
||||
#define _IO_stdout ((_IO_FILE*)(&_IO_stdout_))
|
||||
#define _IO_stderr ((_IO_FILE*)(&_IO_stderr_))
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int __underflow __P((_IO_FILE*));
|
||||
extern int __uflow __P((_IO_FILE*));
|
||||
extern int __overflow __P((_IO_FILE*, int));
|
||||
|
||||
extern unsigned __adjust_column __P((unsigned start, const char *line, int count));
|
||||
|
||||
#define _IO_getc(_fp) \
|
||||
((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end ? __uflow(_fp) \
|
||||
: *(unsigned char*)(_fp)->_IO_read_ptr++)
|
||||
#define _IO_peekc(_fp) \
|
||||
((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end \
|
||||
&& __underflow(_fp) == EOF ? EOF \
|
||||
: *(unsigned char*)(_fp)->_IO_read_ptr)
|
||||
|
||||
#define _IO_putc(_ch, _fp) \
|
||||
(((_fp)->_IO_write_ptr >= (_fp)->_IO_write_end) \
|
||||
? __overflow(_fp, (unsigned char)(_ch)) \
|
||||
: (unsigned char)(*(_fp)->_IO_write_ptr++ = (_ch)))
|
||||
|
||||
#define _IO_feof(__fp) (((__fp)->_flags & _IO_EOF_SEEN) != 0)
|
||||
#define _IO_ferror(__fp) (((__fp)->_flags & _IO_ERR_SEEN) != 0)
|
||||
|
||||
/* This one is for Emacs. */
|
||||
#define _IO_PENDING_OUTPUT_COUNT(_fp) \
|
||||
((_fp)->_IO_write_ptr - (_fp)->_IO_write_base)
|
||||
|
||||
extern int _IO_vfscanf __P((_IO_FILE*, const char*, _IO_va_list, int*));
|
||||
extern int _IO_vfprintf __P((_IO_FILE*, const char*, _IO_va_list));
|
||||
extern _IO_ssize_t _IO_padn __P((_IO_FILE *, int, _IO_ssize_t));
|
||||
extern _IO_size_t _IO_sgetn __P((_IO_FILE *, void*, _IO_size_t));
|
||||
|
||||
extern void _IO_free_backup_area __P((_IO_FILE*));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _IO_STDIO_H */
|
||||
|
|
@ -1,326 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 1993 Free Software Foundation
|
||||
|
||||
This file is part of the GNU IO Library. This library 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, or (at your option)
|
||||
any later version.
|
||||
|
||||
This library 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 GNU CC; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
As a special exception, if you link this library with files
|
||||
compiled with a GNU compiler to produce an executable, this does not cause
|
||||
the resulting executable to be covered by the GNU General Public License.
|
||||
This exception does not however invalidate any other reasons why
|
||||
the executable file might be covered by the GNU General Public License. */
|
||||
|
||||
#include <errno.h>
|
||||
#ifndef errno
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
#include "iolibio.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum _IO_seekflags_ {
|
||||
_IO_seek_set = 0,
|
||||
_IO_seek_cur = 1,
|
||||
_IO_seek_end = 2,
|
||||
|
||||
/* These bits are ignored unless the _IO_FILE has independent
|
||||
read and write positions. */
|
||||
_IO_seek_not_in = 4, /* Don't move read posistion. */
|
||||
_IO_seek_not_out = 8, /* Don't move write posistion. */
|
||||
_IO_seek_pos_ignored = 16 /* Result is ignored (except EOF) */
|
||||
} _IO_seekflags;
|
||||
|
||||
typedef int (*_IO_overflow_t) __P((_IO_FILE*, int));
|
||||
typedef int (*_IO_underflow_t) __P((_IO_FILE*));
|
||||
typedef _IO_size_t (*_IO_xsputn_t) __P((_IO_FILE*,const void*,_IO_size_t));
|
||||
typedef _IO_size_t (*_IO_xsgetn_t) __P((_IO_FILE*, void*, _IO_size_t));
|
||||
typedef _IO_ssize_t (*_IO_read_t) __P((_IO_FILE*, void*, _IO_ssize_t));
|
||||
typedef _IO_ssize_t (*_IO_write_t) __P((_IO_FILE*,const void*,_IO_ssize_t));
|
||||
typedef int (*_IO_stat_t) __P((_IO_FILE*, void*));
|
||||
typedef _IO_fpos_t (*_IO_seek_t) __P((_IO_FILE*, _IO_off_t, int));
|
||||
typedef int (*_IO_doallocate_t) __P((_IO_FILE*));
|
||||
typedef int (*_IO_pbackfail_t) __P((_IO_FILE*, int));
|
||||
typedef int (*_IO_setbuf_t) __P((_IO_FILE*, char *, _IO_ssize_t));
|
||||
typedef int (*_IO_sync_t) __P((_IO_FILE*));
|
||||
typedef void (*_IO_finish_t) __P((_IO_FILE*)); /* finalize */
|
||||
typedef int (*_IO_close_t) __P((_IO_FILE*)); /* finalize */
|
||||
typedef _IO_fpos_t (*_IO_seekoff_t) __P((_IO_FILE*, _IO_off_t, _IO_seekflags));
|
||||
|
||||
/* The _IO_seek_cur and _IO_seek_end options are not allowed. */
|
||||
typedef _IO_fpos_t (*_IO_seekpos_t) __P((_IO_FILE*, _IO_fpos_t, _IO_seekflags));
|
||||
|
||||
struct _IO_jump_t {
|
||||
_IO_overflow_t __overflow;
|
||||
_IO_underflow_t __underflow;
|
||||
_IO_xsputn_t __xsputn;
|
||||
_IO_xsgetn_t __xsgetn;
|
||||
_IO_read_t __read;
|
||||
_IO_write_t __write;
|
||||
_IO_doallocate_t __doallocate;
|
||||
_IO_pbackfail_t __pbackfail;
|
||||
_IO_setbuf_t __setbuf;
|
||||
_IO_sync_t __sync;
|
||||
_IO_finish_t __finish;
|
||||
_IO_close_t __close;
|
||||
_IO_stat_t __stat;
|
||||
_IO_seek_t __seek;
|
||||
_IO_seekoff_t __seekoff;
|
||||
_IO_seekpos_t __seekpos;
|
||||
_IO_underflow_t __uflow;
|
||||
#if 0
|
||||
get_column;
|
||||
set_column;
|
||||
#endif
|
||||
};
|
||||
|
||||
/* We always allocate an extra word following an _IO_FILE.
|
||||
This is for compatibility with C++ streambuf; the word can
|
||||
be used to smash to a pointer to a virtual function table. */
|
||||
|
||||
struct _IO_FILE_plus {
|
||||
_IO_FILE file;
|
||||
const void *vtable;
|
||||
};
|
||||
|
||||
/* Generic functions */
|
||||
|
||||
extern _IO_fpos_t _IO_seekoff __P((_IO_FILE*, _IO_off_t, _IO_seekflags));
|
||||
extern _IO_fpos_t _IO_seekpos __P((_IO_FILE*, _IO_fpos_t, _IO_seekflags));
|
||||
|
||||
extern int _IO_switch_to_get_mode __P((_IO_FILE*));
|
||||
extern void _IO_init __P((_IO_FILE*, int));
|
||||
extern int _IO_sputbackc __P((_IO_FILE*, int));
|
||||
extern int _IO_sungetc __P((_IO_FILE*));
|
||||
extern void _IO_un_link __P((_IO_FILE*));
|
||||
extern void _IO_link_in __P((_IO_FILE *));
|
||||
extern void _IO_doallocbuf __P((_IO_FILE*));
|
||||
extern void _IO_unsave_markers __P((_IO_FILE*));
|
||||
extern void _IO_setb __P((_IO_FILE*, char*, char*, int));
|
||||
extern unsigned _IO_adjust_column __P((unsigned, const char *, int));
|
||||
#define _IO_sputn(__fp, __s, __n) (__fp->_jumps->__xsputn(__fp, __s, __n))
|
||||
|
||||
/* Marker-related function. */
|
||||
|
||||
extern void _IO_init_marker __P((struct _IO_marker *, _IO_FILE *));
|
||||
extern void _IO_remove_marker __P((struct _IO_marker*));
|
||||
extern int _IO_marker_difference __P((struct _IO_marker *, struct _IO_marker *));
|
||||
extern int _IO_marker_delta __P((struct _IO_marker *));
|
||||
extern int _IO_seekmark __P((_IO_FILE *, struct _IO_marker *, int));
|
||||
|
||||
/* Default jumptable functions. */
|
||||
|
||||
extern int _IO_default_underflow __P((_IO_FILE*));
|
||||
extern int _IO_default_uflow _PARAMS((_IO_FILE*));
|
||||
extern int _IO_default_doallocate __P((_IO_FILE*));
|
||||
extern void _IO_default_finish __P((_IO_FILE *));
|
||||
extern int _IO_default_pbackfail __P((_IO_FILE*, int));
|
||||
extern int _IO_default_setbuf __P((_IO_FILE *, char*, _IO_ssize_t));
|
||||
extern _IO_size_t _IO_default_xsputn __P((_IO_FILE *, const void*, _IO_size_t));
|
||||
extern _IO_size_t _IO_default_xsgetn __P((_IO_FILE *, void*, _IO_size_t));
|
||||
extern _IO_fpos_t _IO_default_seekoff __P((_IO_FILE*, _IO_off_t, _IO_seekflags));
|
||||
extern _IO_fpos_t _IO_default_seekpos __P((_IO_FILE*, _IO_fpos_t, _IO_seekflags));
|
||||
extern _IO_ssize_t _IO_default_write __P((_IO_FILE*,const void*,_IO_ssize_t));
|
||||
extern _IO_ssize_t _IO_default_read __P((_IO_FILE*, void*, _IO_ssize_t));
|
||||
extern int _IO_default_stat __P((_IO_FILE*, void*));
|
||||
extern _IO_fpos_t _IO_default_seek __P((_IO_FILE*, _IO_off_t, int));
|
||||
extern int _IO_default_sync __P((_IO_FILE*));
|
||||
#define _IO_default_close ((_IO_close_t)_IO_default_sync)
|
||||
|
||||
extern struct _IO_jump_t _IO_file_jumps;
|
||||
extern struct _IO_jump_t _IO_streambuf_jumps;
|
||||
extern struct _IO_jump_t _IO_proc_jumps;
|
||||
extern struct _IO_jump_t _IO_str_jumps;
|
||||
extern int _IO_do_write __P((_IO_FILE*, const char*, _IO_size_t));
|
||||
extern int _IO_flush_all __P((void));
|
||||
extern void _IO_cleanup __P((void));
|
||||
extern void _IO_flush_all_linebuffered __P((void));
|
||||
|
||||
#define _IO_do_flush(_f) \
|
||||
_IO_do_write(_f, (_f)->_IO_write_base, \
|
||||
(_f)->_IO_write_ptr-(_f)->_IO_write_base)
|
||||
#define _IO_in_put_mode(_fp) ((_fp)->_flags & _IO_CURRENTLY_PUTTING)
|
||||
#define _IO_mask_flags(fp, f, mask) \
|
||||
((fp)->_flags = ((fp)->_flags & ~(mask)) | ((f) & (mask)))
|
||||
#define _IO_setg(fp, eb, g, eg) ((fp)->_IO_read_base = (eb),\
|
||||
(fp)->_IO_read_ptr = (g), (fp)->_IO_read_end = (eg))
|
||||
#define _IO_setp(__fp, __p, __ep) \
|
||||
((__fp)->_IO_write_base = (__fp)->_IO_write_ptr = __p, (__fp)->_IO_write_end = (__ep))
|
||||
#define _IO_have_backup(fp) ((fp)->_IO_save_base != NULL)
|
||||
#define _IO_in_backup(fp) ((fp)->_flags & _IO_IN_BACKUP)
|
||||
#define _IO_have_markers(fp) ((fp)->_markers != NULL)
|
||||
#define _IO_blen(p) ((fp)->_IO_buf_end - (fp)->_IO_buf_base)
|
||||
|
||||
/* Jumptable functions for files. */
|
||||
|
||||
extern int _IO_file_doallocate __P((_IO_FILE*));
|
||||
extern int _IO_file_setbuf __P((_IO_FILE *, char*, _IO_ssize_t));
|
||||
extern _IO_fpos_t _IO_file_seekoff __P((_IO_FILE*, _IO_off_t, _IO_seekflags));
|
||||
extern _IO_size_t _IO_file_xsputn __P((_IO_FILE*,const void*,_IO_size_t));
|
||||
extern int _IO_file_stat __P((_IO_FILE*, void*));
|
||||
extern int _IO_file_close __P((_IO_FILE*));
|
||||
extern int _IO_file_underflow __P((_IO_FILE *));
|
||||
extern int _IO_file_overflow __P((_IO_FILE *, int));
|
||||
#define _IO_file_is_open(__fp) ((__fp)->_fileno >= 0)
|
||||
extern void _IO_file_init __P((_IO_FILE*));
|
||||
extern _IO_FILE* _IO_file_attach __P((_IO_FILE*, int));
|
||||
extern _IO_FILE* _IO_file_fopen __P((_IO_FILE*, const char*, const char*));
|
||||
extern _IO_ssize_t _IO_file_write __P((_IO_FILE*,const void*,_IO_ssize_t));
|
||||
extern _IO_ssize_t _IO_file_read __P((_IO_FILE*, void*, _IO_ssize_t));
|
||||
extern int _IO_file_sync __P((_IO_FILE*));
|
||||
extern int _IO_file_close_it __P((_IO_FILE*));
|
||||
extern _IO_fpos_t _IO_file_seek __P((_IO_FILE *, _IO_off_t, int));
|
||||
extern void _IO_file_finish __P((_IO_FILE*));
|
||||
|
||||
/* Other file functions. */
|
||||
extern _IO_FILE* _IO_file_attach __P((_IO_FILE *, int));
|
||||
|
||||
/* Jumptable functions for proc_files. */
|
||||
extern _IO_FILE* _IO_proc_open __P((_IO_FILE*, const char*, const char *));
|
||||
extern int _IO_proc_close __P((_IO_FILE*));
|
||||
|
||||
/* Jumptable functions for strfiles. */
|
||||
extern int _IO_str_underflow __P((_IO_FILE*));
|
||||
extern int _IO_str_overflow __P((_IO_FILE *, int));
|
||||
extern int _IO_str_pbackfail __P((_IO_FILE*, int));
|
||||
extern _IO_fpos_t _IO_str_seekoff __P((_IO_FILE*,_IO_off_t,_IO_seekflags));
|
||||
|
||||
/* Other strfile functions */
|
||||
extern void _IO_str_init_static __P((_IO_FILE *, char*, int, char*));
|
||||
extern void _IO_str_init_readonly __P((_IO_FILE *, const char*, int));
|
||||
extern _IO_ssize_t _IO_str_count __P ((_IO_FILE*));
|
||||
|
||||
extern _IO_size_t _IO_getline __P((_IO_FILE*,char*,_IO_size_t,int,int));
|
||||
extern _IO_ssize_t _IO_getdelim __P((char**, _IO_size_t*, int, _IO_FILE*));
|
||||
extern double _IO_strtod __P((const char *, char **));
|
||||
extern char * _IO_dtoa __P((double __d, int __mode, int __ndigits,
|
||||
int *__decpt, int *__sign, char **__rve));
|
||||
extern int _IO_outfloat __P((double __value, _IO_FILE *__sb, int __type,
|
||||
int __width, int __precision, int __flags,
|
||||
int __sign_mode, int __fill));
|
||||
|
||||
extern _IO_FILE *_IO_list_all;
|
||||
extern void (*_IO_cleanup_registration_needed) __P ((void));
|
||||
|
||||
#ifndef EOF
|
||||
#define EOF (-1)
|
||||
#endif
|
||||
#ifndef NULL
|
||||
#if !defined(__cplusplus) || defined(__GNUC__)
|
||||
#define NULL ((void*)0)
|
||||
#else
|
||||
#define NULL (0)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define FREE_BUF(_B) free(_B)
|
||||
#define ALLOC_BUF(_S) (char*)malloc(_S)
|
||||
|
||||
#ifndef OS_FSTAT
|
||||
#define OS_FSTAT fstat
|
||||
#endif
|
||||
struct stat;
|
||||
extern _IO_ssize_t _IO_read __P((int, void*, _IO_size_t));
|
||||
extern _IO_ssize_t _IO_write __P((int, const void*, _IO_size_t));
|
||||
extern _IO_off_t _IO_lseek __P((int, _IO_off_t, int));
|
||||
extern int _IO_close __P((int));
|
||||
extern int _IO_fstat __P((int, struct stat *));
|
||||
|
||||
/* Operations on _IO_fpos_t.
|
||||
Normally, these are trivial, but we provide hooks for configurations
|
||||
where an _IO_fpos_t is a struct.
|
||||
Note that _IO_off_t must be an integral type. */
|
||||
|
||||
/* _IO_pos_BAD is an _IO_fpos_t value indicating error, unknown, or EOF. */
|
||||
#ifndef _IO_pos_BAD
|
||||
#define _IO_pos_BAD ((_IO_fpos_t)(-1))
|
||||
#endif
|
||||
/* _IO_pos_as_off converts an _IO_fpos_t value to an _IO_off_t value. */
|
||||
#ifndef _IO_pos_as_off
|
||||
#define _IO_pos_as_off(__pos) ((_IO_off_t)(__pos))
|
||||
#endif
|
||||
/* _IO_pos_adjust adjust an _IO_fpos_t by some number of bytes. */
|
||||
#ifndef _IO_pos_adjust
|
||||
#define _IO_pos_adjust(__pos, __delta) ((__pos) += (__delta))
|
||||
#endif
|
||||
/* _IO_pos_0 is an _IO_fpos_t value indicating beginning of file. */
|
||||
#ifndef _IO_pos_0
|
||||
#define _IO_pos_0 ((_IO_fpos_t)0)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/* check following! */
|
||||
#define FILEBUF_LITERAL(CHAIN, FLAGS, FD) \
|
||||
{ _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, &_IO_file_jumps, FD}
|
||||
|
||||
/* Define builtinbuf_vtable as a name for the virtual function table
|
||||
of the builtinbuf class. */
|
||||
#if !defined(builtinbuf_vtable) && defined(__cplusplus)
|
||||
#ifdef __GNUC__
|
||||
extern char builtinbuf_vtable[]
|
||||
asm (_G_VTABLE_LABEL_PREFIX
|
||||
#if _G_VTABLE_LABEL_HAS_LENGTH
|
||||
"10"
|
||||
#endif
|
||||
"builtinbuf");
|
||||
#else /* !__GNUC__ */
|
||||
#if _G_VTABLE_LABEL_HAS_LENGTH
|
||||
#define builtinbuf_vtable _G_VTABLE_LABEL_PREFIX_ID##10builtinbuf
|
||||
#else
|
||||
#define builtinbuf_vtable _G_VTABLE_LABEL_PREFIX_ID##builtinbuf
|
||||
#endif
|
||||
extern char builtinbuf_vtable[];
|
||||
#endif /* !__GNUC__ */
|
||||
#endif /* !defined(builtinbuf_vtable) && defined(__cplusplus) */
|
||||
|
||||
#if defined(__STDC__) || defined(__cplusplus)
|
||||
#define _IO_va_start(args, last) va_start(args, last)
|
||||
#else
|
||||
#define _IO_va_start(args, last) va_start(args)
|
||||
#endif
|
||||
|
||||
extern struct _IO_fake_stdiobuf _IO_stdin_buf, _IO_stdout_buf, _IO_stderr_buf;
|
||||
|
||||
#if 1
|
||||
#define COERCE_FILE(FILE) /* Nothing */
|
||||
#else
|
||||
/* This is part of the kludge for binary compatibility with old stdio. */
|
||||
#define COERCE_FILE(FILE) \
|
||||
(((FILE)->_IO_file_flags & _IO_MAGIC_MASK) == _OLD_MAGIC_MASK \
|
||||
&& (FILE) = *(FILE**)&((int*)fp)[1])
|
||||
#endif
|
||||
|
||||
#ifdef EINVAL
|
||||
#define MAYBE_SET_EINVAL errno = EINVAL
|
||||
#else
|
||||
#define MAYBE_SET_EINVAL /* nothing */
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
#define CHECK_FILE(FILE,RET) \
|
||||
if ((FILE) == NULL) { MAYBE_SET_EINVAL; return RET; } \
|
||||
else { COERCE_FILE(FILE); \
|
||||
if (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \
|
||||
{ errno = EINVAL; return RET; }}
|
||||
#else
|
||||
#define CHECK_FILE(FILE,RET) \
|
||||
COERCE_FILE(FILE)
|
||||
#endif
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
#ifndef _new_h
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#define _new_h 1
|
||||
|
||||
#include <defines.h>
|
||||
|
||||
#ifndef NO_LIBGXX_MALLOC
|
||||
#define MALLOC_ALIGN_MASK 7 /* ptrs aligned at 8 byte boundaries */
|
||||
#define MALLOC_MIN_OVERHEAD 8 /* 8 bytes of overhead per pointer */
|
||||
#endif
|
||||
|
||||
extern "C" fvoid_t *set_new_handler(fvoid_t *);
|
||||
|
||||
#ifdef __GNUG__
|
||||
extern fvoid_t *__new_handler;
|
||||
extern "C" void __default_new_handler();
|
||||
|
||||
#define NEW(where) new ( where )
|
||||
#endif
|
||||
|
||||
// default placement version of operator new
|
||||
inline void *operator new(size_t, void *place) { return place; }
|
||||
inline void *operator new[](size_t, void *place) { return place; }
|
||||
|
||||
#endif
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
|
||||
#ifndef OSFCN_H
|
||||
#define OSFCN_H 1
|
||||
|
||||
#include <std.h>
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
#if _G_HAVE_SYS_SOCKET
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
#if _G_HAVE_SYS_RESOURCE
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -1,154 +0,0 @@
|
|||
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
|
||||
Copyright (C) 1993 Free Software Foundation
|
||||
|
||||
This file is part of the GNU IO Library. This library 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, or (at your option)
|
||||
any later version.
|
||||
|
||||
This library 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 GNU CC; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
As a special exception, if you link this library with files
|
||||
compiled with a GNU compiler to produce an executable, this does not cause
|
||||
the resulting executable to be covered by the GNU General Public License.
|
||||
This exception does not however invalidate any other reasons why
|
||||
the executable file might be covered by the GNU General Public License.
|
||||
|
||||
Written by Per Bothner (bothner@cygnus.com). */
|
||||
|
||||
#ifndef PARSESTREAM_H
|
||||
#define PARSESTREAM_H
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#include "streambuf.h"
|
||||
|
||||
// A parsebuf is a streambuf optimized for scanning text files.
|
||||
// It keeps track of line and column numbers.
|
||||
// It is guaranteed to remember the entire current line,
|
||||
// as well the '\n'-s on either side of it (if they exist).
|
||||
// You can arbitrarily seek (or unget) within this extended line.
|
||||
// Other backward seeks are not supported.
|
||||
// Normal read semantics are supported (and hence istream operators like >>).
|
||||
|
||||
class parsebuf : public streambuf {
|
||||
protected:
|
||||
_IO_fpos_t pos_at_line_start;
|
||||
long _line_length;
|
||||
unsigned long __line_number;
|
||||
char *buf_start;
|
||||
char *buf_end;
|
||||
|
||||
public:
|
||||
parsebuf *chain;
|
||||
|
||||
// Return column number (raw - don't handle tabs etc).
|
||||
// Retult can be -1, meaning: at '\n' before current line.
|
||||
virtual int tell_in_line();
|
||||
|
||||
// seek to (raw) column I in current line.
|
||||
// Result is new (raw) column position - differs from I if unable to seek.
|
||||
// Seek to -1 tries to seek to before previous LF.
|
||||
virtual int seek_in_line(int i);
|
||||
|
||||
// Note: there is no "current line" initially, until something is read.
|
||||
|
||||
// Current line number, starting with 0.
|
||||
// If tell_in_line()==-1, then line number of next line.
|
||||
int line_number() { return __line_number; }
|
||||
|
||||
// Length of current line, not counting either '\n'.
|
||||
int line_length() { return _line_length; }
|
||||
// Current line - not a copy, so file ops may trash it.
|
||||
virtual char* current_line();
|
||||
virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
|
||||
virtual streambuf* setbuf(char* p, int len);
|
||||
protected:
|
||||
parsebuf() { chain= NULL;
|
||||
__line_number = 0; pos_at_line_start = 0; _line_length = -1; }
|
||||
virtual int pbackfail(int c);
|
||||
};
|
||||
|
||||
// A string_parsebuf is a parsebuf whose source is a fixed string.
|
||||
|
||||
class string_parsebuf : public parsebuf {
|
||||
public:
|
||||
int do_delete;
|
||||
string_parsebuf(char *str, int len, int delete_at_close=0);
|
||||
virtual int underflow();
|
||||
virtual char* current_line();
|
||||
virtual int seek_in_line(int i);
|
||||
virtual int tell_in_line();
|
||||
char *left() const { return base(); }
|
||||
char *right() const { return ebuf(); }
|
||||
// streampos seekoff(streamoff, _seek_dir, int);
|
||||
};
|
||||
|
||||
// A func_parsebuf calls a given function to get new input.
|
||||
// Each call returns an entire NUL-terminated line (without the '\n').
|
||||
// That line has been allocated with malloc(), not new.
|
||||
// The interface is tailored to the GNU readline library.
|
||||
// Example:
|
||||
// char* DoReadLine(void* arg)
|
||||
// {
|
||||
// char *line = readline((char*)arg); /* 'arg' is used as prompt. */
|
||||
// if line == NULL) { putc('\n', stderr); return NULL; }
|
||||
// if (line[0] != '\0') add_history(line);
|
||||
// return line;
|
||||
// }
|
||||
// char PromptBuffer[100] = "> ";
|
||||
// func_parsebuf my_stream(DoReadLine, PromptBuffer);
|
||||
|
||||
typedef char *(*CharReader)(void *arg);
|
||||
class istream;
|
||||
|
||||
class func_parsebuf : public parsebuf {
|
||||
public:
|
||||
void *arg;
|
||||
CharReader read_func;
|
||||
int backed_up_to_newline;
|
||||
func_parsebuf(CharReader func, void *argm = NULL);
|
||||
int underflow();
|
||||
virtual int tell_in_line();
|
||||
virtual int seek_in_line(int i);
|
||||
virtual char* current_line();
|
||||
};
|
||||
|
||||
// A general_parsebuf is a parsebuf which gets its input from some
|
||||
// other streambuf. It explicitly buffers up an entire line.
|
||||
|
||||
class general_parsebuf : public parsebuf {
|
||||
public:
|
||||
streambuf *sbuf;
|
||||
int delete_buf; // Delete sbuf when destroying this.
|
||||
general_parsebuf(streambuf *buf, int delete_arg_buf = 0);
|
||||
int underflow();
|
||||
virtual int tell_in_line();
|
||||
virtual int seek_in_line(int i);
|
||||
~general_parsebuf();
|
||||
virtual char* current_line();
|
||||
};
|
||||
|
||||
#if 0
|
||||
class parsestream : public istream {
|
||||
streammarker marks[2];
|
||||
short _first; // of the two marks; either 0 or 1
|
||||
int _lineno;
|
||||
int first() { return _first; }
|
||||
int second() { return 1-_first; }
|
||||
int line_length() { marks[second].delta(marks[first]); }
|
||||
int line_length() { marks[second].delta(marks[first]); }
|
||||
int seek_in_line(int i);
|
||||
int tell_in_line();
|
||||
int line_number();
|
||||
};
|
||||
#endif
|
||||
#endif /*!defined(PARSESTREAM_H)*/
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
|
||||
Copyright (C) 1993 Free Software Foundation
|
||||
|
||||
This file is part of the GNU IO Library. This library 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, or (at your option)
|
||||
any later version.
|
||||
|
||||
This library 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 GNU CC; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
As a special exception, if you link this library with files
|
||||
compiled with a GNU compiler to produce an executable, this does not cause
|
||||
the resulting executable to be covered by the GNU General Public License.
|
||||
This exception does not however invalidate any other reasons why
|
||||
the executable file might be covered by the GNU General Public License. */
|
||||
|
||||
/* Written by Per Bothner (bothner@cygnus.com). */
|
||||
|
||||
#ifndef _PFSTREAM_H
|
||||
#define _PFSTREAM_H
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#include <fstream.h>
|
||||
|
||||
// ipfstream foo("NAME") is like: ifstream foo("NAME"). However,
|
||||
// if NAME starts *or ends* with a '|', the remainder of NAME is
|
||||
// evaluated as a shell command (using a procbuf), and all input
|
||||
// read from foo is whatever that shell writes to its standard output.
|
||||
// E.g. ipfstream foo("|zcat foo.Z") or ipfstream foo("zcat foo.Z|")
|
||||
// (These two forms are equivalent.)
|
||||
|
||||
class ipfstream : public ifstream {
|
||||
public:
|
||||
ipfstream(const char *name, int mode=ios::in, int prot=0664);
|
||||
};
|
||||
|
||||
// opfstream foo("NAME") is like: ofstream foo("NAME").
|
||||
// However, if NAME starts with a '|', the remainder of NAME is
|
||||
// evaluated as a shell command (using a procbuf), and all output
|
||||
// written to foo is piped to the standard input of that shell.
|
||||
// E.g. opfstream foo("|more");
|
||||
|
||||
class opfstream : public ofstream {
|
||||
public:
|
||||
opfstream(const char *name, int mode=ios::out, int prot=0664);
|
||||
};
|
||||
#endif /*!_PFSTREAM_H*/
|
||||
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
|
||||
Copyright (C) 1993 Free Software Foundation
|
||||
|
||||
This file is part of the GNU IO Library. This library 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, or (at your option)
|
||||
any later version.
|
||||
|
||||
This library 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 GNU CC; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
As a special exception, if you link this library with files
|
||||
compiled with a GNU compiler to produce an executable, this does not cause
|
||||
the resulting executable to be covered by the GNU General Public License.
|
||||
This exception does not however invalidate any other reasons why
|
||||
the executable file might be covered by the GNU General Public License. */
|
||||
|
||||
/* Written by Per Bothner (bothner@cygnus.com). */
|
||||
|
||||
#include <streambuf.h>
|
||||
|
||||
class procbuf : public filebuf {
|
||||
/* Following fields must match those in struct _IO_proc_file */
|
||||
_IO_pid_t _pid;
|
||||
public:
|
||||
procbuf() : filebuf() { }
|
||||
procbuf(const char *command, int mode);
|
||||
procbuf* open(const char *command, int mode);
|
||||
procbuf *close() { return (procbuf*)filebuf::close(); }
|
||||
virtual int sys_close();
|
||||
~procbuf();
|
||||
};
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,35 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988, 1992 Free Software Foundation
|
||||
written by Doug Lea (dl@rocky.oswego.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef _std_h
|
||||
#define _std_h 1
|
||||
|
||||
#include <_G_config.h>
|
||||
#include <defines.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
extern "C" {
|
||||
int strcasecmp _G_ARGS((const char*, const char*));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
|
||||
Copyright (C) 1993 Free Software Foundation
|
||||
|
||||
This file is part of the GNU IO Library. This library 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, or (at your option)
|
||||
any later version.
|
||||
|
||||
This library 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 GNU CC; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
As a special exception, if you link this library with files
|
||||
compiled with a GNU compiler to produce an executable, this does not cause
|
||||
the resulting executable to be covered by the GNU General Public License.
|
||||
This exception does not however invalidate any other reasons why
|
||||
the executable file might be covered by the GNU General Public License. */
|
||||
|
||||
/* Written by Per Bothner (bothner@cygnus.com). */
|
||||
|
||||
#ifndef _STDIOSTREAM_H
|
||||
#define _STDIOSTREAM_H
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include <iostream.h>
|
||||
#include <stdio.h>
|
||||
|
||||
class stdiobuf : public filebuf {
|
||||
protected:
|
||||
FILE *_file;
|
||||
public:
|
||||
FILE* stdiofile() const { return _file; }
|
||||
stdiobuf(FILE *);
|
||||
~stdiobuf();
|
||||
int buffered () const { return _flags & _IO_UNBUFFERED ? 0 : 1; }
|
||||
void buffered (int);
|
||||
virtual streamsize sys_read(char*, streamsize);
|
||||
virtual streampos sys_seek(streamoff, _seek_dir);
|
||||
virtual streamsize sys_write(const char*, streamsize);
|
||||
virtual int sys_close();
|
||||
virtual int sync();
|
||||
virtual int overflow(int c = EOF);
|
||||
streamsize xsputn(const char* s, streamsize n);
|
||||
};
|
||||
|
||||
class istdiostream : public istream
|
||||
{
|
||||
private:
|
||||
stdiobuf _file;
|
||||
public:
|
||||
istdiostream (FILE* __f) : _file(__f), istream() { init(&_file); }
|
||||
stdiobuf* rdbuf()/* const */ { return &_file; }
|
||||
int buffered () const { return _file.buffered (); }
|
||||
void buffered (int _i) { _file.buffered (_i); }
|
||||
};
|
||||
|
||||
class ostdiostream : public ostream
|
||||
{
|
||||
private:
|
||||
stdiobuf _file;
|
||||
public:
|
||||
ostdiostream (FILE* __f) : _file(__f), ostream() { init(&_file); }
|
||||
stdiobuf* rdbuf() /* const */ { return &_file; }
|
||||
int buffered () const { return _file.buffered (); }
|
||||
void buffered (int _i) { _file.buffered (_i); }
|
||||
};
|
||||
|
||||
#endif /* !_STDIOSTREAM_H */
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 1993 Free Software Foundation
|
||||
|
||||
This file is part of the GNU IO Library. This library 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, or (at your option)
|
||||
any later version.
|
||||
|
||||
This library 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 GNU CC; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
As a special exception, if you link this library with files
|
||||
compiled with a GNU compiler to produce an executable, this does not cause
|
||||
the resulting executable to be covered by the GNU General Public License.
|
||||
This exception does not however invalidate any other reasons why
|
||||
the executable file might be covered by the GNU General Public License. */
|
||||
|
||||
#ifndef _COMPAT_STREAM_H
|
||||
#define _COMPAT_STREAM_H
|
||||
|
||||
// Compatibility with old library.
|
||||
|
||||
#define _STREAM_COMPAT
|
||||
#include <iostream.h>
|
||||
|
||||
extern char* form(const char*, ...);
|
||||
|
||||
extern char* dec(long, int=0);
|
||||
extern char* dec(int, int=0);
|
||||
extern char* dec(unsigned long, int=0);
|
||||
extern char* dec(unsigned int, int=0);
|
||||
|
||||
extern char* hex(long, int=0);
|
||||
extern char* hex(int, int=0);
|
||||
extern char* hex(unsigned long, int=0);
|
||||
extern char* hex(unsigned int, int=0);
|
||||
|
||||
extern char* oct(long, int=0);
|
||||
extern char* oct(int, int=0);
|
||||
extern char* oct(unsigned long, int=0);
|
||||
extern char* oct(unsigned int, int=0);
|
||||
|
||||
char* chr(char ch, int width = 0);
|
||||
char* str(const char* s, int width = 0);
|
||||
|
||||
inline istream& WS(istream& str) { return ws(str); }
|
||||
|
||||
#endif /* !_COMPAT_STREAM_H */
|
||||
|
|
@ -1,454 +0,0 @@
|
|||
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
|
||||
Copyright (C) 1993 Free Software Foundation
|
||||
|
||||
This file is part of the GNU IO Library. This library 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, or (at your option)
|
||||
any later version.
|
||||
|
||||
This library 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 GNU CC; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
As a special exception, if you link this library with files
|
||||
compiled with a GNU compiler to produce an executable, this does not cause
|
||||
the resulting executable to be covered by the GNU General Public License.
|
||||
This exception does not however invalidate any other reasons why
|
||||
the executable file might be covered by the GNU General Public License. */
|
||||
|
||||
#ifndef _STREAMBUF_H
|
||||
#define _STREAMBUF_H
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
/* #define _G_IO_THROW */ /* Not implemented: ios::failure */
|
||||
|
||||
extern "C" {
|
||||
#include <libio.h>
|
||||
}
|
||||
//#include <_G_config.h>
|
||||
#ifdef _IO_NEED_STDARG_H
|
||||
#include <stdarg.h>
|
||||
#endif
|
||||
#ifndef _IO_va_list
|
||||
#define _IO_va_list char *
|
||||
#endif
|
||||
|
||||
#ifndef EOF
|
||||
#define EOF (-1)
|
||||
#endif
|
||||
#ifndef NULL
|
||||
#ifdef __GNUC__
|
||||
#define NULL ((void*)0)
|
||||
#else
|
||||
#define NULL (0)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _IO_wchar_t
|
||||
#define _IO_wchar_t short
|
||||
#endif
|
||||
|
||||
class istream; /* Work-around for a g++ name mangling bug. Fixed in 2.6. */
|
||||
class ostream; class streambuf;
|
||||
|
||||
// In case some header files defines these as macros.
|
||||
#undef open
|
||||
#undef close
|
||||
|
||||
extern "C" int __underflow(struct _IO_FILE*);
|
||||
extern "C" int __overflow(struct _IO_FILE*, int);
|
||||
|
||||
typedef _IO_off_t streamoff;
|
||||
typedef _IO_fpos_t streampos;
|
||||
typedef _IO_ssize_t streamsize;
|
||||
|
||||
typedef unsigned long __fmtflags;
|
||||
typedef unsigned char __iostate;
|
||||
|
||||
struct _ios_fields
|
||||
{ // The data members of an ios.
|
||||
// Directly using _strbuf is dangerous, because the vtable
|
||||
// pointer can be NULL. Use rdbuf() when in doubt.
|
||||
streambuf *_strbuf;
|
||||
ostream* _tie;
|
||||
int _width;
|
||||
__fmtflags _flags;
|
||||
_IO_wchar_t _fill;
|
||||
__iostate _state;
|
||||
__iostate _exceptions;
|
||||
int _precision;
|
||||
|
||||
void *_arrays; /* Support for ios::iword and ios::pword. */
|
||||
};
|
||||
|
||||
#define _IOS_GOOD 0
|
||||
#define _IOS_EOF 1
|
||||
#define _IOS_FAIL 2
|
||||
#define _IOS_BAD 4
|
||||
|
||||
#define _IO_INPUT 1
|
||||
#define _IO_OUTPUT 2
|
||||
#define _IO_ATEND 4
|
||||
#define _IO_APPEND 8
|
||||
#define _IO_TRUNC 16
|
||||
#define _IO_NOCREATE 32
|
||||
#define _IO_NOREPLACE 64
|
||||
#define _IO_BIN 128
|
||||
|
||||
#ifdef _STREAM_COMPAT
|
||||
enum state_value {
|
||||
_good = _IOS_GOOD,
|
||||
_eof = _IOS_EOF,
|
||||
_fail = _IOS_FAIL,
|
||||
_bad = _IOS_BAD };
|
||||
enum open_mode {
|
||||
input = _IO_INPUT,
|
||||
output = _IO_OUTPUT,
|
||||
atend = _IO_ATEND,
|
||||
append = _IO_APPEND };
|
||||
#endif
|
||||
|
||||
class ios : public _ios_fields {
|
||||
ios& operator=(ios&); /* Not allowed! */
|
||||
public:
|
||||
typedef __fmtflags fmtflags;
|
||||
typedef int iostate;
|
||||
typedef int openmode;
|
||||
typedef int streamsize;
|
||||
enum io_state {
|
||||
goodbit = _IOS_GOOD,
|
||||
eofbit = _IOS_EOF,
|
||||
failbit = _IOS_FAIL,
|
||||
badbit = _IOS_BAD };
|
||||
enum open_mode {
|
||||
in = _IO_INPUT,
|
||||
out = _IO_OUTPUT,
|
||||
ate = _IO_ATEND,
|
||||
app = _IO_APPEND,
|
||||
trunc = _IO_TRUNC,
|
||||
nocreate = _IO_NOCREATE,
|
||||
noreplace = _IO_NOREPLACE,
|
||||
bin = _IOS_BIN };
|
||||
enum seek_dir { beg, cur, end};
|
||||
// ANSI: typedef enum seek_dir seekdir; etc
|
||||
// NOTE: If adding flags here, before to update ios::bitalloc().
|
||||
enum { skipws=_IO_SKIPWS,
|
||||
left=_IO_LEFT, right=_IO_RIGHT, internal=_IO_INTERNAL,
|
||||
dec=_IO_DEC, oct=_IO_OCT, hex=_IO_HEX,
|
||||
showbase=_IO_SHOWBASE, showpoint=_IO_SHOWPOINT,
|
||||
uppercase=_IO_UPPERCASE, showpos=_IO_SHOWPOS,
|
||||
scientific=_IO_SCIENTIFIC, fixed=_IO_FIXED,
|
||||
unitbuf=_IO_UNITBUF, stdio=_IO_STDIO,
|
||||
dont_close=_IO_DONT_CLOSE // Don't delete streambuf on stream destruction
|
||||
};
|
||||
enum { // Masks.
|
||||
basefield=dec+oct+hex,
|
||||
floatfield = scientific+fixed,
|
||||
adjustfield = left+right+internal
|
||||
};
|
||||
|
||||
#ifdef _IO_THROW
|
||||
class failure : public xmsg {
|
||||
ios* _stream;
|
||||
public:
|
||||
failure(ios* stream) { _stream = stream; }
|
||||
failure(string cause, ios* stream) { _stream = stream; }
|
||||
ios* rdios() const { return _stream; }
|
||||
};
|
||||
#endif
|
||||
|
||||
ostream* tie() const { return _tie; }
|
||||
ostream* tie(ostream* val) { ostream* save=_tie; _tie=val; return save; }
|
||||
|
||||
// Methods to change the format state.
|
||||
_IO_wchar_t fill() const { return (_IO_wchar_t)_fill; }
|
||||
_IO_wchar_t fill(_IO_wchar_t newf)
|
||||
{_IO_wchar_t oldf = (_IO_wchar_t)_fill; _fill = (char)newf; return oldf;}
|
||||
fmtflags flags() const { return _flags; }
|
||||
fmtflags flags(fmtflags new_val) {
|
||||
fmtflags old_val = _flags; _flags = new_val; return old_val; }
|
||||
int precision() const { return _precision; }
|
||||
int precision(int newp) {
|
||||
unsigned short oldp = _precision; _precision = (unsigned short)newp;
|
||||
return oldp; }
|
||||
fmtflags setf(fmtflags val) {
|
||||
fmtflags oldbits = _flags;
|
||||
_flags |= val; return oldbits; }
|
||||
fmtflags setf(fmtflags val, fmtflags mask) {
|
||||
fmtflags oldbits = _flags;
|
||||
_flags = (_flags & ~mask) | (val & mask); return oldbits; }
|
||||
fmtflags unsetf(fmtflags mask) {
|
||||
fmtflags oldbits = _flags;
|
||||
_flags &= ~mask; return oldbits; }
|
||||
int width() const { return _width; }
|
||||
int width(int val) { int save = _width; _width = val; return save; }
|
||||
|
||||
#ifdef _IO_THROW
|
||||
void _throw_failure() const { throw new ios::failure(this); }
|
||||
#else
|
||||
void _throw_failure() const { }
|
||||
#endif
|
||||
streambuf* rdbuf() const { return _strbuf; }
|
||||
#ifdef _STREAM_COMPAT
|
||||
void _IO_fix_vtable(); /* TEMPORARY - for binary compatibility */
|
||||
void _IO_fix_vtable() const; /* TEMPORARY - for binary compatibility */
|
||||
#endif
|
||||
streambuf* rdbuf(streambuf *_s) {
|
||||
streambuf *_old = _strbuf; _strbuf = _s; clear (); return _old; }
|
||||
void clear(iostate state = 0) {
|
||||
_state = _strbuf ? state : state|badbit;
|
||||
if (_state & _exceptions) _throw_failure(); }
|
||||
void set(iostate flag) { _state |= flag;
|
||||
if (_state & _exceptions) _throw_failure(); }
|
||||
void setstate(iostate flag) { _state |= flag; // ANSI
|
||||
if (_state & _exceptions) _throw_failure(); }
|
||||
int good() const { return _state == 0; }
|
||||
int eof() const { return _state & ios::eofbit; }
|
||||
int fail() const { return _state & (ios::badbit|ios::failbit); }
|
||||
int bad() const { return _state & ios::badbit; }
|
||||
iostate rdstate() const { return _state; }
|
||||
operator void*() const { return fail() ? (void*)0 : (void*)(-1); }
|
||||
int operator!() const { return fail(); }
|
||||
iostate exceptions() const { return _exceptions; }
|
||||
void exceptions(iostate enable) {
|
||||
_exceptions = enable;
|
||||
if (_state & _exceptions) _throw_failure(); }
|
||||
|
||||
static int sync_with_stdio(int on);
|
||||
static void sync_with_stdio() { sync_with_stdio(1); }
|
||||
static fmtflags bitalloc();
|
||||
static int xalloc();
|
||||
void*& pword(int);
|
||||
void* pword(int) const;
|
||||
long& iword(int);
|
||||
long iword(int) const;
|
||||
|
||||
#ifdef _STREAM_COMPAT
|
||||
void unset(state_value flag) { _state &= ~flag; }
|
||||
void close();
|
||||
int is_open();
|
||||
int readable();
|
||||
int writable();
|
||||
#endif
|
||||
|
||||
// Used to initialize standard streams. Not needed in this implementation.
|
||||
class Init {
|
||||
public:
|
||||
Init () { }
|
||||
};
|
||||
|
||||
protected:
|
||||
ios(streambuf* sb = 0, ostream* tie_to = 0) { init(sb, tie_to); }
|
||||
virtual ~ios();
|
||||
void init(streambuf* sb, ostream* tie = 0);
|
||||
};
|
||||
|
||||
#if __GNUG__==1
|
||||
typedef int _seek_dir;
|
||||
#else
|
||||
typedef ios::seek_dir _seek_dir;
|
||||
#endif
|
||||
|
||||
// Magic numbers and bits for the _flags field.
|
||||
// The magic numbers use the high-order bits of _flags;
|
||||
// the remaining bits are abailable for variable flags.
|
||||
// Note: The magic numbers must all be negative if stdio
|
||||
// emulation is desired.
|
||||
|
||||
// A streammarker remembers a position in a buffer.
|
||||
// You are guaranteed to be able to seek back to it if it is saving().
|
||||
class streammarker : private _IO_marker {
|
||||
friend class streambuf;
|
||||
void set_offset(int offset) { _pos = offset; }
|
||||
public:
|
||||
streammarker(streambuf *sb);
|
||||
~streammarker();
|
||||
int saving() { return 1; }
|
||||
int delta(streammarker&);
|
||||
int delta();
|
||||
};
|
||||
|
||||
extern unsigned __adjust_column(unsigned start, const char *line, int count);
|
||||
|
||||
struct streambuf : public _IO_FILE { // protected??
|
||||
friend class ios;
|
||||
friend class istream;
|
||||
friend class ostream;
|
||||
friend class streammarker;
|
||||
const void *&_vtable() { return *(const void**)((_IO_FILE*)this + 1); }
|
||||
protected:
|
||||
static streambuf* _list_all; /* List of open streambufs. */
|
||||
_IO_FILE*& xchain() { return _chain; }
|
||||
void _un_link();
|
||||
void _link_in();
|
||||
char* gptr() const
|
||||
{ return _IO_file_flags & _IO_IN_BACKUP ? _IO_save_base : _IO_read_ptr; }
|
||||
char* pptr() const { return _IO_write_ptr; }
|
||||
char* egptr() const
|
||||
{ return _IO_file_flags & _IO_IN_BACKUP ? _IO_save_end : _IO_read_end; }
|
||||
char* epptr() const { return _IO_write_end; }
|
||||
char* pbase() const { return _IO_write_base; }
|
||||
char* eback() const
|
||||
{ return _IO_file_flags & _IO_IN_BACKUP ? _IO_save_base : _IO_read_base;}
|
||||
char* base() const { return _IO_buf_base; }
|
||||
char* ebuf() const { return _IO_buf_end; }
|
||||
int blen() const { return _IO_buf_end - _IO_buf_base; }
|
||||
void xput_char(char c) { *_IO_write_ptr++ = c; }
|
||||
int xflags() { return _IO_file_flags; }
|
||||
int xflags(int f) {int fl = _IO_file_flags; _IO_file_flags = f; return fl;}
|
||||
void xsetflags(int f) { _IO_file_flags |= f; }
|
||||
void xsetflags(int f, int mask)
|
||||
{ _IO_file_flags = (_IO_file_flags & ~mask) | (f & mask); }
|
||||
void gbump(int n)
|
||||
{ _IO_file_flags & _IO_IN_BACKUP ? (_IO_save_base+=n):(_IO_read_ptr+=n);}
|
||||
void pbump(int n) { _IO_write_ptr += n; }
|
||||
void setb(char* b, char* eb, int a=0);
|
||||
void setp(char* p, char* ep)
|
||||
{ _IO_write_base=_IO_write_ptr=p; _IO_write_end=ep; }
|
||||
void setg(char* eb, char* g, char *eg) {
|
||||
if (_IO_file_flags & _IO_IN_BACKUP) _IO_free_backup_area(this);
|
||||
_IO_read_base = eb; _IO_read_ptr = g; _IO_read_end = eg; }
|
||||
char *shortbuf() { return _shortbuf; }
|
||||
|
||||
int in_backup() { return _flags & _IO_IN_BACKUP; }
|
||||
// The start of the main get area: FIXME: wrong for write-mode filebuf?
|
||||
char *Gbase() { return in_backup() ? _IO_save_base : _IO_read_base; }
|
||||
// The end of the main get area:
|
||||
char *eGptr() { return in_backup() ? _IO_save_end : _IO_read_end; }
|
||||
// The start of the backup area:
|
||||
char *Bbase() { return in_backup() ? _IO_read_base : _IO_save_base; }
|
||||
char *Bptr() { return _IO_backup_base; }
|
||||
// The end of the backup area:
|
||||
char *eBptr() { return in_backup() ? _IO_read_end : _IO_save_end; }
|
||||
char *Nbase() { return _IO_save_base; }
|
||||
char *eNptr() { return _IO_save_end; }
|
||||
int have_backup() { return _IO_save_base != NULL; }
|
||||
int have_markers() { return _markers != NULL; }
|
||||
void free_backup_area();
|
||||
void unsave_markers(); // Make all streammarkers !saving().
|
||||
int put_mode() { return _flags & _IO_CURRENTLY_PUTTING; }
|
||||
int switch_to_get_mode();
|
||||
|
||||
streambuf(int flags=0);
|
||||
public:
|
||||
static int flush_all();
|
||||
static void flush_all_linebuffered(); // Flush all line buffered files.
|
||||
virtual int underflow(); // Leave public for now
|
||||
virtual int overflow(int c = EOF); // Leave public for now
|
||||
virtual int doallocate();
|
||||
streampos sseekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
|
||||
streampos sseekpos(streampos pos, int mode = ios::in|ios::out);
|
||||
|
||||
virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
|
||||
virtual streampos seekpos(streampos pos, int mode = ios::in|ios::out);
|
||||
int seekmark(streammarker& mark, int delta = 0);
|
||||
int sputbackc(char c);
|
||||
int sungetc();
|
||||
virtual ~streambuf();
|
||||
int unbuffered() { return _flags & _IO_UNBUFFERED ? 1 : 0; }
|
||||
int linebuffered() { return _flags & _IO_LINE_BUF ? 1 : 0; }
|
||||
void unbuffered(int i)
|
||||
{ if (i) _flags |= _IO_UNBUFFERED; else _flags &= ~_IO_UNBUFFERED; }
|
||||
void linebuffered(int i)
|
||||
{ if (i) _flags |= _IO_LINE_BUF; else _flags &= ~_IO_LINE_BUF; }
|
||||
int allocate() { // For AT&T compatibility
|
||||
if (base() || unbuffered()) return 0;
|
||||
else return doallocate(); }
|
||||
// Allocate a buffer if needed; use _shortbuf if appropriate.
|
||||
void allocbuf() { if (base() == NULL) doallocbuf(); }
|
||||
void doallocbuf();
|
||||
virtual int sync();
|
||||
virtual int pbackfail(int c);
|
||||
virtual streambuf* setbuf(char* p, int len);
|
||||
int in_avail() { return _IO_read_end - _IO_read_ptr; }
|
||||
int out_waiting() { return _IO_write_ptr - _IO_write_base; }
|
||||
virtual streamsize xsputn(const char* s, streamsize n);
|
||||
streamsize sputn(const char* s, streamsize n) { return xsputn(s, n); }
|
||||
streamsize padn(char pad, streamsize n) { return _IO_padn(this, pad, n); }
|
||||
virtual streamsize xsgetn(char* s, streamsize n);
|
||||
streamsize sgetn(char* s, streamsize n) { return _IO_sgetn(this, s, n); }
|
||||
int ignore(int);
|
||||
virtual int get_column();
|
||||
virtual int set_column(int);
|
||||
long sgetline(char* buf, _IO_size_t n, char delim, int putback_delim);
|
||||
int sputc(int c) { return _IO_putc(c, this); }
|
||||
int sbumpc() { return _IO_getc(this); }
|
||||
int sgetc() { return _IO_peekc(this); }
|
||||
int snextc() {
|
||||
if (_IO_read_ptr >= _IO_read_end && __underflow(this) == EOF)
|
||||
return EOF;
|
||||
else return _IO_read_ptr++, sgetc(); }
|
||||
void stossc() { if (_IO_read_ptr < _IO_read_end) _IO_read_ptr++; }
|
||||
int vscan(char const *fmt0, _IO_va_list ap, ios* stream = NULL);
|
||||
int scan(char const *fmt0 ...);
|
||||
int vform(char const *fmt0, _IO_va_list ap);
|
||||
int form(char const *fmt0 ...);
|
||||
#if 0 /* Work in progress */
|
||||
int column(); // Current column number (of put pointer). -1 is unknown.
|
||||
void column(int c); // Set column number of put pointer to c.
|
||||
#endif
|
||||
virtual streamsize sys_read(char* buf, streamsize size);
|
||||
virtual streampos sys_seek(streamoff, _seek_dir);
|
||||
virtual streamsize sys_write(const char*, streamsize);
|
||||
virtual int sys_stat(void*); // Actually, a (struct stat*)
|
||||
virtual int sys_close();
|
||||
};
|
||||
|
||||
// A backupbuf is a streambuf with full backup and savepoints on reading.
|
||||
// All standard streambufs in the GNU iostream library are backupbufs.
|
||||
|
||||
class filebuf : public streambuf {
|
||||
protected:
|
||||
void init();
|
||||
public:
|
||||
static const int openprot; // Non-ANSI AT&T-ism: Default open protection.
|
||||
filebuf();
|
||||
filebuf(int fd);
|
||||
filebuf(int fd, char* p, int len);
|
||||
static filebuf *__new();
|
||||
~filebuf();
|
||||
filebuf* attach(int fd);
|
||||
filebuf* open(const char *filename, const char *mode);
|
||||
filebuf* open(const char *filename, ios::openmode mode, int prot = 0664);
|
||||
virtual int underflow();
|
||||
virtual int overflow(int c = EOF);
|
||||
int is_open() const { return _fileno >= 0; }
|
||||
int fd() const { return is_open() ? _fileno : EOF; }
|
||||
filebuf* close();
|
||||
virtual int doallocate();
|
||||
virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
|
||||
virtual streambuf* setbuf(char* p, int len);
|
||||
streamsize xsputn(const char* s, streamsize n);
|
||||
streamsize xsgetn(char* s, streamsize n);
|
||||
virtual int sync();
|
||||
protected: // See documentation in filebuf.C.
|
||||
// virtual int pbackfail(int c);
|
||||
int is_reading() { return eback() != egptr(); }
|
||||
char* cur_ptr() { return is_reading() ? gptr() : pptr(); }
|
||||
/* System's idea of pointer */
|
||||
char* file_ptr() { return eGptr(); }
|
||||
int do_write(const char *data, int to_do);
|
||||
// Low-level operations (Usually invoke system calls.)
|
||||
virtual streamsize sys_read(char* buf, streamsize size);
|
||||
virtual streampos sys_seek(streamoff, _seek_dir);
|
||||
virtual streamsize sys_write(const char*, streamsize);
|
||||
virtual int sys_stat(void*); // Actually, a (struct stat*)
|
||||
virtual int sys_close();
|
||||
};
|
||||
|
||||
inline void ios::init(streambuf* sb, ostream* tie_to) {
|
||||
_state = sb ? ios::goodbit : ios::badbit; _exceptions=0;
|
||||
_strbuf=sb; _tie = tie_to; _width=0; _fill=' ';
|
||||
_flags=ios::skipws|ios::dec; _precision=6; _arrays = 0; }
|
||||
|
||||
inline ios::~ios() {
|
||||
if (!(_flags & (unsigned int)ios::dont_close)) delete rdbuf(); }
|
||||
#endif /* _STREAMBUF_H */
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 1993 Free Software Foundation
|
||||
|
||||
This file is part of the GNU IO Library. This library 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, or (at your option)
|
||||
any later version.
|
||||
|
||||
This library 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 GNU CC; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
As a special exception, if you link this library with files
|
||||
compiled with a GNU compiler to produce an executable, this does not cause
|
||||
the resulting executable to be covered by the GNU General Public License.
|
||||
This exception does not however invalidate any other reasons why
|
||||
the executable file might be covered by the GNU General Public License. */
|
||||
|
||||
#include <libio.h>
|
||||
#ifdef TODO
|
||||
Merge into libio.h ?
|
||||
#endif
|
||||
|
||||
typedef void *(*_IO_alloc_type) __P((_IO_size_t));
|
||||
typedef void (*_IO_free_type) __P((void*));
|
||||
|
||||
struct _IO_str_fields
|
||||
{
|
||||
/* The current length is max(_len, _IO_write_ptr-_IO_write_base). */
|
||||
_IO_size_t _len;
|
||||
_IO_alloc_type _allocate_buffer;
|
||||
_IO_free_type _free_buffer;
|
||||
};
|
||||
|
||||
typedef struct _IO_strfile_
|
||||
{
|
||||
struct _IO_FILE _f;
|
||||
const void *_vtable;
|
||||
struct _IO_str_fields _s;
|
||||
} _IO_strfile;
|
||||
|
|
@ -1,109 +0,0 @@
|
|||
/* This is part of libio/iostream, providing -*- C++ -*- input/output.
|
||||
Copyright (C) 1993 Free Software Foundation
|
||||
|
||||
This file is part of the GNU IO Library. This library 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, or (at your option)
|
||||
any later version.
|
||||
|
||||
This library 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 GNU CC; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
As a special exception, if you link this library with files
|
||||
compiled with a GNU compiler to produce an executable, this does not cause
|
||||
the resulting executable to be covered by the GNU General Public License.
|
||||
This exception does not however invalidate any other reasons why
|
||||
the executable file might be covered by the GNU General Public License. */
|
||||
|
||||
/* Written by Per Bothner (bothner@cygnus.com). */
|
||||
|
||||
#ifndef __STRSTREAM_H
|
||||
#define __STRSTREAM_H
|
||||
#ifdef __GNUG__
|
||||
#pragma interface
|
||||
#endif
|
||||
#include <iostream.h>
|
||||
#include <strfile.h>
|
||||
|
||||
class strstreambuf : public streambuf
|
||||
{
|
||||
struct _IO_str_fields _s;
|
||||
|
||||
void init_dynamic(_IO_alloc_type alloc, _IO_free_type free,
|
||||
int initial_size = 128);
|
||||
void init_static(char *ptr, int size, char *pstart);
|
||||
void init_readonly(const char *ptr, int size);
|
||||
protected:
|
||||
int is_static() const { return _s._allocate_buffer == (_IO_alloc_type)0; }
|
||||
virtual int overflow(int = EOF);
|
||||
virtual int underflow();
|
||||
virtual int pbackfail(int c);
|
||||
public:
|
||||
virtual ~strstreambuf();
|
||||
strstreambuf() { init_dynamic(0, 0); }
|
||||
strstreambuf(int initial_size) { init_dynamic(0, 0, initial_size); }
|
||||
strstreambuf(void *(*alloc)(_IO_size_t), void (*free)(void*))
|
||||
{ init_dynamic(alloc, free); }
|
||||
strstreambuf(char *ptr, int size, char *pstart = NULL)
|
||||
{ init_static(ptr, size, pstart); }
|
||||
strstreambuf(unsigned char *ptr, int size, unsigned char *pstart = NULL)
|
||||
{ init_static((char*)ptr, size, (char*)pstart); }
|
||||
strstreambuf(const char *ptr, int size)
|
||||
{ init_readonly(ptr, size); }
|
||||
strstreambuf(const unsigned char *ptr, int size)
|
||||
{ init_readonly((const char*)ptr, size); }
|
||||
strstreambuf(signed char *ptr, int size, signed char *pstart = NULL)
|
||||
{ init_static((char*)ptr, size, (char*)pstart); }
|
||||
strstreambuf(const signed char *ptr, int size)
|
||||
{ init_readonly((const char*)ptr, size); }
|
||||
// Note: frozen() is always true if is_static().
|
||||
int frozen() { return _flags & _IO_USER_BUF ? 1 : 0; }
|
||||
void freeze(int n=1)
|
||||
{ if (!is_static())
|
||||
{ if (n) _flags |= _IO_USER_BUF; else _flags &= ~_IO_USER_BUF; } }
|
||||
_IO_ssize_t pcount();
|
||||
char *str();
|
||||
virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
|
||||
};
|
||||
|
||||
class strstreambase : virtual public ios {
|
||||
public:
|
||||
strstreambuf* rdbuf() { return (strstreambuf*)ios::rdbuf(); }
|
||||
protected:
|
||||
strstreambase() { }
|
||||
strstreambase(char *cp, int n, int mode=ios::out);
|
||||
};
|
||||
|
||||
class istrstream : public strstreambase, public istream {
|
||||
public:
|
||||
istrstream(const char*, int=0);
|
||||
};
|
||||
|
||||
class ostrstream : public strstreambase, public ostream {
|
||||
public:
|
||||
ostrstream();
|
||||
ostrstream(char *cp, int n, int mode=ios::out) :strstreambase(cp,n,mode){}
|
||||
_IO_ssize_t pcount() { return ((strstreambuf*)_strbuf)->pcount(); }
|
||||
char *str() { return ((strstreambuf*)_strbuf)->str(); }
|
||||
void freeze(int n = 1) { ((strstreambuf*)_strbuf)->freeze(n); }
|
||||
int frozen() { return ((strstreambuf*)_strbuf)->frozen(); }
|
||||
};
|
||||
|
||||
class strstream : public strstreambase, public iostream {
|
||||
public:
|
||||
strstream() : strstreambase() { init(new strstreambuf()); }
|
||||
strstream(char *cp, int n, int mode=ios::out) :strstreambase(cp,n,mode){}
|
||||
_IO_ssize_t pcount() { return ((strstreambuf*)_strbuf)->pcount(); }
|
||||
char *str() { return ((strstreambuf*)_strbuf)->str(); }
|
||||
void freeze(int n = 1) { ((strstreambuf*)_strbuf)->freeze(n); }
|
||||
int frozen() { return ((strstreambuf*)_strbuf)->frozen(); }
|
||||
};
|
||||
|
||||
#endif /*!__STRSTREAM_H*/
|
||||
|
|
@ -1,292 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1989 Free Software Foundation
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include <ACG.h>
|
||||
#include <assert.h>
|
||||
|
||||
//
|
||||
// This is an extension of the older implementation of Algorithm M
|
||||
// which I previously supplied. The main difference between this
|
||||
// version and the old code are:
|
||||
//
|
||||
// + Andres searched high & low for good constants for
|
||||
// the LCG.
|
||||
//
|
||||
// + theres more bit chopping going on.
|
||||
//
|
||||
// The following contains his comments.
|
||||
//
|
||||
// agn@UNH.CS.CMU.EDU sez..
|
||||
//
|
||||
// The generator below is based on 2 well known
|
||||
// methods: Linear Congruential (LCGs) and Additive
|
||||
// Congruential generators (ACGs).
|
||||
//
|
||||
// The LCG produces the longest possible sequence
|
||||
// of 32 bit random numbers, each being unique in
|
||||
// that sequence (it has only 32 bits of state).
|
||||
// It suffers from 2 problems: a) Independence
|
||||
// isnt great, that is the (n+1)th number is
|
||||
// somewhat related to the preceding one, unlike
|
||||
// flipping a coin where knowing the past outcomes
|
||||
// dont help to predict the next result. b)
|
||||
// Taking parts of a LCG generated number can be
|
||||
// quite non-random: for example, looking at only
|
||||
// the least significant byte gives a permuted
|
||||
// 8-bit counter (that has a period length of only
|
||||
// 256). The advantage of an LCA is that it is
|
||||
// perfectly uniform when run for the entire period
|
||||
// length (and very uniform for smaller sequences
|
||||
// too, if the parameters are chosen carefully).
|
||||
//
|
||||
// ACGs have extremly long period lengths and
|
||||
// provide good independence. Unfortunately,
|
||||
// uniformity isnt not too great. Furthermore, I
|
||||
// didnt find any theoretically analysis of ACGs
|
||||
// that addresses uniformity.
|
||||
//
|
||||
// The RNG given below will return numbers
|
||||
// generated by an LCA that are permuted under
|
||||
// control of a ACG. 2 permutations take place: the
|
||||
// 4 bytes of one LCG generated number are
|
||||
// subjected to one of 16 permutations selected by
|
||||
// 4 bits of the ACG. The permutation a such that
|
||||
// byte of the result may come from each byte of
|
||||
// the LCG number. This effectively destroys the
|
||||
// structure within a word. Finally, the sequence
|
||||
// of such numbers is permuted within a range of
|
||||
// 256 numbers. This greatly improves independence.
|
||||
//
|
||||
//
|
||||
// Algorithm M as describes in Knuths "Art of Computer Programming",
|
||||
// Vol 2. 1969
|
||||
// is used with a linear congruential generator (to get a good uniform
|
||||
// distribution) that is permuted with a Fibonacci additive congruential
|
||||
// generator to get good independence.
|
||||
//
|
||||
// Bit, byte, and word distributions were extensively tested and pass
|
||||
// Chi-squared test near perfect scores (>7E8 numbers tested, Uniformity
|
||||
// assumption holds with probability > 0.999)
|
||||
//
|
||||
// Run-up tests for on 7E8 numbers confirm independence with
|
||||
// probability > 0.97.
|
||||
//
|
||||
// Plotting random points in 2d reveals no apparent structure.
|
||||
//
|
||||
// Autocorrelation on sequences of 5E5 numbers (A(i) = SUM X(n)*X(n-i),
|
||||
// i=1..512)
|
||||
// results in no obvious structure (A(i) ~ const).
|
||||
//
|
||||
// Except for speed and memory requirements, this generator outperforms
|
||||
// random() for all tests. (random() scored rather low on uniformity tests,
|
||||
// while independence test differences were less dramatic).
|
||||
//
|
||||
// AGN would like to..
|
||||
// thanks to M.Mauldin, H.Walker, J.Saxe and M.Molloy for inspiration & help.
|
||||
//
|
||||
// And I would (DGC) would like to thank Donald Kunth for AGN for letting me
|
||||
// use his extensions in this implementation.
|
||||
//
|
||||
|
||||
//
|
||||
// Part of the table on page 28 of Knuth, vol II. This allows us
|
||||
// to adjust the size of the table at the expense of shorter sequences.
|
||||
//
|
||||
|
||||
static randomStateTable[][3] = {
|
||||
{3,7,16}, {4,9, 32}, {3,10, 32}, {1,11, 32}, {1,15,64}, {3,17,128},
|
||||
{7,18,128}, {3,20,128}, {2,21, 128}, {1,22, 128}, {5,23, 128}, {3,25, 128},
|
||||
{2,29, 128}, {3,31, 128}, {13,33, 256}, {2,35, 256}, {11,36, 256},
|
||||
{14,39,256}, {3,41,256}, {9,49,256}, {3,52,256}, {24,55,256}, {7,57, 256},
|
||||
{19,58,256}, {38,89,512}, {17,95,512}, {6,97,512}, {11,98,512}, {-1,-1,-1} };
|
||||
|
||||
//
|
||||
// spatial permutation table
|
||||
// RANDOM_PERM_SIZE must be a power of two
|
||||
//
|
||||
|
||||
#define RANDOM_PERM_SIZE 64
|
||||
_G_uint32_t randomPermutations[RANDOM_PERM_SIZE] = {
|
||||
0xffffffff, 0x00000000, 0x00000000, 0x00000000, // 3210
|
||||
0x0000ffff, 0x00ff0000, 0x00000000, 0xff000000, // 2310
|
||||
0xff0000ff, 0x0000ff00, 0x00000000, 0x00ff0000, // 3120
|
||||
0x00ff00ff, 0x00000000, 0xff00ff00, 0x00000000, // 1230
|
||||
|
||||
0xffff0000, 0x000000ff, 0x00000000, 0x0000ff00, // 3201
|
||||
0x00000000, 0x00ff00ff, 0x00000000, 0xff00ff00, // 2301
|
||||
0xff000000, 0x00000000, 0x000000ff, 0x00ffff00, // 3102
|
||||
0x00000000, 0x00000000, 0x00000000, 0xffffffff, // 2103
|
||||
|
||||
0xff00ff00, 0x00000000, 0x00ff00ff, 0x00000000, // 3012
|
||||
0x0000ff00, 0x00000000, 0x00ff0000, 0xff0000ff, // 2013
|
||||
0x00000000, 0x00000000, 0xffffffff, 0x00000000, // 1032
|
||||
0x00000000, 0x0000ff00, 0xffff0000, 0x000000ff, // 1023
|
||||
|
||||
0x00000000, 0xffffffff, 0x00000000, 0x00000000, // 0321
|
||||
0x00ffff00, 0xff000000, 0x00000000, 0x000000ff, // 0213
|
||||
0x00000000, 0xff000000, 0x0000ffff, 0x00ff0000, // 0132
|
||||
0x00000000, 0xff00ff00, 0x00000000, 0x00ff00ff // 0123
|
||||
};
|
||||
|
||||
//
|
||||
// SEED_TABLE_SIZE must be a power of 2
|
||||
//
|
||||
#define SEED_TABLE_SIZE 32
|
||||
static _G_uint32_t seedTable[SEED_TABLE_SIZE] = {
|
||||
0xbdcc47e5, 0x54aea45d, 0xec0df859, 0xda84637b,
|
||||
0xc8c6cb4f, 0x35574b01, 0x28260b7d, 0x0d07fdbf,
|
||||
0x9faaeeb0, 0x613dd169, 0x5ce2d818, 0x85b9e706,
|
||||
0xab2469db, 0xda02b0dc, 0x45c60d6e, 0xffe49d10,
|
||||
0x7224fea3, 0xf9684fc9, 0xfc7ee074, 0x326ce92a,
|
||||
0x366d13b5, 0x17aaa731, 0xeb83a675, 0x7781cb32,
|
||||
0x4ec7c92d, 0x7f187521, 0x2cf346b4, 0xad13310f,
|
||||
0xb89cff2b, 0x12164de1, 0xa865168d, 0x32b56cdf
|
||||
};
|
||||
|
||||
//
|
||||
// The LCG used to scramble the ACG
|
||||
//
|
||||
//
|
||||
// LC-parameter selection follows recommendations in
|
||||
// "Handbook of Mathematical Functions" by Abramowitz & Stegun 10th, edi.
|
||||
//
|
||||
// LC_A = 251^2, ~= sqrt(2^32) = 66049
|
||||
// LC_C = result of a long trial & error series = 3907864577
|
||||
//
|
||||
|
||||
static const _G_uint32_t LC_A = 66049;
|
||||
static const _G_uint32_t LC_C = 3907864577;
|
||||
static inline _G_uint32_t LCG(_G_uint32_t x)
|
||||
{
|
||||
return( x * LC_A + LC_C );
|
||||
}
|
||||
|
||||
|
||||
ACG::ACG(_G_uint32_t seed, int size)
|
||||
{
|
||||
|
||||
initialSeed = seed;
|
||||
|
||||
//
|
||||
// Determine the size of the state table
|
||||
//
|
||||
|
||||
for (register int l = 0;
|
||||
randomStateTable[l][0] != -1 && randomStateTable[l][1] < size;
|
||||
l++);
|
||||
|
||||
if (randomStateTable[l][1] == -1) {
|
||||
l--;
|
||||
}
|
||||
|
||||
initialTableEntry = l;
|
||||
|
||||
stateSize = randomStateTable[ initialTableEntry ][ 1 ];
|
||||
auxSize = randomStateTable[ initialTableEntry ][ 2 ];
|
||||
|
||||
//
|
||||
// Allocate the state table & the auxillary table in a single malloc
|
||||
//
|
||||
|
||||
state = new _G_uint32_t[stateSize + auxSize];
|
||||
auxState = &state[stateSize];
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize the state
|
||||
//
|
||||
void
|
||||
ACG::reset()
|
||||
{
|
||||
register _G_uint32_t u;
|
||||
|
||||
if (initialSeed < SEED_TABLE_SIZE) {
|
||||
u = seedTable[ initialSeed ];
|
||||
} else {
|
||||
u = initialSeed ^ seedTable[ initialSeed & (SEED_TABLE_SIZE-1) ];
|
||||
}
|
||||
|
||||
|
||||
j = randomStateTable[ initialTableEntry ][ 0 ] - 1;
|
||||
k = randomStateTable[ initialTableEntry ][ 1 ] - 1;
|
||||
|
||||
register int i;
|
||||
for(i = 0; i < stateSize; i++) {
|
||||
state[i] = u = LCG(u);
|
||||
}
|
||||
|
||||
for (i = 0; i < auxSize; i++) {
|
||||
auxState[i] = u = LCG(u);
|
||||
}
|
||||
|
||||
k = u % stateSize;
|
||||
int tailBehind = (stateSize - randomStateTable[ initialTableEntry ][ 0 ]);
|
||||
j = k - tailBehind;
|
||||
if (j < 0) {
|
||||
j += stateSize;
|
||||
}
|
||||
|
||||
lcgRecurr = u;
|
||||
|
||||
assert(sizeof(double) == 2 * sizeof(_G_int32_t));
|
||||
}
|
||||
|
||||
ACG::~ACG()
|
||||
{
|
||||
if (state) delete state;
|
||||
state = 0;
|
||||
// don't delete auxState, it's really an alias for state.
|
||||
}
|
||||
|
||||
//
|
||||
// Returns 32 bits of random information.
|
||||
//
|
||||
|
||||
_G_uint32_t
|
||||
ACG::asLong()
|
||||
{
|
||||
_G_uint32_t result = state[k] + state[j];
|
||||
state[k] = result;
|
||||
j = (j <= 0) ? (stateSize-1) : (j-1);
|
||||
k = (k <= 0) ? (stateSize-1) : (k-1);
|
||||
|
||||
short int auxIndex = (result >> 24) & (auxSize - 1);
|
||||
register _G_uint32_t auxACG = auxState[auxIndex];
|
||||
auxState[auxIndex] = lcgRecurr = LCG(lcgRecurr);
|
||||
|
||||
//
|
||||
// 3c is a magic number. We are doing four masks here, so we
|
||||
// do not want to run off the end of the permutation table.
|
||||
// This insures that we have always got four entries left.
|
||||
//
|
||||
register _G_uint32_t *perm = & randomPermutations[result & 0x3c];
|
||||
|
||||
result = *(perm++) & auxACG;
|
||||
result |= *(perm++) & ((auxACG << 24)
|
||||
| ((auxACG >> 8)& 0xffffff));
|
||||
result |= *(perm++) & ((auxACG << 16)
|
||||
| ((auxACG >> 16) & 0xffff));
|
||||
result |= *(perm++) & ((auxACG << 8)
|
||||
| ((auxACG >> 24) & 0xff));
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
|
@ -1,110 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1989 Free Software Foundation
|
||||
written by Doug Lea (dl@rocky.oswego.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include <std.h>
|
||||
#include <AllocRing.h>
|
||||
#include <new.h>
|
||||
|
||||
AllocRing::AllocRing(int max)
|
||||
:n(max), current(0), nodes(new AllocQNode[max])
|
||||
{
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
nodes[i].ptr = 0;
|
||||
nodes[i].sz = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int AllocRing::find(void* p)
|
||||
{
|
||||
if (p == 0) return -1;
|
||||
|
||||
for (int i = 0; i < n; ++i)
|
||||
if (nodes[i].ptr == p)
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
void AllocRing::clear()
|
||||
{
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
if (nodes[i].ptr != 0)
|
||||
{
|
||||
delete(nodes[i].ptr);
|
||||
nodes[i].ptr = 0;
|
||||
}
|
||||
nodes[i].sz = 0;
|
||||
}
|
||||
current = 0;
|
||||
}
|
||||
|
||||
|
||||
void AllocRing::free(void* p)
|
||||
{
|
||||
int idx = find(p);
|
||||
if (idx >= 0)
|
||||
{
|
||||
delete nodes[idx].ptr;
|
||||
nodes[idx].ptr = 0;
|
||||
}
|
||||
}
|
||||
|
||||
AllocRing::~AllocRing()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
int AllocRing::contains(void* p)
|
||||
{
|
||||
return find(p) >= 0;
|
||||
}
|
||||
|
||||
static inline unsigned int good_size(unsigned int s)
|
||||
{
|
||||
unsigned int req = s + 4;
|
||||
unsigned int good = 8;
|
||||
while (good < req) good <<= 1;
|
||||
return good - 4;
|
||||
}
|
||||
|
||||
void* AllocRing::alloc(int s)
|
||||
{
|
||||
unsigned int size = good_size(s);
|
||||
|
||||
void* p;
|
||||
if (nodes[current].ptr != 0 &&
|
||||
nodes[current].sz >= int(size) &&
|
||||
nodes[current].sz < int(4 * size))
|
||||
p = nodes[current].ptr;
|
||||
else
|
||||
{
|
||||
if (nodes[current].ptr != 0) delete nodes[current].ptr;
|
||||
p = new char[size];
|
||||
nodes[current].ptr = p;
|
||||
nodes[current].sz = size;
|
||||
}
|
||||
++current;
|
||||
if (current >= n) current = 0;
|
||||
return p;
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Dirk Grunwald (grunwald@cs.uiuc.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include <builtin.h>
|
||||
#include <Random.h>
|
||||
#include <Binomial.h>
|
||||
|
||||
double Binomial::operator()()
|
||||
{
|
||||
int s = 0;
|
||||
for (int i = 0; i < pN; i++) {
|
||||
if (pGenerator -> asDouble() < pU) {
|
||||
s++;
|
||||
}
|
||||
}
|
||||
return(double(s));
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,256 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Doug Lea (dl@rocky.oswego.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include <Complex.h>
|
||||
#include <std.h>
|
||||
#include <builtin.h>
|
||||
|
||||
// error handling
|
||||
|
||||
void default_Complex_error_handler(const char* msg)
|
||||
{
|
||||
cerr << "Fatal Complex arithmetic error. " << msg << "\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
one_arg_error_handler_t Complex_error_handler = default_Complex_error_handler;
|
||||
|
||||
one_arg_error_handler_t set_Complex_error_handler(one_arg_error_handler_t f)
|
||||
{
|
||||
one_arg_error_handler_t old = Complex_error_handler;
|
||||
Complex_error_handler = f;
|
||||
return old;
|
||||
}
|
||||
|
||||
void Complex::error(const char* msg) const
|
||||
{
|
||||
(*Complex_error_handler)(msg);
|
||||
}
|
||||
|
||||
/* from romine@xagsun.epm.ornl.gov */
|
||||
Complex /* const */ operator / (const Complex& x, const Complex& y)
|
||||
{
|
||||
double den = fabs(y.real()) + fabs(y.imag());
|
||||
if (den == 0.0) x.error ("Attempted division by zero.");
|
||||
double xrden = x.real() / den;
|
||||
double xiden = x.imag() / den;
|
||||
double yrden = y.real() / den;
|
||||
double yiden = y.imag() / den;
|
||||
double nrm = yrden * yrden + yiden * yiden;
|
||||
return Complex((xrden * yrden + xiden * yiden) / nrm,
|
||||
(xiden * yrden - xrden * yiden) / nrm);
|
||||
}
|
||||
|
||||
Complex& Complex::operator /= (const Complex& y)
|
||||
{
|
||||
double den = fabs(y.real()) + fabs(y.imag());
|
||||
if (den == 0.0) error ("Attempted division by zero.");
|
||||
double xrden = re / den;
|
||||
double xiden = im / den;
|
||||
double yrden = y.real() / den;
|
||||
double yiden = y.imag() / den;
|
||||
double nrm = yrden * yrden + yiden * yiden;
|
||||
re = (xrden * yrden + xiden * yiden) / nrm;
|
||||
im = (xiden * yrden - xrden * yiden) / nrm;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Complex /* const */ operator / (double x, const Complex& y)
|
||||
{
|
||||
double den = norm(y);
|
||||
if (den == 0.0) y.error ("Attempted division by zero.");
|
||||
return Complex((x * y.real()) / den, -(x * y.imag()) / den);
|
||||
}
|
||||
|
||||
Complex /* const */ operator / (const Complex& x, double y)
|
||||
{
|
||||
if (y == 0.0) x.error ("Attempted division by zero.");
|
||||
return Complex(x.real() / y, x.imag() / y);
|
||||
}
|
||||
|
||||
|
||||
Complex& Complex::operator /= (double y)
|
||||
{
|
||||
if (y == 0.0) error ("Attempted division by zero.");
|
||||
re /= y; im /= y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Complex /* const */ exp(const Complex& x)
|
||||
{
|
||||
double r = exp(x.real());
|
||||
return Complex(r * cos(x.imag()),
|
||||
r * sin(x.imag()));
|
||||
}
|
||||
|
||||
Complex /* const */ cosh(const Complex& x)
|
||||
{
|
||||
return Complex(cos(x.imag()) * cosh(x.real()),
|
||||
sin(x.imag()) * sinh(x.real()));
|
||||
}
|
||||
|
||||
Complex /* const */ sinh(const Complex& x)
|
||||
{
|
||||
return Complex(cos(x.imag()) * sinh(x.real()),
|
||||
sin(x.imag()) * cosh(x.real()));
|
||||
}
|
||||
|
||||
Complex /* const */ cos(const Complex& x)
|
||||
{
|
||||
return Complex(cos(x.real()) * cosh(x.imag()),
|
||||
-sin(x.real()) * sinh(x.imag()));
|
||||
}
|
||||
|
||||
Complex /* const */ sin(const Complex& x)
|
||||
{
|
||||
return Complex(sin(x.real()) * cosh(x.imag()),
|
||||
cos(x.real()) * sinh(x.imag()));
|
||||
}
|
||||
|
||||
Complex /* const */ log(const Complex& x)
|
||||
{
|
||||
double h = hypot(x.real(), x.imag());
|
||||
if (h <= 0.0) x.error("attempted log of zero magnitude number.");
|
||||
return Complex(log(h), atan2(x.imag(), x.real()));
|
||||
}
|
||||
|
||||
// Corrections based on reports from: thc@cs.brown.edu & saito@sdr.slb.com
|
||||
Complex /* const */ pow(const Complex& x, const Complex& p)
|
||||
{
|
||||
double h = hypot(x.real(), x.imag());
|
||||
if (h <= 0.0) x.error("attempted power of zero magnitude number.");
|
||||
|
||||
double a = atan2(x.imag(), x.real());
|
||||
double lr = pow(h, p.real());
|
||||
double li = p.real() * a;
|
||||
if (p.imag() != 0.0)
|
||||
{
|
||||
lr /= exp(p.imag() * a);
|
||||
li += p.imag() * log(h);
|
||||
}
|
||||
return Complex(lr * cos(li), lr * sin(li));
|
||||
}
|
||||
|
||||
Complex /* const */ pow(const Complex& x, double p)
|
||||
{
|
||||
double h = hypot(x.real(), x.imag());
|
||||
if (h <= 0.0) x.error("attempted power of zero magnitude number.");
|
||||
double lr = pow(h, p);
|
||||
double a = atan2(x.imag(), x.real());
|
||||
double li = p * a;
|
||||
return Complex(lr * cos(li), lr * sin(li));
|
||||
}
|
||||
|
||||
|
||||
Complex /* const */ sqrt(const Complex& x)
|
||||
{
|
||||
if (x.real() == 0.0 && x.imag() == 0.0)
|
||||
return Complex(0.0, 0.0);
|
||||
else
|
||||
{
|
||||
double s = sqrt((fabs(x.real()) + hypot(x.real(), x.imag())) * 0.5);
|
||||
double d = (x.imag() / s) * 0.5;
|
||||
if (x.real() > 0.0)
|
||||
return Complex(s, d);
|
||||
else if (x.imag() >= 0.0)
|
||||
return Complex(d, s);
|
||||
else
|
||||
return Complex(-d, -s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Complex /* const */ pow(const Complex& x, int p)
|
||||
{
|
||||
if (p == 0)
|
||||
return Complex(1.0, 0.0);
|
||||
else if (x == 0.0)
|
||||
return Complex(0.0, 0.0);
|
||||
else
|
||||
{
|
||||
Complex res(1.0, 0.0);
|
||||
Complex b = x;
|
||||
if (p < 0)
|
||||
{
|
||||
p = -p;
|
||||
b = 1.0 / b;
|
||||
}
|
||||
for(;;)
|
||||
{
|
||||
if (p & 1)
|
||||
res *= b;
|
||||
if ((p >>= 1) == 0)
|
||||
return res;
|
||||
else
|
||||
b *= b;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ostream& operator << (ostream& s, const Complex& x)
|
||||
{
|
||||
return s << "(" << x.real() << ", " << x.imag() << ")" ;
|
||||
}
|
||||
|
||||
istream& operator >> (istream& s, Complex& x)
|
||||
{
|
||||
#ifdef _OLD_STREAMS
|
||||
if (!s.good())
|
||||
{
|
||||
return s;
|
||||
}
|
||||
#else
|
||||
if (!s.ipfx(0))
|
||||
{
|
||||
s.clear(ios::failbit|s.rdstate()); // Redundant if using GNU iostreams.
|
||||
return s;
|
||||
}
|
||||
#endif
|
||||
double r, i;
|
||||
char ch;
|
||||
s >> ws;
|
||||
s.get(ch);
|
||||
if (ch == '(')
|
||||
{
|
||||
s >> r;
|
||||
s >> ws;
|
||||
s.get(ch);
|
||||
if (ch == ',')
|
||||
{
|
||||
s >> i;
|
||||
s >> ws;
|
||||
s .get(ch);
|
||||
}
|
||||
else
|
||||
i = 0;
|
||||
if (ch != ')')
|
||||
s.clear(ios::failbit);
|
||||
}
|
||||
else
|
||||
{
|
||||
s.putback(ch);
|
||||
s >> r;
|
||||
i = 0;
|
||||
}
|
||||
x = Complex(r, i);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
|
@ -1,253 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 1989, 1992 Free Software Foundation
|
||||
written by Eric Newton (newton@rocky.oswego.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <builtin.h>
|
||||
#ifndef _OLD_STREAMS
|
||||
#include <strstream.h>
|
||||
#endif
|
||||
// Include CurseW.h and/or curses.h *after* iostream includes,
|
||||
// because curses.h defines a clear macro that conflicts with iostream. Sigh.
|
||||
#include <CursesW.h>
|
||||
|
||||
#if _G_HAVE_CURSES
|
||||
|
||||
int CursesWindow::count = 0;
|
||||
|
||||
/*
|
||||
* C++ interface to curses library.
|
||||
*
|
||||
*/
|
||||
|
||||
#if !defined(_IO_MAGIC) && !defined(HAVE_VSCANF) &&!defined vsscanf
|
||||
extern "C" int _doscan(FILE *, const char*, va_list args);
|
||||
|
||||
static int vsscanf(char *buf, const char * fmt, va_list args)
|
||||
{
|
||||
FILE b;
|
||||
#ifdef _IOSTRG
|
||||
b._flag = _IOREAD|_IOSTRG;
|
||||
#else
|
||||
b._flag = _IOREAD;
|
||||
#endif
|
||||
b._base = (unsigned char*)buf;
|
||||
b._ptr = (unsigned char*)buf;
|
||||
b._cnt = BUFSIZ;
|
||||
return _doscan(&b, fmt, args);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* varargs functions are handled conservatively:
|
||||
* They interface directly into the underlying
|
||||
* _doscan, _doprnt and/or vfprintf routines rather than
|
||||
* assume that such things are handled compatibly in the curses library
|
||||
*/
|
||||
|
||||
int CursesWindow::scanw(const char * fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
#ifdef VMS
|
||||
int result = wscanw(w , fmt , args);
|
||||
#else /* NOT VMS */
|
||||
char buf[BUFSIZ];
|
||||
int result = wgetstr(w, buf);
|
||||
if (result == OK) {
|
||||
|
||||
#ifdef _IO_MAGIC /* GNU iostreams */
|
||||
strstreambuf ss(buf, BUFSIZ);
|
||||
result = ss.vscan(fmt, args);
|
||||
#else
|
||||
result = vsscanf(buf, fmt, args);
|
||||
#endif
|
||||
}
|
||||
#endif /* !VMS */
|
||||
va_end(args);
|
||||
return result;
|
||||
}
|
||||
|
||||
int CursesWindow::mvscanw(int y, int x, const char * fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
char buf[BUFSIZ];
|
||||
int result = wmove(w, y, x);
|
||||
if (result == OK)
|
||||
#ifdef VMS
|
||||
result=wscanw(w , fmt , args);
|
||||
#else /* !VMS */
|
||||
{
|
||||
result = wgetstr(w, buf);
|
||||
if (result == OK) {
|
||||
#ifdef _IO_MAGIC /* GNU iostreams */
|
||||
strstreambuf ss(buf, BUFSIZ);
|
||||
result = ss.vscan(fmt, args);
|
||||
#else
|
||||
result = vsscanf(buf, fmt, args);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif /* !VMS */
|
||||
va_end(args);
|
||||
return result;
|
||||
}
|
||||
|
||||
int CursesWindow::printw(const char * fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
char buf[BUFSIZ];
|
||||
vsprintf(buf, fmt, args);
|
||||
va_end(args);
|
||||
return waddstr(w, buf);
|
||||
}
|
||||
|
||||
|
||||
int CursesWindow::mvprintw(int y, int x, const char * fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int result = wmove(w, y, x);
|
||||
if (result == OK)
|
||||
{
|
||||
char buf[BUFSIZ];
|
||||
vsprintf(buf, fmt, args);
|
||||
result = waddstr(w, buf);
|
||||
}
|
||||
va_end(args);
|
||||
return result;
|
||||
}
|
||||
|
||||
CursesWindow::CursesWindow(int lines, int cols, int begin_y, int begin_x)
|
||||
{
|
||||
if (count==0)
|
||||
initscr();
|
||||
|
||||
w = newwin(lines, cols, begin_y, begin_x);
|
||||
if (w == 0)
|
||||
{
|
||||
(*lib_error_handler)("CursesWindow", "Cannot construct window");
|
||||
}
|
||||
|
||||
alloced = 1;
|
||||
subwins = par = sib = 0;
|
||||
count++;
|
||||
}
|
||||
|
||||
CursesWindow::CursesWindow(WINDOW* &window)
|
||||
{
|
||||
if (count==0)
|
||||
initscr();
|
||||
|
||||
w = window;
|
||||
alloced = 0;
|
||||
subwins = par = sib = 0;
|
||||
count++;
|
||||
}
|
||||
|
||||
CursesWindow::CursesWindow(CursesWindow& win, int l, int c,
|
||||
int by, int bx, char absrel)
|
||||
{
|
||||
|
||||
if (absrel == 'r') // relative origin
|
||||
{
|
||||
by += win.begy();
|
||||
bx += win.begx();
|
||||
}
|
||||
|
||||
// Even though we treat subwindows as a tree, the standard curses
|
||||
// library needs the `subwin' call to link to the root in
|
||||
// order to correctly perform refreshes, etc.
|
||||
|
||||
CursesWindow* root = &win;
|
||||
while (root->par != 0) root = root->par;
|
||||
|
||||
w = subwin(root->w, l, c, by, bx);
|
||||
if (w == 0)
|
||||
{
|
||||
(*lib_error_handler)("CursesWindow", "Cannot construct subwindow");
|
||||
}
|
||||
|
||||
par = &win;
|
||||
sib = win.subwins;
|
||||
win.subwins = this;
|
||||
subwins = 0;
|
||||
alloced = 1;
|
||||
count++;
|
||||
}
|
||||
|
||||
|
||||
void CursesWindow::kill_subwindows()
|
||||
{
|
||||
for (CursesWindow* p = subwins; p != 0; p = p->sib)
|
||||
{
|
||||
p->kill_subwindows();
|
||||
if (p->alloced)
|
||||
{
|
||||
if (p->w != 0)
|
||||
::delwin(p->w);
|
||||
p->alloced = 0;
|
||||
}
|
||||
p->w = 0; // cause a run-time error if anyone attempts to use...
|
||||
}
|
||||
}
|
||||
|
||||
CursesWindow::~CursesWindow()
|
||||
{
|
||||
kill_subwindows();
|
||||
|
||||
if (par != 0) // Snip us from the parent's list of subwindows.
|
||||
{
|
||||
CursesWindow * win = par->subwins;
|
||||
CursesWindow * trail = 0;
|
||||
for (;;)
|
||||
{
|
||||
if (win == 0)
|
||||
break;
|
||||
else if (win == this)
|
||||
{
|
||||
if (trail != 0)
|
||||
trail->sib = win->sib;
|
||||
else
|
||||
par->subwins = win->sib;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
trail = win;
|
||||
win = win->sib;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (alloced && w != 0)
|
||||
delwin(w);
|
||||
|
||||
--count;
|
||||
if (count == 0)
|
||||
endwin();
|
||||
else if (count < 0) // cannot happen!
|
||||
{
|
||||
(*lib_error_handler)("CursesWindow", "Too many windows destroyed");
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* _G_HAVE_CURSES */
|
||||
|
|
@ -1,327 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Doug Lea (dl@rocky.oswego.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef _G_NO_TEMPLATES
|
||||
#ifdef __GNUG__
|
||||
//#pragma implementation
|
||||
#endif
|
||||
#include <limits.h>
|
||||
#include <stream.h>
|
||||
#include <builtin.h>
|
||||
#include "DLList.h"
|
||||
|
||||
void BaseDLList::error(const char* msg) const
|
||||
{
|
||||
(*lib_error_handler)("DLList", msg);
|
||||
}
|
||||
|
||||
int BaseDLList::length() const
|
||||
{
|
||||
int l = 0;
|
||||
BaseDLNode* t = h;
|
||||
if (t != 0) do { ++l; t = t->fd; } while (t != h);
|
||||
return l;
|
||||
}
|
||||
|
||||
// Note: This is an internal method. It does *not* free old contents!
|
||||
|
||||
void BaseDLList::copy(const BaseDLList& a)
|
||||
{
|
||||
if (a.h == 0)
|
||||
h = 0;
|
||||
else
|
||||
{
|
||||
BaseDLNode* p = a.h;
|
||||
BaseDLNode* t = copy_node(p->item());
|
||||
h = t;
|
||||
p = p->fd;
|
||||
while (p != a.h)
|
||||
{
|
||||
BaseDLNode* n = copy_node(p->item());
|
||||
t->fd = n;
|
||||
n->bk = t;
|
||||
t = n;
|
||||
p = p->fd;
|
||||
}
|
||||
t->fd = h;
|
||||
h->bk = t;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void BaseDLList::clear()
|
||||
{
|
||||
if (h == 0)
|
||||
return;
|
||||
|
||||
BaseDLNode* p = h->fd;
|
||||
h->fd = 0;
|
||||
h = 0;
|
||||
|
||||
while (p != 0)
|
||||
{
|
||||
BaseDLNode* nxt = p->fd;
|
||||
delete_node(p);
|
||||
p = nxt;
|
||||
}
|
||||
}
|
||||
|
||||
BaseDLList& BaseDLList::operator = (const BaseDLList& a)
|
||||
{
|
||||
if (h != a.h)
|
||||
{
|
||||
clear();
|
||||
copy(a);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Pix BaseDLList::prepend(const void *datum)
|
||||
{
|
||||
BaseDLNode* t = copy_node(datum);
|
||||
if (h == 0)
|
||||
t->fd = t->bk = h = t;
|
||||
else
|
||||
{
|
||||
t->fd = h;
|
||||
t->bk = h->bk;
|
||||
h->bk->fd = t;
|
||||
h->bk = t;
|
||||
h = t;
|
||||
}
|
||||
return Pix(t);
|
||||
}
|
||||
|
||||
Pix BaseDLList::append(const void *datum)
|
||||
{
|
||||
BaseDLNode* t = copy_node(datum);
|
||||
if (h == 0)
|
||||
t->fd = t->bk = h = t;
|
||||
else
|
||||
{
|
||||
t->bk = h->bk;
|
||||
t->bk->fd = t;
|
||||
t->fd = h;
|
||||
h->bk = t;
|
||||
}
|
||||
return Pix(t);
|
||||
}
|
||||
|
||||
Pix BaseDLList::ins_after(Pix p, const void *datum)
|
||||
{
|
||||
if (p == 0) return prepend(datum);
|
||||
BaseDLNode* u = (BaseDLNode*) p;
|
||||
BaseDLNode* t = copy_node(datum);
|
||||
t->bk = u;
|
||||
t->fd = u->fd;
|
||||
u->fd->bk = t;
|
||||
u->fd = t;
|
||||
return Pix(t);
|
||||
}
|
||||
|
||||
Pix BaseDLList::ins_before(Pix p, const void *datum)
|
||||
{
|
||||
if (p == 0) error("null Pix");
|
||||
BaseDLNode* u = (BaseDLNode*) p;
|
||||
BaseDLNode* t = copy_node(datum);
|
||||
t->bk = u->bk;
|
||||
t->fd = u;
|
||||
u->bk->fd = t;
|
||||
u->bk = t;
|
||||
if (u == h) h = t;
|
||||
return Pix(t);
|
||||
}
|
||||
|
||||
void BaseDLList::join(BaseDLList& b)
|
||||
{
|
||||
BaseDLNode* t = b.h;
|
||||
b.h = 0;
|
||||
if (h == 0)
|
||||
h = t;
|
||||
else if (t != 0)
|
||||
{
|
||||
BaseDLNode* l = t->bk;
|
||||
h->bk->fd = t;
|
||||
t->bk = h->bk;
|
||||
h->bk = l;
|
||||
l->fd = h;
|
||||
}
|
||||
}
|
||||
|
||||
int BaseDLList::owns(Pix p) const
|
||||
{
|
||||
BaseDLNode* t = h;
|
||||
if (t != 0 && p != 0)
|
||||
{
|
||||
do
|
||||
{
|
||||
if (Pix(t) == p) return 1;
|
||||
t = t->fd;
|
||||
} while (t != h);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void BaseDLList::del(Pix& p, int dir)
|
||||
{
|
||||
if (p == 0) error("null Pix");
|
||||
BaseDLNode* t = (BaseDLNode*) p;
|
||||
if (t->fd == t)
|
||||
{
|
||||
h = 0;
|
||||
p = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dir < 0)
|
||||
{
|
||||
if (t == h)
|
||||
p = 0;
|
||||
else
|
||||
p = Pix(t->bk);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (t == h->bk)
|
||||
p = 0;
|
||||
else
|
||||
p = Pix(t->fd);
|
||||
}
|
||||
t->bk->fd = t->fd;
|
||||
t->fd->bk = t->bk;
|
||||
if (t == h) h = t->fd;
|
||||
}
|
||||
delete_node(t);
|
||||
}
|
||||
|
||||
void BaseDLList::del_after(Pix& p)
|
||||
{
|
||||
if (p == 0)
|
||||
{
|
||||
del_front();
|
||||
return;
|
||||
}
|
||||
|
||||
BaseDLNode* b = (BaseDLNode*) p;
|
||||
BaseDLNode* t = b->fd;
|
||||
|
||||
if (b == t)
|
||||
{
|
||||
h = 0;
|
||||
p = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
t->bk->fd = t->fd;
|
||||
t->fd->bk = t->bk;
|
||||
if (t == h) h = t->fd;
|
||||
}
|
||||
delete_node(t);
|
||||
}
|
||||
|
||||
void BaseDLList::remove_front(void *dst)
|
||||
{
|
||||
if (h == 0)
|
||||
error("remove_front of empty list");
|
||||
else {
|
||||
BaseDLNode* t = h;
|
||||
copy_item(dst, t->item());
|
||||
if (h->fd == h)
|
||||
h = 0;
|
||||
else
|
||||
{
|
||||
h->fd->bk = h->bk;
|
||||
h->bk->fd = h->fd;
|
||||
h = h->fd;
|
||||
}
|
||||
delete_node(t);
|
||||
}
|
||||
}
|
||||
|
||||
void BaseDLList::del_front()
|
||||
{
|
||||
if (h == 0)
|
||||
error("del_front of empty list");
|
||||
BaseDLNode* t = h;
|
||||
if (h->fd == h)
|
||||
h = 0;
|
||||
else
|
||||
{
|
||||
h->fd->bk = h->bk;
|
||||
h->bk->fd = h->fd;
|
||||
h = h->fd;
|
||||
}
|
||||
delete_node(t);
|
||||
}
|
||||
|
||||
void BaseDLList::remove_rear(void *dst)
|
||||
{
|
||||
if (h == 0)
|
||||
error("remove_rear of empty list");
|
||||
else
|
||||
{
|
||||
BaseDLNode* t = h->bk;
|
||||
copy_item(dst, t->item());
|
||||
if (h->fd == h)
|
||||
h = 0;
|
||||
else
|
||||
{
|
||||
t->fd->bk = t->bk;
|
||||
t->bk->fd = t->fd;
|
||||
}
|
||||
delete_node(t);
|
||||
}
|
||||
}
|
||||
|
||||
void BaseDLList::del_rear()
|
||||
{
|
||||
if (h == 0)
|
||||
error("del_rear of empty list");
|
||||
BaseDLNode* t = h->bk;
|
||||
if (h->fd == h)
|
||||
h = 0;
|
||||
else
|
||||
{
|
||||
t->fd->bk = t->bk;
|
||||
t->bk->fd = t->fd;
|
||||
}
|
||||
delete_node(t);
|
||||
}
|
||||
|
||||
|
||||
int BaseDLList::OK() const
|
||||
{
|
||||
int v = 1;
|
||||
if (h != 0)
|
||||
{
|
||||
BaseDLNode* t = h;
|
||||
long count = LONG_MAX; // Lots of chances to find h!
|
||||
do
|
||||
{
|
||||
count--;
|
||||
v &= t->bk->fd == t;
|
||||
v &= t->fd->bk == t;
|
||||
t = t->fd;
|
||||
} while (v && count > 0 && t != h);
|
||||
v &= count > 0;
|
||||
}
|
||||
if (!v) error("invariant failure");
|
||||
return v;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Dirk Grunwald (grunwald@cs.uiuc.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include <builtin.h>
|
||||
#include <Random.h>
|
||||
#include <DiscUnif.h>
|
||||
|
||||
double DiscreteUniform::operator()()
|
||||
{
|
||||
long tmp = long(floor(delta * pGenerator -> asDouble()));
|
||||
return( double(pLow + tmp) );
|
||||
}
|
||||
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Dirk Grunwald (grunwald@cs.uiuc.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include <builtin.h>
|
||||
#include <Random.h>
|
||||
#include <Erlang.h>
|
||||
|
||||
double Erlang::operator()()
|
||||
{
|
||||
double prod = 1.0;
|
||||
|
||||
for (int i = 0; i < k; i++) {
|
||||
prod *= pGenerator -> asDouble();
|
||||
}
|
||||
return(-log(prod)/a);
|
||||
}
|
||||
|
|
@ -1,663 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1989 Free Software Foundation
|
||||
written by Doug Lea (dl@rocky.oswego.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
//
|
||||
// Fix.cc : variable length fixed point data type class functions
|
||||
//
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include <Fix.h>
|
||||
#include <std.h>
|
||||
#include <Obstack.h>
|
||||
#include <AllocRing.h>
|
||||
#include <strstream.h>
|
||||
|
||||
// member constants
|
||||
|
||||
const _G_uint16_t Fix::min_length;
|
||||
const _G_uint16_t Fix::max_length;
|
||||
const double Fix::min_value;
|
||||
const double Fix::max_value;
|
||||
|
||||
// default parameters
|
||||
|
||||
_G_uint16_t Fix::default_length = 16;
|
||||
int Fix::default_print_width = 8;
|
||||
|
||||
Fix::PEH Fix::overflow_handler = Fix::overflow_saturate;
|
||||
|
||||
Fix::Rep Fix::Rep_0 = { 16, 1, 1, { 0 } };
|
||||
Fix::Rep Fix::Rep_m1 = { 16, 1, 1, { 0x8000 } };
|
||||
Fix::Rep Fix::Rep_quotient_bump = { 16, 1, 1, { 0x4000 } };
|
||||
|
||||
// error handling
|
||||
|
||||
void
|
||||
Fix::default_error_handler(const char* msg)
|
||||
{
|
||||
cerr << "Fix: " << msg << "\n";
|
||||
abort();
|
||||
}
|
||||
|
||||
void
|
||||
Fix::default_range_error_handler(const char* msg)
|
||||
{
|
||||
cerr << "Fix: range error in " << msg << "\n";
|
||||
//abort();
|
||||
}
|
||||
|
||||
one_arg_error_handler_t
|
||||
Fix::error_handler = Fix::default_error_handler,
|
||||
Fix::range_error_handler = Fix::default_range_error_handler;
|
||||
|
||||
one_arg_error_handler_t
|
||||
Fix::set_error_handler(one_arg_error_handler_t f)
|
||||
{
|
||||
one_arg_error_handler_t old = error_handler;
|
||||
error_handler = f;
|
||||
return old;
|
||||
}
|
||||
|
||||
one_arg_error_handler_t
|
||||
Fix::set_range_error_handler(one_arg_error_handler_t f)
|
||||
{
|
||||
one_arg_error_handler_t old = range_error_handler;
|
||||
range_error_handler = f;
|
||||
return old;
|
||||
}
|
||||
|
||||
void
|
||||
Fix::error(const char* msg)
|
||||
{
|
||||
error_handler(msg);
|
||||
}
|
||||
|
||||
void
|
||||
Fix::range_error(const char* msg)
|
||||
{
|
||||
range_error_handler(msg);
|
||||
}
|
||||
|
||||
// Fix::Rep allocation and initialization functions
|
||||
|
||||
static inline Fix::Rep*
|
||||
_new_Fix(_G_uint16_t len)
|
||||
{
|
||||
int siz = (((_G_uint32_t) len + 15) >> 4);
|
||||
if (siz <= 0) siz = 1;
|
||||
unsigned int allocsiz = (sizeof(Fix::Rep) + (siz - 1) * sizeof(_G_uint16_t));
|
||||
Fix::Rep* z = (Fix::Rep*)(new char[allocsiz]);
|
||||
memset(z, 0, allocsiz);
|
||||
z->len = len;
|
||||
z->siz = siz;
|
||||
z->ref = 1;
|
||||
return z;
|
||||
}
|
||||
|
||||
Fix::Rep*
|
||||
Fix::new_Fix(_G_uint16_t len)
|
||||
{
|
||||
return _new_Fix(len);
|
||||
}
|
||||
|
||||
Fix::Rep*
|
||||
Fix::new_Fix(_G_uint16_t len, const Rep* x)
|
||||
{
|
||||
Rep* z = _new_Fix(len);
|
||||
return copy(x,z);
|
||||
}
|
||||
|
||||
Fix::Rep*
|
||||
Fix::new_Fix(_G_uint16_t len, double d)
|
||||
{
|
||||
Rep* z = _new_Fix(len);
|
||||
|
||||
if ( d == max_value )
|
||||
{
|
||||
z->s[0] = 0x7fff;
|
||||
for ( int i=1; i < z->siz; i++ )
|
||||
z->s[i] = 0xffff;
|
||||
}
|
||||
else if ( d < min_value || d > max_value )
|
||||
range_error("declaration");
|
||||
else
|
||||
{
|
||||
if (d < 0)
|
||||
d += 2.0;
|
||||
d *= 32768;
|
||||
for ( int i=0; i < z->siz; i++ )
|
||||
{
|
||||
z->s[i] = (_G_uint16_t )d;
|
||||
d -= z->s[i];
|
||||
d *= 65536;
|
||||
}
|
||||
if ( d >= 32768 )
|
||||
z->s[z->siz-1]++;
|
||||
}
|
||||
mask(z);
|
||||
return z;
|
||||
}
|
||||
|
||||
// convert to a double
|
||||
|
||||
double
|
||||
value(const Fix& x)
|
||||
{
|
||||
double d = 0.0;
|
||||
for ( int i=x.rep->siz-1; i >= 0; i-- )
|
||||
{
|
||||
d += x.rep->s[i];
|
||||
d *= 1./65536.;
|
||||
}
|
||||
d *= 2.;
|
||||
return d < 1. ? d : d - 2.;
|
||||
}
|
||||
|
||||
// extract mantissa to Integer
|
||||
|
||||
Integer
|
||||
mantissa(const Fix& x)
|
||||
{
|
||||
Integer a = 1, b=1;
|
||||
for ( int i=0; i < x.rep->siz; i++ )
|
||||
{
|
||||
a <<= 16;
|
||||
a += x.rep->s[i];
|
||||
b <<= 16;
|
||||
}
|
||||
return a-b;
|
||||
}
|
||||
|
||||
// comparison functions
|
||||
|
||||
inline static int
|
||||
docmp(const _G_uint16_t* x, const _G_uint16_t* y, int siz)
|
||||
{
|
||||
int diff = (_G_int16_t )*x - (_G_int16_t )*y;
|
||||
while ( --siz && !diff )
|
||||
diff = (_G_int32_t )(_G_uint32_t )*++x - (_G_int32_t )(_G_uint32_t )*++y;
|
||||
return diff;
|
||||
}
|
||||
|
||||
inline static int
|
||||
docmpz(const _G_uint16_t* x, int siz)
|
||||
{
|
||||
while ( siz-- )
|
||||
if ( *x++ ) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
Fix::compare(const Rep* x, const Rep* y)
|
||||
{
|
||||
if ( x->siz == y->siz )
|
||||
return docmp(x->s, y->s, x->siz);
|
||||
else
|
||||
{
|
||||
int r;
|
||||
const Rep* longer, *shorter;
|
||||
if ( x->siz > y->siz )
|
||||
{
|
||||
longer = x;
|
||||
shorter = y;
|
||||
r = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
longer = y;
|
||||
shorter = x;
|
||||
r = -1;
|
||||
}
|
||||
int diff = docmp(x->s, y->s, shorter->siz);
|
||||
if ( diff )
|
||||
return diff;
|
||||
else if ( docmpz(&longer->s[shorter->siz], longer->siz-shorter->siz) )
|
||||
return r;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// arithmetic functions
|
||||
|
||||
Fix::Rep*
|
||||
Fix::add(const Rep* x, const Rep* y, Rep* r)
|
||||
{
|
||||
_G_uint16_t xsign = x->s[0], ysign = y->s[0];
|
||||
const Rep* longer, *shorter;
|
||||
if ( x->len >= y->len )
|
||||
longer = x, shorter = y;
|
||||
else
|
||||
longer = y, shorter = x;
|
||||
if ( r == NULL )
|
||||
r = new_Fix(longer->len);
|
||||
for ( int i=r->siz-1; i >= longer->siz; i-- )
|
||||
r->s[i] = 0;
|
||||
for ( ; i >= shorter->siz; i-- )
|
||||
r->s[i] = longer->s[i];
|
||||
_G_uint32_t sum = 0, carry = 0;
|
||||
for ( ; i >= 0; i-- )
|
||||
{
|
||||
sum = carry + (_G_uint32_t )x->s[i] + (_G_uint32_t )y->s[i];
|
||||
carry = sum >> 16;
|
||||
r->s[i] = sum;
|
||||
}
|
||||
if ( (xsign ^ sum) & (ysign ^ sum) & 0x8000 )
|
||||
overflow_handler(r);
|
||||
return r;
|
||||
}
|
||||
|
||||
Fix::Rep*
|
||||
Fix::subtract(const Rep* x, const Rep* y, Rep* r)
|
||||
{
|
||||
_G_uint16_t xsign = x->s[0], ysign = y->s[0];
|
||||
const Rep* longer, *shorter;
|
||||
if ( x->len >= y->len )
|
||||
longer = x, shorter = y;
|
||||
else
|
||||
longer = y, shorter = x;
|
||||
if ( r == NULL )
|
||||
r = new_Fix(longer->len);
|
||||
for ( int i=r->siz-1; i >= longer->siz; i-- )
|
||||
r->s[i] = 0;
|
||||
for ( ; i >= shorter->siz; i-- )
|
||||
r->s[i] = (longer == x ? x->s[i] : -y->s[i]);
|
||||
_G_int16_t carry = 0;
|
||||
_G_uint32_t sum = 0;
|
||||
for ( ; i >= 0; i-- )
|
||||
{
|
||||
sum = (_G_int32_t )carry + (_G_uint32_t )x->s[i] - (_G_uint32_t )y->s[i];
|
||||
carry = sum >> 16;
|
||||
r->s[i] = sum;
|
||||
}
|
||||
if ( (xsign ^ sum) & (~ysign ^ sum) & 0x8000 )
|
||||
overflow_handler(r);
|
||||
return r;
|
||||
}
|
||||
|
||||
Fix::Rep*
|
||||
Fix::multiply(const Rep* x, const Rep* y, Rep* r)
|
||||
{
|
||||
if ( r == NULL )
|
||||
r = new_Fix(x->len + y->len);
|
||||
int xsign = x->s[0] & 0x8000,
|
||||
ysign = y->s[0] & 0x8000;
|
||||
Fix X(x->len), Y(y->len);
|
||||
if ( xsign )
|
||||
x = negate(x,X.rep);
|
||||
if ( ysign )
|
||||
y = negate(y,Y.rep);
|
||||
for ( int i=0; i < r->siz; i++ )
|
||||
r->s[i] = 0;
|
||||
for ( i=x->siz-1; i >= 0; i-- )
|
||||
{
|
||||
_G_uint32_t carry = 0;
|
||||
for ( int j=y->siz-1; j >= 0; j-- )
|
||||
{
|
||||
int k = i + j + 1;
|
||||
_G_uint32_t a = (_G_uint32_t )x->s[i] * (_G_uint32_t )y->s[j];
|
||||
_G_uint32_t b = ((a << 1) & 0xffff) + carry;
|
||||
if ( k < r->siz )
|
||||
{
|
||||
b += r->s[k];
|
||||
r->s[k] = b;
|
||||
}
|
||||
if ( k < (int)r->siz + 1 )
|
||||
carry = (a >> 15) + (b >> 16);
|
||||
}
|
||||
r->s[i] = carry;
|
||||
}
|
||||
if ( xsign != ysign )
|
||||
negate(r,r);
|
||||
return r;
|
||||
}
|
||||
|
||||
Fix::Rep*
|
||||
Fix::multiply(const Rep* x, int y, Rep* r)
|
||||
{
|
||||
if ( y != (_G_int16_t )y )
|
||||
range_error("multiply by int -- int too large");
|
||||
if ( r == NULL )
|
||||
r = new_Fix(x->len);
|
||||
for ( int i=r->siz-1; i >= x->siz; i-- )
|
||||
r->s[i] = 0;
|
||||
_G_int32_t a, carry = 0;
|
||||
for ( ; i > 0; i-- )
|
||||
{
|
||||
a = (_G_int32_t) (_G_uint32_t )x->s[i] * y + carry;
|
||||
r->s[i] = a;
|
||||
carry = a >> 16; // assumes arithmetic right shift
|
||||
}
|
||||
a = (_G_int32_t) (_G_int16_t )x->s[0] * y + carry;
|
||||
r->s[0] = a;
|
||||
a &= 0xffff8000L;
|
||||
if ( a != (_G_int32_t)0xffff8000L && a != (_G_int32_t)0L ) {
|
||||
r->s[0] = 0x8000 ^ x->s[0] ^ y;
|
||||
overflow_handler(r);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
Fix::Rep*
|
||||
Fix::divide(const Rep* x, const Rep* y, Rep* q, Rep* r)
|
||||
{
|
||||
int xsign = x->s[0] & 0x8000,
|
||||
ysign = y->s[0] & 0x8000;
|
||||
if ( q == NULL )
|
||||
q = new_Fix(x->len);
|
||||
copy(&Rep_0,q);
|
||||
if ( r == NULL )
|
||||
r = new_Fix(x->len + y->len - 1);
|
||||
if ( xsign )
|
||||
negate(x,r);
|
||||
else
|
||||
copy(x,r);
|
||||
Fix Y(y->len);
|
||||
Rep* y2 = ( ysign ? negate(y,Y.rep) : copy(y,Y.rep) );
|
||||
if ( !compare(y2) )
|
||||
range_error("division -- division by zero");
|
||||
else if ( compare(x,y2) >= 0 )
|
||||
if ( compare(x,y2) == 0 && (xsign ^ ysign) != 0 )
|
||||
{
|
||||
copy(&Rep_m1,q);
|
||||
copy(&Rep_0,r);
|
||||
}
|
||||
else
|
||||
range_error("division");
|
||||
else
|
||||
{
|
||||
Rep* t;
|
||||
Fix S(r->len),
|
||||
W(q->len,&Rep_quotient_bump);
|
||||
for ( int i=1; i < q->len; i++ )
|
||||
{
|
||||
shift(y2,-1,y2);
|
||||
subtract(r,y2,S.rep);
|
||||
int s_status = compare(S.rep);
|
||||
if ( s_status == 0 )
|
||||
{
|
||||
t = r, r = S.rep, S.rep = t;
|
||||
break;
|
||||
}
|
||||
else if ( s_status > 0 )
|
||||
{
|
||||
t = r, r = S.rep, S.rep = t;
|
||||
add(q,W.rep,q);
|
||||
}
|
||||
shift(W.rep,-1,W.rep);
|
||||
}
|
||||
if ( xsign ^ ysign )
|
||||
negate(q,q);
|
||||
}
|
||||
return q;
|
||||
}
|
||||
|
||||
Fix::Rep*
|
||||
Fix::shift(const Rep* x, int y, Rep* r)
|
||||
{
|
||||
if ( r == NULL )
|
||||
r = new_Fix(x->len);
|
||||
if ( y == 0 )
|
||||
{
|
||||
copy (x, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
int ay = abs((_G_int32_t) y),
|
||||
ayh = ay >> 4,
|
||||
ayl = ay & 0x0f;
|
||||
int xl, u, ilow, ihigh;
|
||||
_G_uint16_t *rs;
|
||||
const _G_uint16_t *xsl, *xsr;
|
||||
|
||||
if ( y > 0 )
|
||||
{
|
||||
rs = r->s;
|
||||
xsl = x->s + ayh;
|
||||
xsr = xsl + 1;
|
||||
xl = ayl;
|
||||
u = 1;
|
||||
ihigh = x->siz - ayh - 1;
|
||||
ilow = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
rs = &r->s[r->siz - 1];
|
||||
xsr = &x->s[r->siz - 1] - ayh;
|
||||
xsl = xsr - 1;
|
||||
xl = 16 - ayl;
|
||||
u = -1;
|
||||
ihigh = r->siz - ayh - 1;
|
||||
ilow = ihigh - x->siz;
|
||||
}
|
||||
|
||||
int xr = 16 - xl;
|
||||
_G_uint16_t xrmask = 0xffffL >> xr;
|
||||
for ( int i=0; i < ilow; i++, rs+=u, xsl+=u, xsr+=u )
|
||||
*rs = 0;
|
||||
for ( ; i < ihigh; i++, rs+=u, xsl+=u, xsr+=u )
|
||||
*rs = (*xsl << xl) + ((*xsr >> xr) & xrmask);
|
||||
*rs = (y > 0 ? (*xsl << xl) : ((*xsr >> xr) & xrmask));
|
||||
rs += u;
|
||||
for ( ; ++i < r->siz; rs+=u )
|
||||
*rs = 0;
|
||||
return r;
|
||||
}
|
||||
|
||||
Fix::Rep*
|
||||
Fix::negate(const Rep* x, Rep* r)
|
||||
{
|
||||
if ( r == NULL )
|
||||
r = new_Fix(x->len);
|
||||
_G_uint32_t carry = 1;
|
||||
for ( int i=r->siz-1; i >= x->siz; i-- )
|
||||
r->s[i] = 0;
|
||||
for ( ; i >= 0; i-- )
|
||||
{
|
||||
_G_uint32_t a = (_G_uint16_t )~x->s[i] + carry; // bug work-around
|
||||
r->s[i] = a;
|
||||
carry = a >> 16;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
// io functions
|
||||
|
||||
Fix
|
||||
atoF(const char* a, int len)
|
||||
{
|
||||
return Fix(len,atof(a));
|
||||
}
|
||||
|
||||
extern AllocRing _libgxx_fmtq;
|
||||
|
||||
void
|
||||
Fix::printon(ostream& s, int width) const
|
||||
{
|
||||
double val = value(*this);
|
||||
int old_precision = s.precision(width-3);
|
||||
_G_int32_t old_flags = s.setf(ios::fixed, ios::fixed|ios::scientific);
|
||||
if (val >= 0)
|
||||
s << ' ';
|
||||
s.width(width-2);
|
||||
s << val;
|
||||
s.precision(old_precision);
|
||||
s.flags(old_flags);
|
||||
}
|
||||
|
||||
char*
|
||||
Ftoa(Fix& x, int width)
|
||||
{
|
||||
int wrksiz = width + 2;
|
||||
char *fmtbase = (char *) _libgxx_fmtq.alloc(wrksiz);
|
||||
ostrstream stream(fmtbase, wrksiz);
|
||||
|
||||
x.printon(stream, width);
|
||||
stream << ends;
|
||||
return fmtbase;
|
||||
}
|
||||
|
||||
extern Obstack _libgxx_io_ob;
|
||||
|
||||
Fix
|
||||
Fix::operator %= (int y)
|
||||
{
|
||||
Fix r((int )rep->len + y, *this); return *this = r;
|
||||
}
|
||||
|
||||
istream&
|
||||
operator >> (istream& s, Fix& y)
|
||||
{
|
||||
int got_one = 0;
|
||||
if (!s.ipfx(0))
|
||||
{
|
||||
s.clear(ios::failbit|s.rdstate()); // Redundant if using GNU iostreams.
|
||||
return s;
|
||||
}
|
||||
|
||||
char sign = 0, point = 0;
|
||||
char ch;
|
||||
s >> ws;
|
||||
if (!s.good())
|
||||
{
|
||||
s.clear(ios::failbit|s.rdstate());
|
||||
return s;
|
||||
}
|
||||
while (s.get(ch))
|
||||
{
|
||||
if (ch == '-')
|
||||
{
|
||||
if (sign == 0)
|
||||
{
|
||||
sign = 1;
|
||||
_libgxx_io_ob.grow(ch);
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
if (ch == '.')
|
||||
{
|
||||
if (point == 0)
|
||||
{
|
||||
point = 1;
|
||||
_libgxx_io_ob.grow(ch);
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
else if (ch >= '0' && ch <= '9')
|
||||
{
|
||||
got_one = 1;
|
||||
_libgxx_io_ob.grow(ch);
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
char * p = (char*)(_libgxx_io_ob.finish(0));
|
||||
if (s.good())
|
||||
s.putback(ch);
|
||||
if (!got_one)
|
||||
s.clear(ios::failbit|s.rdstate());
|
||||
else
|
||||
y = atoF(p);
|
||||
_libgxx_io_ob.free(p);
|
||||
return s;
|
||||
}
|
||||
|
||||
void
|
||||
show(const Fix& x)
|
||||
{
|
||||
cout << "len = " << x.rep->len << "\n";
|
||||
cout << "siz = " << x.rep->siz << "\n";
|
||||
cout << "ref = " << x.rep->ref << "\n";
|
||||
cout << "man = ";
|
||||
#ifdef _OLD_STREAMS
|
||||
cout << Itoa(mantissa(x),16,4*x.rep->siz);
|
||||
#else
|
||||
int old_flags = cout.setf(ios::hex, ios::hex|ios::dec|ios::oct);
|
||||
cout.width(4*x.rep->siz);
|
||||
cout << mantissa(x);
|
||||
cout.setf(old_flags, ios::hex|ios::dec|ios::oct);
|
||||
#endif
|
||||
cout << "\n";
|
||||
cout << "val = " << value(x) << "\n";
|
||||
}
|
||||
|
||||
// parameter setting operations
|
||||
|
||||
Fix::PEH Fix::set_overflow_handler(PEH new_handler)
|
||||
{
|
||||
PEH old_handler = overflow_handler;
|
||||
overflow_handler = new_handler;
|
||||
return old_handler;
|
||||
}
|
||||
|
||||
int
|
||||
Fix::set_default_length(int newlen)
|
||||
{
|
||||
_G_uint16_t oldlen = default_length;
|
||||
if ( newlen < min_length || newlen > max_length )
|
||||
error("illegal length in Fix::set_default_length");
|
||||
default_length = newlen;
|
||||
return oldlen;
|
||||
}
|
||||
|
||||
// overflow handlers
|
||||
|
||||
void
|
||||
Fix::overflow_saturate(Rep* r)
|
||||
{
|
||||
if ( (_G_int16_t) r->s[0] > 0 )
|
||||
{
|
||||
r->s[0] = 0x8000;
|
||||
for ( int i=1; i < r->siz; i++ )
|
||||
r->s[i] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
r->s[0] = 0x7fff;
|
||||
for ( int i = 1; i < (int)r->siz; i++ )
|
||||
r->s[i] = 0xffff;
|
||||
mask(r);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Fix::overflow_wrap(Rep*)
|
||||
{}
|
||||
|
||||
void
|
||||
Fix::overflow_warning_saturate(Rep* r)
|
||||
{
|
||||
overflow_warning(r);
|
||||
overflow_saturate(r);
|
||||
}
|
||||
|
||||
void
|
||||
Fix::overflow_warning(Rep*)
|
||||
{
|
||||
cerr << "Fix: overflow warning\n";
|
||||
}
|
||||
|
||||
void
|
||||
Fix::overflow_error(Rep*)
|
||||
{
|
||||
cerr << "Fix: overflow error\n";
|
||||
abort();
|
||||
}
|
||||
|
|
@ -1,238 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Kurt Baudendistel (gt-eedsp!baud@gatech.edu)
|
||||
adapted for libg++ by Doug Lea (dl@rocky.oswego.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
//
|
||||
// Fix.cc : fixed precision class support functions
|
||||
//
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include <Fix16.h>
|
||||
|
||||
// basic operators too large to be inline
|
||||
|
||||
short Fix16::assign(double d)
|
||||
{
|
||||
if (d == 1.0)
|
||||
return Fix16_m_max;
|
||||
else if (d > Fix16_max)
|
||||
{
|
||||
short i = Fix16_m_max;
|
||||
range_error(i);
|
||||
return i;
|
||||
}
|
||||
else if (d < Fix16_min)
|
||||
{
|
||||
short i = Fix16_m_min;
|
||||
range_error(i);
|
||||
return i;
|
||||
}
|
||||
else
|
||||
return round(Fix16_mult * d);
|
||||
}
|
||||
|
||||
_G_int32_t Fix32::assign(double d)
|
||||
{
|
||||
if (d == 1.0)
|
||||
return Fix32_m_max;
|
||||
else if (d > Fix32_max)
|
||||
{
|
||||
_G_int32_t i = Fix32_m_max;
|
||||
range_error(i);
|
||||
return i;
|
||||
}
|
||||
else if (d < Fix32_min)
|
||||
{
|
||||
_G_int32_t i = Fix32_m_min;
|
||||
range_error(i);
|
||||
return i;
|
||||
}
|
||||
else
|
||||
return round(Fix32_mult * d);
|
||||
}
|
||||
|
||||
|
||||
Fix32 operator * (const Fix32& a, const Fix32& b)
|
||||
{
|
||||
// break a and b into lo and hi parts, and do a multiple-precision
|
||||
// multiply, with rounding
|
||||
|
||||
int apos = (a.m >= 0);
|
||||
_G_uint32_t ua = (apos)? a.m : - a.m;
|
||||
ua <<= 1; // ua is biased so result will be 31 bit mantissa, not 30:
|
||||
_G_uint32_t hi_a = (ua >> 16) & ((1 << 16) - 1);
|
||||
_G_uint32_t lo_a = ua & ((1 << 16) - 1);
|
||||
|
||||
int bpos = (b.m >= 0);
|
||||
_G_uint32_t ub = (bpos)? b.m : -b.m;
|
||||
_G_uint32_t hi_b = (ub >> 16) & ((1 << 16) - 1);
|
||||
_G_uint32_t lo_b = ub & ((1 << 16) - 1);
|
||||
|
||||
_G_uint32_t r = lo_a * lo_b + (1 << 15);
|
||||
r = (r >> 16) + hi_a * lo_b + lo_a * hi_b + (1 << 15);
|
||||
r = (r >> 16) + hi_a * hi_b;
|
||||
_G_int32_t p = (apos != bpos)? -r : r;
|
||||
return Fix32(p);
|
||||
}
|
||||
|
||||
Fix16 operator / (const Fix16& a, const Fix16& b)
|
||||
{
|
||||
short q;
|
||||
int apos = (a.m >= 0);
|
||||
_G_int32_t la = (apos)? a.m : -a.m;
|
||||
_G_int32_t scaled_a = la << 15;
|
||||
int bpos = (b.m >= 0);
|
||||
short sb = (bpos)? b.m: -b.m;
|
||||
if (la >= sb)
|
||||
{
|
||||
q = (apos == bpos)? Fix16_m_max: Fix16_m_min;
|
||||
a.range_error(q);
|
||||
}
|
||||
else
|
||||
{
|
||||
q = scaled_a / sb;
|
||||
if ((scaled_a % sb) >= (sb / 2)) ++q;
|
||||
if (apos != bpos) q = -q;
|
||||
}
|
||||
return Fix16(q);
|
||||
}
|
||||
|
||||
Fix32 operator / (const Fix32& a, const Fix32& b)
|
||||
{
|
||||
_G_int32_t q;
|
||||
int apos = (a.m >= 0);
|
||||
_G_uint32_t la = (apos)? a.m : -a.m;
|
||||
int bpos = (b.m >= 0);
|
||||
_G_uint32_t lb = (bpos)? b.m: -b.m;
|
||||
if (la >= lb)
|
||||
{
|
||||
q = (apos == bpos)? Fix32_m_max: Fix32_m_min;
|
||||
a.range_error(q);
|
||||
}
|
||||
else // standard shift-based division alg
|
||||
{
|
||||
q = 0;
|
||||
_G_int32_t r = la;
|
||||
|
||||
for (int i = 32; i > 0; i--)
|
||||
{
|
||||
if ((unsigned)(r) > lb) {
|
||||
q = (q << 1) | 1;
|
||||
r -= lb;
|
||||
}
|
||||
else
|
||||
q = (q << 1);
|
||||
r <<= 1;
|
||||
}
|
||||
|
||||
if (apos != bpos) q = -q; // Fix sign
|
||||
}
|
||||
return Fix32(q);
|
||||
}
|
||||
|
||||
|
||||
// error handling
|
||||
|
||||
void Fix16::overflow(short& i) const
|
||||
{
|
||||
(*Fix16_overflow_handler)(i);
|
||||
}
|
||||
|
||||
void Fix32::overflow(_G_int32_t& i) const
|
||||
{
|
||||
(*Fix32_overflow_handler)(i);
|
||||
}
|
||||
|
||||
void Fix16::range_error(short& i) const
|
||||
{
|
||||
(*Fix16_range_error_handler)(i);
|
||||
}
|
||||
|
||||
void Fix32::range_error(_G_int32_t& i) const
|
||||
{
|
||||
(*Fix32_range_error_handler)(i);
|
||||
}
|
||||
|
||||
// data definitions
|
||||
|
||||
Fix16_peh Fix16_overflow_handler = Fix16_overflow_saturate;
|
||||
Fix32_peh Fix32_overflow_handler = Fix32_overflow_saturate;
|
||||
|
||||
Fix16_peh Fix16_range_error_handler = Fix16_warning;
|
||||
Fix32_peh Fix32_range_error_handler = Fix32_warning;
|
||||
|
||||
//function definitions
|
||||
|
||||
Fix16_peh set_Fix16_overflow_handler(Fix16_peh new_handler) {
|
||||
Fix16_peh old_handler = Fix16_overflow_handler;
|
||||
Fix16_overflow_handler = new_handler;
|
||||
return old_handler;
|
||||
}
|
||||
|
||||
Fix32_peh set_Fix32_overflow_handler(Fix32_peh new_handler) {
|
||||
Fix32_peh old_handler = Fix32_overflow_handler;
|
||||
Fix32_overflow_handler = new_handler;
|
||||
return old_handler;
|
||||
}
|
||||
|
||||
void set_overflow_handler(Fix16_peh handler16, Fix32_peh handler32) {
|
||||
set_Fix16_overflow_handler(handler16);
|
||||
set_Fix32_overflow_handler(handler32);
|
||||
}
|
||||
|
||||
Fix16_peh set_Fix16_range_error_handler(Fix16_peh new_handler) {
|
||||
Fix16_peh old_handler = Fix16_range_error_handler;
|
||||
Fix16_range_error_handler = new_handler;
|
||||
return old_handler;
|
||||
}
|
||||
|
||||
Fix32_peh set_Fix32_range_error_handler(Fix32_peh new_handler) {
|
||||
Fix32_peh old_handler = Fix32_range_error_handler;
|
||||
Fix32_range_error_handler = new_handler;
|
||||
return old_handler;
|
||||
}
|
||||
|
||||
void set_range_error_handler(Fix16_peh handler16, Fix32_peh handler32) {
|
||||
set_Fix16_range_error_handler(handler16);
|
||||
set_Fix32_range_error_handler(handler32);
|
||||
}
|
||||
|
||||
void Fix16_overflow_saturate(short& i)
|
||||
{ i = (i > 0 ? Fix16_m_min : Fix16_m_max); }
|
||||
void Fix16_ignore(short&) {}
|
||||
void Fix16_warning(short&)
|
||||
{ cerr << "warning: Fix16 result out of range\n"; }
|
||||
void Fix16_overflow_warning_saturate(short& i)
|
||||
{ cerr << "warning: Fix16 result out of range\n";
|
||||
Fix16_overflow_saturate(i); }
|
||||
void Fix16_abort(short&)
|
||||
{ cerr << "error: Fix16 result out of range\n"; abort(); }
|
||||
|
||||
void Fix32_ignore(_G_int32_t&) {}
|
||||
void Fix32_overflow_saturate(_G_int32_t& i)
|
||||
{ i = (i > 0 ? Fix32_m_min : Fix32_m_max); }
|
||||
void Fix32_warning(_G_int32_t&)
|
||||
{ cerr << "warning: Fix32 result out of range\n"; }
|
||||
void Fix32_overflow_warning_saturate(_G_int32_t& i)
|
||||
{ cerr << "warning: Fix32 result out of range\n";
|
||||
Fix32_overflow_saturate(i); }
|
||||
void Fix32_abort(_G_int32_t&)
|
||||
{ cerr << "error: Fix32 result out of range\n"; abort(); }
|
||||
|
||||
|
|
@ -1,329 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Kurt Baudendistel (gt-eedsp!baud@gatech.edu)
|
||||
adapted for libg++ by Doug Lea (dl@rocky.oswego.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
//
|
||||
// Fix24.cc : fixed precision class support functions
|
||||
//
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include <Fix24.h>
|
||||
|
||||
// basic operators too large to be inline
|
||||
|
||||
_G_int32_t Fix24::assign(double d)
|
||||
{
|
||||
if (d == 1.0)
|
||||
return Fix24_m_max;
|
||||
else if (d > Fix24_max)
|
||||
{
|
||||
_G_int32_t i = Fix24_m_max;
|
||||
range_error(i);
|
||||
return i;
|
||||
}
|
||||
else if (d < Fix24_min)
|
||||
{
|
||||
_G_int32_t i = Fix24_m_min;
|
||||
range_error(i);
|
||||
return i;
|
||||
}
|
||||
else {
|
||||
// Round to 24 bits
|
||||
d = (_G_int32_t) (d * (1 << 24) + ((d >= 0)? 0.5 : -0.5));
|
||||
/* Convert to integer format */
|
||||
return ((_G_int32_t) d) << (Fix24_shift - 24);
|
||||
}
|
||||
}
|
||||
|
||||
twolongs Fix48::assign(double d)
|
||||
{
|
||||
if (d == 1.0)
|
||||
return Fix48_m_max;
|
||||
else if (d > Fix48_max)
|
||||
{
|
||||
twolongs i = Fix48_m_max;
|
||||
range_error(i);
|
||||
return i;
|
||||
}
|
||||
else if (d < Fix48_min)
|
||||
{
|
||||
twolongs i = Fix48_m_min;
|
||||
range_error(i);
|
||||
return i;
|
||||
}
|
||||
else {
|
||||
twolongs i;
|
||||
int sign = (d < 0);
|
||||
|
||||
/* First, convert the absolute value of d to a 48-bit integer format */
|
||||
if (d < 0) d = -d;
|
||||
i.u = ((_G_int32_t)(d *= Fix24_mult)) & 0xffffff00;
|
||||
i.l = ((_G_uint32_t)((d - i.u)* (Fix24_mult / (1 << 7)))) & 0xffffff00;
|
||||
|
||||
/* Calculate the two's complement if d was negative */
|
||||
if (sign) {
|
||||
_G_uint32_t oldlower = i.l;
|
||||
i.l = (~i.l + 1) & 0xffffff00;
|
||||
i.u = (~i.u + (((oldlower ^ i.l) & Fix24_msb)? 0 : 1)) & ~0xffL;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Fix48 operator * (const Fix24& a, const Fix24& b)
|
||||
{
|
||||
// break a and b into lo and hi parts, and do a multiple-precision
|
||||
// multiply, with rounding
|
||||
|
||||
int apos = (a.m >= 0);
|
||||
_G_uint32_t ua = (apos)? a.m : - a.m;
|
||||
ua <<= 1; // ua is biased so result will be 47 bit mantissa, not 46:
|
||||
_G_uint32_t hi_a = (ua >> 16) & ((1 << 16) - 1);
|
||||
_G_uint32_t lo_a = ua & ((1 << 16) - 1);
|
||||
|
||||
int bpos = (b.m >= 0);
|
||||
_G_uint32_t ub = (bpos)? b.m : -b.m;
|
||||
_G_uint32_t hi_b = (ub >> 16) & ((1 << 16) - 1);
|
||||
_G_uint32_t lo_b = ub & ((1 << 16) - 1);
|
||||
|
||||
_G_uint32_t
|
||||
hi_r = hi_a * hi_b,
|
||||
mi_r = hi_a * lo_b + lo_a * hi_b,
|
||||
lo_r = lo_a * lo_b,
|
||||
rl = ((hi_r << 16) & 0x00ffffffL) + (mi_r & 0x00ffffffL) + (lo_r >> 16);
|
||||
twolongs r;
|
||||
r.u = (hi_r & 0xffffff00L) + ((mi_r >> 16) & 0x0000ff00L)
|
||||
+ ((rl >> 16) & 0x0000ff00L);
|
||||
r.l = rl << 8;
|
||||
|
||||
if ( apos != bpos ) {
|
||||
_G_uint32_t l = r.l;
|
||||
r.l = -r.l;
|
||||
r.u = (~r.u + ((l ^ r.l) & Fix24_msb ? 0 : Fix24_lsb)) & 0xffffff00;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
Fix24 operator / (const Fix24& a, const Fix24& b)
|
||||
{
|
||||
_G_int32_t q;
|
||||
int apos = (a.m >= 0);
|
||||
_G_uint32_t la = (apos)? a.m : -a.m;
|
||||
int bpos = (b.m >= 0);
|
||||
_G_uint32_t lb = (bpos)? b.m: -b.m;
|
||||
if (la >= lb)
|
||||
{
|
||||
q = (apos == bpos)? Fix24_m_max: Fix24_m_min;
|
||||
a.range_error(q);
|
||||
}
|
||||
else // standard shift-based division alg
|
||||
{
|
||||
q = 0;
|
||||
_G_int32_t r = la;
|
||||
|
||||
for (int i = 32; i > 0; i--)
|
||||
{
|
||||
if ((unsigned)(r) > lb) {
|
||||
q = (q << 1) | 1;
|
||||
r -= lb;
|
||||
}
|
||||
else
|
||||
q = (q << 1);
|
||||
r <<= 1;
|
||||
}
|
||||
|
||||
q += 0x80; // Round result to 24 bits
|
||||
if (apos != bpos) q = -q; // Fix sign
|
||||
}
|
||||
return (q & ~0xff);
|
||||
}
|
||||
|
||||
|
||||
Fix48 operator + (const Fix48& f, const Fix48& g)
|
||||
{
|
||||
_G_int32_t lo_r = (f.m.l >> 8) + (g.m.l >> 8);
|
||||
twolongs r;
|
||||
r.u = f.m.u + g.m.u + (lo_r & 0x01000000L ? 0x00000100L : 0);
|
||||
r.l = lo_r << 8;
|
||||
|
||||
if ( (f.m.u ^ r.u) & (g.m.u ^ r.u) & Fix24_msb )
|
||||
f.overflow(r);
|
||||
return r;
|
||||
}
|
||||
|
||||
Fix48 operator - (const Fix48& f, const Fix48& g)
|
||||
{
|
||||
unsigned lo_r = (f.m.l >> 8) - (g.m.l >> 8);
|
||||
twolongs r;
|
||||
r.u = f.m.u - g.m.u - (lo_r & 0x01000000L ? 0x00000100L: 0);
|
||||
r.l = lo_r << 8;
|
||||
|
||||
if ( ((f.m.u ^ r.u) & (-g.m.u ^ r.u) & Fix24_msb) && g.m.u )
|
||||
f.overflow(r);
|
||||
return r;
|
||||
}
|
||||
|
||||
Fix48 operator * (const Fix48& a, int b)
|
||||
{
|
||||
twolongs r;
|
||||
int bpos = (b >= 0);
|
||||
unsigned ub = (bpos)? b : -b;
|
||||
if ( ub >= 65536L ) {
|
||||
r = (bpos)? Fix48_m_max : Fix48_m_min;
|
||||
a.range_error(r);
|
||||
}
|
||||
else {
|
||||
_G_uint32_t
|
||||
lo_r = (a.m.l & 0xffff) * ub,
|
||||
mi_r = ((a.m.l >> 16) & 0xffff) * ub,
|
||||
hi_r = a.m.u * ub;
|
||||
r.l = lo_r + (mi_r << 16);
|
||||
r.u = hi_r + ((mi_r >> 8) & 0x00ffff00L);
|
||||
if ( !bpos ) {
|
||||
_G_uint32_t l = r.l;
|
||||
r.l = -r.l & 0xffffffff;
|
||||
r.u = ~r.u + ((l ^ r.l) & Fix24_msb ? 0 : Fix24_lsb);
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
Fix48 operator << (const Fix48& a, int b)
|
||||
{
|
||||
twolongs r; r.u = 0; r.l = 0;
|
||||
if ( b >= 0 )
|
||||
if ( b < 24 ) {
|
||||
r.u = (a.m.u << b) + ((a.m.l >> (24 - b)) & 0xffffff00L);
|
||||
r.l = a.m.l << b;
|
||||
}
|
||||
else if ( b < 48 ) {
|
||||
r.u = a.m.l << (b - 24);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
Fix48 operator >> (const Fix48& a, int b)
|
||||
{
|
||||
twolongs r; r.u = 0; r.l = 0;
|
||||
if ( b >= 0 )
|
||||
if ( b < 24 ) {
|
||||
r.l = ((a.m.u << (24 - b)) & 0xffffffffL) + ((a.m.l >> b) & 0xffffff00L);
|
||||
r.u = (a.m.u >> b) & ~0xffL;
|
||||
}
|
||||
else if ( b < 48 ) {
|
||||
r.l = (a.m.u >> (b - 24)) & 0xffffff00L;
|
||||
r.u = (a.m.u >> 24) & ~0xffL;
|
||||
}
|
||||
else {
|
||||
r.l = (a.m.u >> 24) & ~0xffL;
|
||||
r.u = r.l;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
// error handling
|
||||
|
||||
void Fix24::overflow(_G_int32_t& i) const
|
||||
{
|
||||
(*Fix24_overflow_handler)(i);
|
||||
}
|
||||
|
||||
void Fix48::overflow(twolongs& i) const
|
||||
{
|
||||
(*Fix48_overflow_handler)(i);
|
||||
}
|
||||
|
||||
void Fix24::range_error(_G_int32_t& i) const
|
||||
{
|
||||
(*Fix24_range_error_handler)(i);
|
||||
}
|
||||
|
||||
void Fix48::range_error(twolongs& i) const
|
||||
{
|
||||
(*Fix48_range_error_handler)(i);
|
||||
}
|
||||
|
||||
// data definitions
|
||||
|
||||
Fix24_peh Fix24_overflow_handler = Fix24_overflow_saturate;
|
||||
Fix48_peh Fix48_overflow_handler = Fix48_overflow_saturate;
|
||||
|
||||
Fix24_peh Fix24_range_error_handler = Fix24_warning;
|
||||
Fix48_peh Fix48_range_error_handler = Fix48_warning;
|
||||
|
||||
//function definitions
|
||||
|
||||
Fix24_peh set_Fix24_overflow_handler(Fix24_peh new_handler) {
|
||||
Fix24_peh old_handler = Fix24_overflow_handler;
|
||||
Fix24_overflow_handler = new_handler;
|
||||
return old_handler;
|
||||
}
|
||||
|
||||
Fix48_peh set_Fix48_overflow_handler(Fix48_peh new_handler) {
|
||||
Fix48_peh old_handler = Fix48_overflow_handler;
|
||||
Fix48_overflow_handler = new_handler;
|
||||
return old_handler;
|
||||
}
|
||||
|
||||
void set_overflow_handler(Fix24_peh handler24, Fix48_peh handler48) {
|
||||
set_Fix24_overflow_handler(handler24);
|
||||
set_Fix48_overflow_handler(handler48);
|
||||
}
|
||||
|
||||
Fix24_peh set_Fix24_range_error_handler(Fix24_peh new_handler) {
|
||||
Fix24_peh old_handler = Fix24_range_error_handler;
|
||||
Fix24_range_error_handler = new_handler;
|
||||
return old_handler;
|
||||
}
|
||||
|
||||
Fix48_peh set_Fix48_range_error_handler(Fix48_peh new_handler) {
|
||||
Fix48_peh old_handler = Fix48_range_error_handler;
|
||||
Fix48_range_error_handler = new_handler;
|
||||
return old_handler;
|
||||
}
|
||||
|
||||
void set_range_error_handler(Fix24_peh handler24, Fix48_peh handler48) {
|
||||
set_Fix24_range_error_handler(handler24);
|
||||
set_Fix48_range_error_handler(handler48);
|
||||
}
|
||||
|
||||
void Fix24_overflow_saturate(_G_int32_t& i)
|
||||
{ i = (i > 0 ? Fix24_m_min : Fix24_m_max); }
|
||||
void Fix24_ignore(_G_int32_t&) {}
|
||||
void Fix24_warning(_G_int32_t&)
|
||||
{ cerr << "warning: Fix24 result out of range\n"; }
|
||||
void Fix24_overflow_warning_saturate(_G_int32_t& i)
|
||||
{ cerr << "warning: Fix24 result out of range\n";
|
||||
Fix24_overflow_saturate(i); }
|
||||
void Fix24_abort(_G_int32_t&)
|
||||
{ cerr << "error: Fix24 result out of range\n"; abort(); }
|
||||
|
||||
void Fix48_ignore(twolongs&) {}
|
||||
void Fix48_overflow_saturate(twolongs& i)
|
||||
{ i = (i.u > 0 ? Fix48_m_min : Fix48_m_max); }
|
||||
void Fix48_warning(twolongs&)
|
||||
{ cerr << "warning: Fix48 result out of range\n"; }
|
||||
void Fix48_overflow_warning_saturate(twolongs& i)
|
||||
{ cerr << "warning: Fix48 result out of range\n";
|
||||
Fix48_overflow_saturate(i); }
|
||||
void Fix48_abort(twolongs&)
|
||||
{ cerr << "error: Fix48 result out of range\n"; abort(); }
|
||||
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Dirk Grunwald (grunwald@cs.uiuc.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include <builtin.h>
|
||||
#include <Random.h>
|
||||
#include <Geom.h>
|
||||
|
||||
double Geometric::operator()()
|
||||
{
|
||||
int samples;
|
||||
for (samples = 1; pGenerator -> asDouble() < pMean; samples++);
|
||||
return((double) samples);
|
||||
}
|
||||
|
||||
|
|
@ -1,253 +0,0 @@
|
|||
/*
|
||||
Getopt for GNU.
|
||||
Copyright (C) 1987, 1989 Free Software Foundation, Inc.
|
||||
|
||||
(Modified by Douglas C. Schmidt for use with GNU G++.)
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
/* AIX requires the alloca decl to be the first thing in the file. */
|
||||
#ifdef __GNUC__
|
||||
#define alloca __builtin_alloca
|
||||
#elif defined(sparc)
|
||||
#include <alloca.h>
|
||||
extern "C" void *__builtin_alloca(...);
|
||||
#elif defined(_AIX)
|
||||
#pragma alloca
|
||||
#else
|
||||
char *alloca ();
|
||||
#endif
|
||||
#include <GetOpt.h>
|
||||
|
||||
char* GetOpt::nextchar = 0;
|
||||
int GetOpt::first_nonopt = 0;
|
||||
int GetOpt::last_nonopt = 0;
|
||||
|
||||
GetOpt::GetOpt (int argc, char **argv, const char *optstring)
|
||||
:opterr (1), nargc (argc), nargv (argv), noptstring (optstring)
|
||||
{
|
||||
/* Initialize the internal data when the first call is made.
|
||||
Start processing options with ARGV-element 1 (since ARGV-element 0
|
||||
is the program name); the sequence of previously skipped
|
||||
non-option ARGV-elements is empty. */
|
||||
|
||||
first_nonopt = last_nonopt = optind = 1;
|
||||
optarg = nextchar = 0;
|
||||
|
||||
/* Determine how to handle the ordering of options and nonoptions. */
|
||||
|
||||
if (optstring[0] == '-')
|
||||
ordering = RETURN_IN_ORDER;
|
||||
else if (getenv ("_POSIX_OPTION_ORDER") != 0)
|
||||
ordering = REQUIRE_ORDER;
|
||||
else
|
||||
ordering = PERMUTE;
|
||||
}
|
||||
|
||||
void
|
||||
GetOpt::exchange (char **argv)
|
||||
{
|
||||
int nonopts_size
|
||||
= (last_nonopt - first_nonopt) * sizeof (char *);
|
||||
char **temp = (char **) alloca (nonopts_size);
|
||||
|
||||
/* Interchange the two blocks of data in argv. */
|
||||
|
||||
memcpy (temp, &argv[first_nonopt], nonopts_size);
|
||||
memcpy (&argv[first_nonopt], &argv[last_nonopt],
|
||||
(optind - last_nonopt) * sizeof (char *));
|
||||
memcpy (&argv[first_nonopt + optind - last_nonopt], temp,
|
||||
nonopts_size);
|
||||
|
||||
/* Update records for the slots the non-options now occupy. */
|
||||
|
||||
first_nonopt += (optind - last_nonopt);
|
||||
last_nonopt = optind;
|
||||
}
|
||||
|
||||
/* Scan elements of ARGV (whose length is ARGC) for option characters
|
||||
given in OPTSTRING.
|
||||
|
||||
If an element of ARGV starts with '-', and is not exactly "-" or "--",
|
||||
then it is an option element. The characters of this element
|
||||
(aside from the initial '-') are option characters. If `getopt'
|
||||
is called repeatedly, it returns successively each of theoption characters
|
||||
from each of the option elements.
|
||||
|
||||
If `getopt' finds another option character, it returns that character,
|
||||
updating `optind' and `nextchar' so that the next call to `getopt' can
|
||||
resume the scan with the following option character or ARGV-element.
|
||||
|
||||
If there are no more option characters, `getopt' returns `EOF'.
|
||||
Then `optind' is the index in ARGV of the first ARGV-element
|
||||
that is not an option. (The ARGV-elements have been permuted
|
||||
so that those that are not options now come last.)
|
||||
|
||||
OPTSTRING is a string containing the legitimate option characters.
|
||||
A colon in OPTSTRING means that the previous character is an option
|
||||
that wants an argument. The argument is taken from the rest of the
|
||||
current ARGV-element, or from the following ARGV-element,
|
||||
and returned in `optarg'.
|
||||
|
||||
If an option character is seen that is not listed in OPTSTRING,
|
||||
return '?' after printing an error message. If you set `opterr' to
|
||||
zero, the error message is suppressed but we still return '?'.
|
||||
|
||||
If a char in OPTSTRING is followed by a colon, that means it wants an arg,
|
||||
so the following text in the same ARGV-element, or the text of the following
|
||||
ARGV-element, is returned in `optarg. Two colons mean an option that
|
||||
wants an optional arg; if there is text in the current ARGV-element,
|
||||
it is returned in `optarg'.
|
||||
|
||||
If OPTSTRING starts with `-', it requests a different method of handling the
|
||||
non-option ARGV-elements. See the comments about RETURN_IN_ORDER, above. */
|
||||
|
||||
int
|
||||
GetOpt::operator () (void)
|
||||
{
|
||||
if (nextchar == 0 || *nextchar == 0)
|
||||
{
|
||||
if (ordering == PERMUTE)
|
||||
{
|
||||
/* If we have just processed some options following some non-options,
|
||||
exchange them so that the options come first. */
|
||||
|
||||
if (first_nonopt != last_nonopt && last_nonopt != optind)
|
||||
exchange (nargv);
|
||||
else if (last_nonopt != optind)
|
||||
first_nonopt = optind;
|
||||
|
||||
/* Now skip any additional non-options
|
||||
and extend the range of non-options previously skipped. */
|
||||
|
||||
while (optind < nargc
|
||||
&& (nargv[optind][0] != '-'
|
||||
|| nargv[optind][1] == 0))
|
||||
optind++;
|
||||
last_nonopt = optind;
|
||||
}
|
||||
|
||||
/* Special ARGV-element `--' means premature end of options.
|
||||
Skip it like a null option,
|
||||
then exchange with previous non-options as if it were an option,
|
||||
then skip everything else like a non-option. */
|
||||
|
||||
if (optind != nargc && !strcmp (nargv[optind], "--"))
|
||||
{
|
||||
optind++;
|
||||
|
||||
if (first_nonopt != last_nonopt && last_nonopt != optind)
|
||||
exchange (nargv);
|
||||
else if (first_nonopt == last_nonopt)
|
||||
first_nonopt = optind;
|
||||
last_nonopt = nargc;
|
||||
|
||||
optind = nargc;
|
||||
}
|
||||
|
||||
/* If we have done all the ARGV-elements, stop the scan
|
||||
and back over any non-options that we skipped and permuted. */
|
||||
|
||||
if (optind == nargc)
|
||||
{
|
||||
/* Set the next-arg-index to point at the non-options
|
||||
that we previously skipped, so the caller will digest them. */
|
||||
if (first_nonopt != last_nonopt)
|
||||
optind = first_nonopt;
|
||||
return EOF;
|
||||
}
|
||||
|
||||
/* If we have come to a non-option and did not permute it,
|
||||
either stop the scan or describe it to the caller and pass it by. */
|
||||
|
||||
if (nargv[optind][0] != '-' || nargv[optind][1] == 0)
|
||||
{
|
||||
if (ordering == REQUIRE_ORDER)
|
||||
return EOF;
|
||||
optarg = nargv[optind++];
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* We have found another option-ARGV-element.
|
||||
Start decoding its characters. */
|
||||
|
||||
nextchar = nargv[optind] + 1;
|
||||
}
|
||||
|
||||
/* Look at and handle the next option-character. */
|
||||
|
||||
{
|
||||
char c = *nextchar++;
|
||||
char *temp = (char *) strchr (noptstring, c);
|
||||
|
||||
/* Increment `optind' when we start to process its last character. */
|
||||
if (*nextchar == 0)
|
||||
optind++;
|
||||
|
||||
if (temp == 0 || c == ':')
|
||||
{
|
||||
if (opterr != 0)
|
||||
{
|
||||
if (c < 040 || c >= 0177)
|
||||
fprintf (stderr, "%s: unrecognized option, character code 0%o\n",
|
||||
nargv[0], c);
|
||||
else
|
||||
fprintf (stderr, "%s: unrecognized option `-%c'\n",
|
||||
nargv[0], c);
|
||||
}
|
||||
return '?';
|
||||
}
|
||||
if (temp[1] == ':')
|
||||
{
|
||||
if (temp[2] == ':')
|
||||
{
|
||||
/* This is an option that accepts an argument optionally. */
|
||||
if (*nextchar != 0)
|
||||
{
|
||||
optarg = nextchar;
|
||||
optind++;
|
||||
}
|
||||
else
|
||||
optarg = 0;
|
||||
nextchar = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* This is an option that requires an argument. */
|
||||
if (*nextchar != 0)
|
||||
{
|
||||
optarg = nextchar;
|
||||
/* If we end this ARGV-element by taking the rest as an arg,
|
||||
we must advance to the next element now. */
|
||||
optind++;
|
||||
}
|
||||
else if (optind == nargc)
|
||||
{
|
||||
if (opterr != 0)
|
||||
fprintf (stderr, "%s: no argument for `-%c' option\n",
|
||||
nargv[0], c);
|
||||
c = '?';
|
||||
}
|
||||
else
|
||||
/* We already incremented `optind' once;
|
||||
increment it again when taking next ARGV-elt as argument. */
|
||||
optarg = nargv[optind++];
|
||||
nextchar = 0;
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Dirk Grunwald (grunwald@cs.uiuc.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include <builtin.h>
|
||||
#include <Random.h>
|
||||
#include <HypGeom.h>
|
||||
|
||||
double HyperGeometric::operator()()
|
||||
{
|
||||
double d = (pGenerator -> asDouble() > pP) ? (1.0 - pP) : (pP);
|
||||
return(-pMean * log(pGenerator -> asDouble()) / (2.0 * d) );
|
||||
}
|
||||
|
||||
|
|
@ -1,142 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 1988, 1993 Free Software Foundation
|
||||
written by Doug Lea (dl@rocky.oswego.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
// Routines for converting between Integers and doubles.
|
||||
// Split up into a separate file to avoid Integer.o's need
|
||||
// for libm.a on some systems (including SunOS 4).
|
||||
|
||||
#include <Integer.h>
|
||||
#include "Integer.hP"
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <limits.h>
|
||||
|
||||
#ifndef HUGE_VAL
|
||||
#ifdef HUGE
|
||||
#define HUGE_VAL HUGE
|
||||
#else
|
||||
#define HUGE_VAL DBL_MAX
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// convert to a double
|
||||
|
||||
double Itodouble(const IntRep* rep)
|
||||
{
|
||||
double d = 0.0;
|
||||
double bound = DBL_MAX / 2.0;
|
||||
for (int i = rep->len - 1; i >= 0; --i)
|
||||
{
|
||||
unsigned short a = I_RADIX >> 1;
|
||||
while (a != 0)
|
||||
{
|
||||
if (d >= bound)
|
||||
return (rep->sgn == I_NEGATIVE) ? -HUGE_VAL : HUGE_VAL;
|
||||
d *= 2.0;
|
||||
if (rep->s[i] & a)
|
||||
d += 1.0;
|
||||
a >>= 1;
|
||||
}
|
||||
}
|
||||
if (rep->sgn == I_NEGATIVE)
|
||||
return -d;
|
||||
else
|
||||
return d;
|
||||
}
|
||||
|
||||
// see whether op double() will work-
|
||||
// have to actually try it in order to find out
|
||||
// since otherwise might trigger fp exception
|
||||
|
||||
int Iisdouble(const IntRep* rep)
|
||||
{
|
||||
double d = 0.0;
|
||||
double bound = DBL_MAX / 2.0;
|
||||
for (int i = rep->len - 1; i >= 0; --i)
|
||||
{
|
||||
unsigned short a = I_RADIX >> 1;
|
||||
while (a != 0)
|
||||
{
|
||||
if (d > bound || (d == bound && (i > 0 || (rep->s[i] & a))))
|
||||
return 0;
|
||||
d *= 2.0;
|
||||
if (rep->s[i] & a)
|
||||
d += 1.0;
|
||||
a >>= 1;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// real division of num / den
|
||||
|
||||
double ratio(const Integer& num, const Integer& den)
|
||||
{
|
||||
Integer q, r;
|
||||
divide(num, den, q, r);
|
||||
double d1 = q.as_double();
|
||||
|
||||
if (d1 >= DBL_MAX || d1 <= -DBL_MAX || sign(r) == 0)
|
||||
return d1;
|
||||
else // use as much precision as available for fractional part
|
||||
{
|
||||
double d2 = 0.0;
|
||||
double d3 = 0.0;
|
||||
int cont = 1;
|
||||
for (int i = den.rep->len - 1; i >= 0 && cont; --i)
|
||||
{
|
||||
unsigned short a = I_RADIX >> 1;
|
||||
while (a != 0)
|
||||
{
|
||||
if (d2 + 1.0 == d2) // out of precision when we get here
|
||||
{
|
||||
cont = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
d2 *= 2.0;
|
||||
if (den.rep->s[i] & a)
|
||||
d2 += 1.0;
|
||||
|
||||
if (i < r.rep->len)
|
||||
{
|
||||
d3 *= 2.0;
|
||||
if (r.rep->s[i] & a)
|
||||
d3 += 1.0;
|
||||
}
|
||||
|
||||
a >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (sign(r) < 0)
|
||||
d3 = -d3;
|
||||
return d1 + d3 / d2;
|
||||
}
|
||||
}
|
||||
|
||||
double
|
||||
Integer::as_double () const
|
||||
{
|
||||
return Itodouble (rep);
|
||||
}
|
||||
|
||||
int
|
||||
Integer::fits_in_double () const
|
||||
{
|
||||
return Iisdouble(rep);
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Dirk Grunwald (grunwald@cs.uiuc.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include <builtin.h>
|
||||
#include <Random.h>
|
||||
#include <Normal.h>
|
||||
|
||||
#include <LogNorm.h>
|
||||
|
||||
//
|
||||
// See Simulation, Modelling & Analysis by Law & Kelton, pp260
|
||||
//
|
||||
//
|
||||
|
||||
double LogNormal::operator()()
|
||||
{
|
||||
return exp (this->Normal::operator()() );
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,103 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1989 Free Software Foundation
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include <MLCG.h>
|
||||
//
|
||||
// SEED_TABLE_SIZE must be a power of 2
|
||||
//
|
||||
|
||||
|
||||
#define SEED_TABLE_SIZE 32
|
||||
|
||||
static _G_int32_t seedTable[SEED_TABLE_SIZE] = {
|
||||
0xbdcc47e5, 0x54aea45d, 0xec0df859, 0xda84637b,
|
||||
0xc8c6cb4f, 0x35574b01, 0x28260b7d, 0x0d07fdbf,
|
||||
0x9faaeeb0, 0x613dd169, 0x5ce2d818, 0x85b9e706,
|
||||
0xab2469db, 0xda02b0dc, 0x45c60d6e, 0xffe49d10,
|
||||
0x7224fea3, 0xf9684fc9, 0xfc7ee074, 0x326ce92a,
|
||||
0x366d13b5, 0x17aaa731, 0xeb83a675, 0x7781cb32,
|
||||
0x4ec7c92d, 0x7f187521, 0x2cf346b4, 0xad13310f,
|
||||
0xb89cff2b, 0x12164de1, 0xa865168d, 0x32b56cdf
|
||||
};
|
||||
|
||||
MLCG::MLCG(_G_int32_t seed1, _G_int32_t seed2)
|
||||
{
|
||||
initialSeedOne = seed1;
|
||||
initialSeedTwo = seed2;
|
||||
reset();
|
||||
}
|
||||
|
||||
void
|
||||
MLCG::reset()
|
||||
{
|
||||
_G_int32_t seed1 = initialSeedOne;
|
||||
_G_int32_t seed2 = initialSeedTwo;
|
||||
|
||||
//
|
||||
// Most people pick stupid seed numbers that do not have enough
|
||||
// bits. In this case, if they pick a small seed number, we
|
||||
// map that to a specific seed.
|
||||
//
|
||||
if (seed1 < 0) {
|
||||
seed1 = (seed1 + 2147483561);
|
||||
seed1 = (seed1 < 0) ? -seed1 : seed1;
|
||||
}
|
||||
|
||||
if (seed2 < 0) {
|
||||
seed2 = (seed2 + 2147483561);
|
||||
seed2 = (seed2 < 0) ? -seed2 : seed2;
|
||||
}
|
||||
|
||||
if (seed1 > -1 && seed1 < SEED_TABLE_SIZE) {
|
||||
seedOne = seedTable[seed1];
|
||||
} else {
|
||||
seedOne = seed1 ^ seedTable[seed1 & (SEED_TABLE_SIZE-1)];
|
||||
}
|
||||
|
||||
if (seed2 > -1 && seed2 < SEED_TABLE_SIZE) {
|
||||
seedTwo = seedTable[seed2];
|
||||
} else {
|
||||
seedTwo = seed2 ^ seedTable[ seed2 & (SEED_TABLE_SIZE-1) ];
|
||||
}
|
||||
seedOne = (seedOne % 2147483561) + 1;
|
||||
seedTwo = (seedTwo % 2147483397) + 1;
|
||||
}
|
||||
|
||||
_G_uint32_t MLCG::asLong()
|
||||
{
|
||||
_G_int32_t k = seedOne % 53668;
|
||||
|
||||
seedOne = 40014 * (seedOne-k * 53668) - k * 12211;
|
||||
if (seedOne < 0) {
|
||||
seedOne += 2147483563;
|
||||
}
|
||||
|
||||
k = seedTwo % 52774;
|
||||
seedTwo = 40692 * (seedTwo - k * 52774) - k * 3791;
|
||||
if (seedTwo < 0) {
|
||||
seedTwo += 2147483399;
|
||||
}
|
||||
|
||||
_G_int32_t z = seedOne - seedTwo;
|
||||
if (z < 1) {
|
||||
z += 2147483562;
|
||||
}
|
||||
return( (unsigned long) z);
|
||||
}
|
||||
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Dirk Grunwald (grunwald@cs.uiuc.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include <builtin.h>
|
||||
#include <Random.h>
|
||||
#include <NegExp.h>
|
||||
|
||||
double NegativeExpntl::operator()()
|
||||
{
|
||||
return(-pMean * log(pGenerator -> asDouble()));
|
||||
}
|
||||
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Dirk Grunwald (grunwald@cs.uiuc.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include <builtin.h>
|
||||
#include <Random.h>
|
||||
#include <Normal.h>
|
||||
//
|
||||
// See Simulation, Modelling & Analysis by Law & Kelton, pp259
|
||||
//
|
||||
// This is the ``polar'' method.
|
||||
//
|
||||
|
||||
double Normal::operator()()
|
||||
{
|
||||
|
||||
if (haveCachedNormal == 1) {
|
||||
haveCachedNormal = 0;
|
||||
return(cachedNormal * pStdDev + pMean );
|
||||
} else {
|
||||
|
||||
for(;;) {
|
||||
double u1 = pGenerator -> asDouble();
|
||||
double u2 = pGenerator -> asDouble();
|
||||
double v1 = 2 * u1 - 1;
|
||||
double v2 = 2 * u2 - 1;
|
||||
double w = (v1 * v1) + (v2 * v2);
|
||||
|
||||
//
|
||||
// We actually generate two IID normal distribution variables.
|
||||
// We cache the one & return the other.
|
||||
//
|
||||
if (w <= 1) {
|
||||
double y = sqrt( (-2 * log(w)) / w);
|
||||
double x1 = v1 * y;
|
||||
double x2 = v2 * y;
|
||||
|
||||
haveCachedNormal = 1;
|
||||
cachedNormal = x2;
|
||||
return(x1 * pStdDev + pMean);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,125 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Doug Lea (dl@rocky.oswego.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include <limits.h>
|
||||
#include <builtin.h>
|
||||
#include <Obstack.h>
|
||||
|
||||
/* We use subtraction of (char *)0 instead of casting to int
|
||||
because on word-addressable machines a simple cast to int
|
||||
may ignore the byte-within-word field of the pointer. */
|
||||
|
||||
#ifndef __PTR_TO_INT
|
||||
#define __PTR_TO_INT(P) ((P) - (char *)0)
|
||||
#endif
|
||||
|
||||
#ifndef __INT_TO_PTR
|
||||
#define __INT_TO_PTR(P) ((P) + (char *)0)
|
||||
#endif
|
||||
|
||||
Obstack::Obstack(int size, int alignment)
|
||||
{
|
||||
alignmentmask = alignment - 1;
|
||||
chunksize = size;
|
||||
chunk = 0;
|
||||
nextfree = objectbase = 0;
|
||||
chunklimit = 0;
|
||||
}
|
||||
|
||||
void Obstack::_free(void* obj)
|
||||
{
|
||||
_obstack_chunk* lp;
|
||||
_obstack_chunk* plp;
|
||||
|
||||
lp = chunk;
|
||||
while (lp != 0 && ((void*)lp > obj || (void*)(lp)->limit < obj))
|
||||
{
|
||||
plp = lp -> prev;
|
||||
delete [] (char*)lp;
|
||||
lp = plp;
|
||||
}
|
||||
if (lp)
|
||||
{
|
||||
objectbase = nextfree = (char *)(obj);
|
||||
chunklimit = lp->limit;
|
||||
chunk = lp;
|
||||
}
|
||||
else if (obj != 0)
|
||||
(*lib_error_handler)("Obstack", "deletion of nonexistent obj");
|
||||
}
|
||||
|
||||
void Obstack::newchunk(int size)
|
||||
{
|
||||
_obstack_chunk* old_chunk = chunk;
|
||||
_obstack_chunk* new_chunk;
|
||||
long new_size;
|
||||
int obj_size = nextfree - objectbase;
|
||||
|
||||
new_size = (obj_size + size) << 1;
|
||||
if (new_size < chunksize)
|
||||
new_size = chunksize;
|
||||
|
||||
new_chunk = chunk = (_obstack_chunk*)(new char[new_size]);
|
||||
new_chunk->prev = old_chunk;
|
||||
new_chunk->limit = chunklimit = (char *) new_chunk + new_size;
|
||||
|
||||
memcpy((void*)new_chunk->contents, (void*)objectbase, obj_size);
|
||||
objectbase = new_chunk->contents;
|
||||
nextfree = objectbase + obj_size;
|
||||
}
|
||||
|
||||
void* Obstack::finish()
|
||||
{
|
||||
void* value = (void*) objectbase;
|
||||
nextfree = __INT_TO_PTR (__PTR_TO_INT (nextfree + alignmentmask)
|
||||
& ~alignmentmask);
|
||||
if (nextfree - (char*)chunk > chunklimit - (char*)chunk)
|
||||
nextfree = chunklimit;
|
||||
objectbase = nextfree;
|
||||
return value;
|
||||
}
|
||||
|
||||
int Obstack::contains(void* obj) // true if obj somewhere in Obstack
|
||||
{
|
||||
for (_obstack_chunk* ch = chunk;
|
||||
ch != 0 && (obj < (void*)ch || obj >= (void*)(ch->limit));
|
||||
ch = ch->prev);
|
||||
|
||||
return ch != 0;
|
||||
}
|
||||
|
||||
int Obstack::OK()
|
||||
{
|
||||
int v = chunksize > 0; // valid size
|
||||
v &= alignmentmask != 0; // and alignment
|
||||
v &= chunk != 0;
|
||||
v &= objectbase >= chunk->contents;
|
||||
v &= nextfree >= objectbase;
|
||||
v &= nextfree <= chunklimit;
|
||||
v &= chunklimit == chunk->limit;
|
||||
_obstack_chunk* p = chunk;
|
||||
// allow lots of chances to find bottom!
|
||||
long x = LONG_MAX;
|
||||
while (p != 0 && x != 0) { --x; p = p->prev; }
|
||||
v &= x > 0;
|
||||
if (!v)
|
||||
(*lib_error_handler)("Obstack", "invariant failure");
|
||||
return v;
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
|
||||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Dirk Grunwald (grunwald@cs.uiuc.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include <builtin.h>
|
||||
#include <Random.h>
|
||||
#include <Poisson.h>
|
||||
|
||||
double Poisson::operator()()
|
||||
{
|
||||
double bound = exp(-1.0 * pMean);
|
||||
int count = 0;
|
||||
|
||||
for (double product = 1.0;
|
||||
product >= bound;
|
||||
product *= pGenerator -> asDouble()) {
|
||||
count++;
|
||||
}
|
||||
return(count - 1);
|
||||
}
|
||||
|
|
@ -1,131 +0,0 @@
|
|||
// This may look like C code, but it is really -*- C++ -*-
|
||||
/*
|
||||
Copyright (C) 1989 Free Software Foundation
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include <assert.h>
|
||||
#include <builtin.h>
|
||||
#include <RNG.h>
|
||||
|
||||
// These two static fields get initialized by RNG::RNG().
|
||||
PrivateRNGSingleType RNG::singleMantissa;
|
||||
PrivateRNGDoubleType RNG::doubleMantissa;
|
||||
|
||||
//
|
||||
// The scale constant is 2^-31. It is used to scale a 31 bit
|
||||
// long to a double.
|
||||
//
|
||||
|
||||
//static const double randomDoubleScaleConstant = 4.656612873077392578125e-10;
|
||||
//static const float randomFloatScaleConstant = 4.656612873077392578125e-10;
|
||||
|
||||
static char initialized = 0;
|
||||
|
||||
RNG::RNG()
|
||||
{
|
||||
if (!initialized)
|
||||
{
|
||||
|
||||
assert (sizeof(double) == 2 * sizeof(_G_uint32_t));
|
||||
|
||||
//
|
||||
// The following is a hack that I attribute to
|
||||
// Andres Nowatzyk at CMU. The intent of the loop
|
||||
// is to form the smallest number 0 <= x < 1.0,
|
||||
// which is then used as a mask for two longwords.
|
||||
// this gives us a fast way way to produce double
|
||||
// precision numbers from longwords.
|
||||
//
|
||||
// I know that this works for IEEE and VAX floating
|
||||
// point representations.
|
||||
//
|
||||
// A further complication is that gnu C will blow
|
||||
// the following loop, unless compiled with -ffloat-store,
|
||||
// because it uses extended representations for some of
|
||||
// of the comparisons. Thus, we have the following hack.
|
||||
// If we could specify #pragma optimize, we wouldn't need this.
|
||||
//
|
||||
|
||||
PrivateRNGDoubleType t;
|
||||
PrivateRNGSingleType s;
|
||||
|
||||
#if _IEEE == 1
|
||||
|
||||
t.d = 1.5;
|
||||
if ( t.u[1] == 0 ) { // sun word order?
|
||||
t.u[0] = 0x3fffffff;
|
||||
t.u[1] = 0xffffffff;
|
||||
}
|
||||
else {
|
||||
t.u[0] = 0xffffffff; // encore word order?
|
||||
t.u[1] = 0x3fffffff;
|
||||
}
|
||||
|
||||
s.u = 0x3fffffff;
|
||||
#else
|
||||
volatile double x = 1.0; // volatile needed when fp hardware used,
|
||||
// and has greater precision than memory doubles
|
||||
double y = 0.5;
|
||||
do { // find largest fp-number < 2.0
|
||||
t.d = x;
|
||||
x += y;
|
||||
y *= 0.5;
|
||||
} while (x != t.d && x < 2.0);
|
||||
|
||||
volatile float xx = 1.0; // volatile needed when fp hardware used,
|
||||
// and has greater precision than memory floats
|
||||
float yy = 0.5;
|
||||
do { // find largest fp-number < 2.0
|
||||
s.s = xx;
|
||||
xx += yy;
|
||||
yy *= 0.5;
|
||||
} while (xx != s.s && xx < 2.0);
|
||||
#endif
|
||||
// set doubleMantissa to 1 for each doubleMantissa bit
|
||||
doubleMantissa.d = 1.0;
|
||||
doubleMantissa.u[0] ^= t.u[0];
|
||||
doubleMantissa.u[1] ^= t.u[1];
|
||||
|
||||
// set singleMantissa to 1 for each singleMantissa bit
|
||||
singleMantissa.s = 1.0;
|
||||
singleMantissa.u ^= s.u;
|
||||
|
||||
initialized = 1;
|
||||
}
|
||||
}
|
||||
|
||||
float RNG::asFloat()
|
||||
{
|
||||
PrivateRNGSingleType result;
|
||||
result.s = 1.0;
|
||||
result.u |= (asLong() & singleMantissa.u);
|
||||
result.s -= 1.0;
|
||||
assert( result.s < 1.0 && result.s >= 0);
|
||||
return( result.s );
|
||||
}
|
||||
|
||||
double RNG::asDouble()
|
||||
{
|
||||
PrivateRNGDoubleType result;
|
||||
result.d = 1.0;
|
||||
result.u[0] |= (asLong() & doubleMantissa.u[0]);
|
||||
result.u[1] |= (asLong() & doubleMantissa.u[1]);
|
||||
result.d -= 1.0;
|
||||
assert( result.d < 1.0 && result.d >= 0);
|
||||
return( result.d );
|
||||
}
|
||||
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include <Random.h>
|
||||
|
|
@ -1,414 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Doug Lea (dl@rocky.oswego.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include <Rational.h>
|
||||
#include <std.h>
|
||||
#include <math.h>
|
||||
#include <builtin.h>
|
||||
#include <float.h>
|
||||
|
||||
void Rational::error(const char* msg) const
|
||||
{
|
||||
(*lib_error_handler)("Rational", msg);
|
||||
}
|
||||
|
||||
static const Integer _Int_One(1);
|
||||
|
||||
void Rational::normalize()
|
||||
{
|
||||
int s = sign(den);
|
||||
if (s == 0)
|
||||
error("Zero denominator.");
|
||||
else if (s < 0)
|
||||
{
|
||||
den.negate();
|
||||
num.negate();
|
||||
}
|
||||
|
||||
Integer g = gcd(num, den);
|
||||
if (ucompare(g, _Int_One) != 0)
|
||||
{
|
||||
num /= g;
|
||||
den /= g;
|
||||
}
|
||||
}
|
||||
|
||||
void add(const Rational& x, const Rational& y, Rational& r)
|
||||
{
|
||||
if (&r != &x && &r != &y)
|
||||
{
|
||||
mul(x.num, y.den, r.num);
|
||||
mul(x.den, y.num, r.den);
|
||||
add(r.num, r.den, r.num);
|
||||
mul(x.den, y.den, r.den);
|
||||
}
|
||||
else
|
||||
{
|
||||
Integer tmp;
|
||||
mul(x.den, y.num, tmp);
|
||||
mul(x.num, y.den, r.num);
|
||||
add(r.num, tmp, r.num);
|
||||
mul(x.den, y.den, r.den);
|
||||
}
|
||||
r.normalize();
|
||||
}
|
||||
|
||||
void sub(const Rational& x, const Rational& y, Rational& r)
|
||||
{
|
||||
if (&r != &x && &r != &y)
|
||||
{
|
||||
mul(x.num, y.den, r.num);
|
||||
mul(x.den, y.num, r.den);
|
||||
sub(r.num, r.den, r.num);
|
||||
mul(x.den, y.den, r.den);
|
||||
}
|
||||
else
|
||||
{
|
||||
Integer tmp;
|
||||
mul(x.den, y.num, tmp);
|
||||
mul(x.num, y.den, r.num);
|
||||
sub(r.num, tmp, r.num);
|
||||
mul(x.den, y.den, r.den);
|
||||
}
|
||||
r.normalize();
|
||||
}
|
||||
|
||||
void mul(const Rational& x, const Rational& y, Rational& r)
|
||||
{
|
||||
mul(x.num, y.num, r.num);
|
||||
mul(x.den, y.den, r.den);
|
||||
r.normalize();
|
||||
}
|
||||
|
||||
void div(const Rational& x, const Rational& y, Rational& r)
|
||||
{
|
||||
if (&r != &x && &r != &y)
|
||||
{
|
||||
mul(x.num, y.den, r.num);
|
||||
mul(x.den, y.num, r.den);
|
||||
}
|
||||
else
|
||||
{
|
||||
Integer tmp;
|
||||
mul(x.num, y.den, tmp);
|
||||
mul(y.num, x.den, r.den);
|
||||
r.num = tmp;
|
||||
}
|
||||
r.normalize();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Rational::invert()
|
||||
{
|
||||
Integer tmp = num;
|
||||
num = den;
|
||||
den = tmp;
|
||||
int s = sign(den);
|
||||
if (s == 0)
|
||||
error("Zero denominator.");
|
||||
else if (s < 0)
|
||||
{
|
||||
den.negate();
|
||||
num.negate();
|
||||
}
|
||||
}
|
||||
|
||||
int compare(const Rational& x, const Rational& y)
|
||||
{
|
||||
int xsgn = sign(x.num);
|
||||
int ysgn = sign(y.num);
|
||||
int d = xsgn - ysgn;
|
||||
if (d == 0 && xsgn != 0) d = compare(x.num * y.den, x.den * y.num);
|
||||
return d;
|
||||
}
|
||||
|
||||
Rational::Rational(double x)
|
||||
{
|
||||
num = 0;
|
||||
den = 1;
|
||||
if (x != 0.0)
|
||||
{
|
||||
int neg = x < 0;
|
||||
if (neg)
|
||||
x = -x;
|
||||
|
||||
const long shift = 15; // a safe shift per step
|
||||
const double width = 32768.0; // = 2^shift
|
||||
const int maxiter = 20; // ought not be necessary, but just in case,
|
||||
// max 300 bits of precision
|
||||
int expt;
|
||||
double mantissa = frexp(x, &expt);
|
||||
long exponent = expt;
|
||||
double intpart;
|
||||
int k = 0;
|
||||
while (mantissa != 0.0 && k++ < maxiter)
|
||||
{
|
||||
mantissa *= width;
|
||||
mantissa = modf(mantissa, &intpart);
|
||||
num <<= shift;
|
||||
num += (long)intpart;
|
||||
exponent -= shift;
|
||||
}
|
||||
if (exponent > 0)
|
||||
num <<= exponent;
|
||||
else if (exponent < 0)
|
||||
den <<= -exponent;
|
||||
if (neg)
|
||||
num.negate();
|
||||
}
|
||||
normalize();
|
||||
}
|
||||
|
||||
|
||||
Integer trunc(const Rational& x)
|
||||
{
|
||||
return x.num / x.den ;
|
||||
}
|
||||
|
||||
|
||||
Rational pow(const Rational& x, const Integer& y)
|
||||
{
|
||||
long yy = y.as_long();
|
||||
return pow(x, yy);
|
||||
}
|
||||
|
||||
#if defined(__GNUG__) && !defined(_G_NO_NRV)
|
||||
|
||||
Rational operator - (const Rational& x) return r(x)
|
||||
{
|
||||
r.negate();
|
||||
}
|
||||
|
||||
Rational abs(const Rational& x) return r(x)
|
||||
{
|
||||
if (sign(r.num) < 0) r.negate();
|
||||
}
|
||||
|
||||
|
||||
Rational sqr(const Rational& x) return r
|
||||
{
|
||||
mul(x.num, x.num, r.num);
|
||||
mul(x.den, x.den, r.den);
|
||||
r.normalize();
|
||||
}
|
||||
|
||||
Integer floor(const Rational& x) return q
|
||||
{
|
||||
Integer r;
|
||||
divide(x.num, x.den, q, r);
|
||||
if (sign(x.num) < 0 && sign(r) != 0) --q;
|
||||
}
|
||||
|
||||
Integer ceil(const Rational& x) return q
|
||||
{
|
||||
Integer r;
|
||||
divide(x.num, x.den, q, r);
|
||||
if (sign(x.num) >= 0 && sign(r) != 0) ++q;
|
||||
}
|
||||
|
||||
Integer round(const Rational& x) return q
|
||||
{
|
||||
Integer r;
|
||||
divide(x.num, x.den, q, r);
|
||||
r <<= 1;
|
||||
if (ucompare(r, x.den) >= 0)
|
||||
{
|
||||
if (sign(x.num) >= 0)
|
||||
++q;
|
||||
else
|
||||
--q;
|
||||
}
|
||||
}
|
||||
|
||||
// power: no need to normalize since num & den already relatively prime
|
||||
|
||||
Rational pow(const Rational& x, long y) return r
|
||||
{
|
||||
if (y >= 0)
|
||||
{
|
||||
pow(x.num, y, r.num);
|
||||
pow(x.den, y, r.den);
|
||||
}
|
||||
else
|
||||
{
|
||||
y = -y;
|
||||
pow(x.num, y, r.den);
|
||||
pow(x.den, y, r.num);
|
||||
if (sign(r.den) < 0)
|
||||
{
|
||||
r.num.negate();
|
||||
r.den.negate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
Rational operator - (const Rational& x)
|
||||
{
|
||||
Rational r(x); r.negate(); return r;
|
||||
}
|
||||
|
||||
Rational abs(const Rational& x)
|
||||
{
|
||||
Rational r(x);
|
||||
if (sign(r.num) < 0) r.negate();
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
Rational sqr(const Rational& x)
|
||||
{
|
||||
Rational r;
|
||||
mul(x.num, x.num, r.num);
|
||||
mul(x.den, x.den, r.den);
|
||||
r.normalize();
|
||||
return r;
|
||||
}
|
||||
|
||||
Integer floor(const Rational& x)
|
||||
{
|
||||
Integer q;
|
||||
Integer r;
|
||||
divide(x.num, x.den, q, r);
|
||||
if (sign(x.num) < 0 && sign(r) != 0) --q;
|
||||
return q;
|
||||
}
|
||||
|
||||
Integer ceil(const Rational& x)
|
||||
{
|
||||
Integer q;
|
||||
Integer r;
|
||||
divide(x.num, x.den, q, r);
|
||||
if (sign(x.num) >= 0 && sign(r) != 0) ++q;
|
||||
return q;
|
||||
}
|
||||
|
||||
Integer round(const Rational& x)
|
||||
{
|
||||
Integer q;
|
||||
Integer r;
|
||||
divide(x.num, x.den, q, r);
|
||||
r <<= 1;
|
||||
if (ucompare(r, x.den) >= 0)
|
||||
{
|
||||
if (sign(x.num) >= 0)
|
||||
++q;
|
||||
else
|
||||
--q;
|
||||
}
|
||||
return q;
|
||||
}
|
||||
|
||||
Rational pow(const Rational& x, long y)
|
||||
{
|
||||
Rational r;
|
||||
if (y >= 0)
|
||||
{
|
||||
pow(x.num, y, r.num);
|
||||
pow(x.den, y, r.den);
|
||||
}
|
||||
else
|
||||
{
|
||||
y = -y;
|
||||
pow(x.num, y, r.den);
|
||||
pow(x.den, y, r.num);
|
||||
if (sign(r.den) < 0)
|
||||
{
|
||||
r.num.negate();
|
||||
r.den.negate();
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
ostream& operator << (ostream& s, const Rational& y)
|
||||
{
|
||||
if (y.denominator() == 1L)
|
||||
s << y.numerator();
|
||||
else
|
||||
{
|
||||
s << y.numerator();
|
||||
s << "/";
|
||||
s << y.denominator();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
istream& operator >> (istream& s, Rational& y)
|
||||
{
|
||||
#ifdef _OLD_STREAMS
|
||||
if (!s.good())
|
||||
{
|
||||
return s;
|
||||
}
|
||||
#else
|
||||
if (!s.ipfx(0))
|
||||
{
|
||||
s.clear(ios::failbit|s.rdstate()); // Redundant if using GNU iostreams.
|
||||
return s;
|
||||
}
|
||||
#endif
|
||||
Integer n = 0;
|
||||
Integer d = 1;
|
||||
if (s >> n)
|
||||
{
|
||||
char ch = 0;
|
||||
s.get(ch);
|
||||
if (ch == '/')
|
||||
{
|
||||
s >> d;
|
||||
}
|
||||
else
|
||||
{
|
||||
s.putback(ch);
|
||||
}
|
||||
}
|
||||
y = Rational(n, d);
|
||||
return s;
|
||||
}
|
||||
|
||||
int Rational::OK() const
|
||||
{
|
||||
int v = num.OK() && den.OK(); // have valid num and denom
|
||||
if (v)
|
||||
{
|
||||
v &= sign(den) > 0; // denominator positive;
|
||||
v &= ucompare(gcd(num, den), _Int_One) == 0; // relatively prime
|
||||
}
|
||||
if (!v) error("invariant failure");
|
||||
return v;
|
||||
}
|
||||
|
||||
int
|
||||
Rational::fits_in_float() const
|
||||
{
|
||||
return Rational (FLT_MIN) <= *this && *this <= Rational (FLT_MAX);
|
||||
}
|
||||
|
||||
int
|
||||
Rational::fits_in_double() const
|
||||
{
|
||||
return Rational (DBL_MIN) <= *this && *this <= Rational (DBL_MAX);
|
||||
}
|
||||
|
|
@ -1,143 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 1988 Free Software Foundation
|
||||
written by Doug Lea (dl@rocky.oswego.edu)
|
||||
|
||||
This file is part of the GNU C++ Library. This library is free
|
||||
software; you can redistribute it and/or modify it under the terms of
|
||||
the GNU Library General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version. This library 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 Library General Public License for more details.
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
Regex class implementation
|
||||
*/
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation
|
||||
#endif
|
||||
#include <std.h>
|
||||
#include <ctype.h>
|
||||
#include <new.h>
|
||||
#include <builtin.h>
|
||||
|
||||
extern "C" {
|
||||
#if 1
|
||||
#include <rx.h>
|
||||
#else
|
||||
#include <gnuregex.h>
|
||||
#endif
|
||||
}
|
||||
|
||||
#include <Regex.h>
|
||||
|
||||
Regex::~Regex()
|
||||
{
|
||||
if (buf) {
|
||||
if (buf->buffer) free(buf->buffer);
|
||||
if (buf->fastmap) free(buf->fastmap);
|
||||
delete(buf);
|
||||
}
|
||||
if (reg)
|
||||
delete(reg);
|
||||
}
|
||||
|
||||
Regex::Regex(const char* t, int fast, int bufsize,
|
||||
const char* transtable)
|
||||
{
|
||||
int tlen = (t == 0)? 0 : strlen(t);
|
||||
buf = new re_pattern_buffer;
|
||||
memset (buf, 0, sizeof(re_pattern_buffer));
|
||||
reg = new re_registers;
|
||||
if (fast)
|
||||
buf->fastmap = (char*)malloc(256);
|
||||
else
|
||||
buf->fastmap = 0;
|
||||
buf->translate = (unsigned char*)transtable;
|
||||
if (tlen > bufsize)
|
||||
bufsize = tlen;
|
||||
buf->allocated = bufsize;
|
||||
buf->buffer = (char *)malloc(buf->allocated);
|
||||
const char* msg = re_compile_pattern((const char*)t, tlen, buf);
|
||||
if (msg != 0)
|
||||
(*lib_error_handler)("Regex", msg);
|
||||
else if (fast)
|
||||
re_compile_fastmap(buf);
|
||||
}
|
||||
|
||||
int Regex::match_info(int& start, int& length, int nth) const
|
||||
{
|
||||
if ((unsigned)(nth) >= RE_NREGS)
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
start = reg->start[nth];
|
||||
length = reg->end[nth] - start;
|
||||
return start >= 0 && length >= 0;
|
||||
}
|
||||
}
|
||||
|
||||
int Regex::search(const char* s, int len, int& matchlen, int startpos) const
|
||||
{
|
||||
int matchpos, pos, range;
|
||||
if (startpos >= 0)
|
||||
{
|
||||
pos = startpos;
|
||||
range = len - startpos;
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = len + startpos;
|
||||
range = -pos;
|
||||
}
|
||||
matchpos = re_search_2(buf, 0, 0, (char*)s, len, pos, range, reg, len);
|
||||
if (matchpos >= 0)
|
||||
matchlen = reg->end[0] - reg->start[0];
|
||||
else
|
||||
matchlen = 0;
|
||||
return matchpos;
|
||||
}
|
||||
|
||||
int Regex::match(const char*s, int len, int p) const
|
||||
{
|
||||
if (p < 0)
|
||||
{
|
||||
p += len;
|
||||
if (p > len)
|
||||
return -1;
|
||||
return re_match_2(buf, 0, 0, (char*)s, p, 0, reg, p);
|
||||
}
|
||||
else if (p > len)
|
||||
return -1;
|
||||
else
|
||||
return re_match_2(buf, 0, 0, (char*)s, len, p, reg, len);
|
||||
}
|
||||
|
||||
int Regex::OK() const
|
||||
{
|
||||
// can't verify much, since we've lost the original string
|
||||
int v = buf != 0; // have a regex buf
|
||||
v &= buf->buffer != 0; // with a pat
|
||||
if (!v) (*lib_error_handler)("Regex", "invariant failure");
|
||||
return v;
|
||||
}
|
||||
|
||||
/*
|
||||
some built-in Regular expressions
|
||||
*/
|
||||
|
||||
const Regex RXwhite("[ \n\t\r\v\f]+", 1);
|
||||
const Regex RXint("-?[0-9]+", 1);
|
||||
const Regex RXdouble("-?\\(\\([0-9]+\\.[0-9]*\\)\\|\\([0-9]+\\)\\|\\(\\.[0-9]+\\)\\)\\([eE][---+]?[0-9]+\\)?", 1, 200);
|
||||
const Regex RXalpha("[A-Za-z]+", 1);
|
||||
const Regex RXlowercase("[a-z]+", 1);
|
||||
const Regex RXuppercase("[A-Z]+", 1);
|
||||
const Regex RXalphanum("[0-9A-Za-z]+", 1);
|
||||
const Regex RXidentifier("[A-Za-z_][A-Za-z0-9_]*", 1);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue