fversion.hh: Variables.make make_version
make_version $(MAJVER) $(MINVER) $(PATCHLEVEL) "$(CXX) `$(CXXVER)`" > $@
+.PHONY: docxx
+docxx: $(hh) $(cc) $(templatecc) $(inl)
+ -mkdir docxx
+ doc++ -p -d docxx $(hh) $(cc) $(templatecc) $(inl)
dist:
-mkdir $(DDIR)
MAJVER=1
MINVER=0
-PATCHLEVEL=25
+PATCHLEVEL=26
+
PACKAGENAME=flower
#PROFILEFLAG=-pg
};
/// hungarian: map
+/** mindblowingly stupid Associative array implementation
+ */
template<class K, class V>
struct Assoc {
Array< Assoc_ent_<K,V> > arr;
- /****************/
+ /* ************** */
int find(K key) const {
for (int i = 0; i < arr.size(); i++) {
int i = find_creat(key);
arr[i].val = val;
}
- /**
+ /*
should create "set" template
*/
V& operator[](K key) {
return arr[find(key)].val;
}
};
-/** mindblowingly stupid Associative array implementation
- */
#endif
K key() { return assoc_.arr[i].key; }
V &val() { return assoc_.arr[i].val; }
};
-/*
- Iterator
- */
#endif
#include "matrix.hh"
+/**
+ structure for using the LU decomposition of a positive definite .
+
+ #P# is split into
+
+ LD transpose(L)
+ */
struct Choleski_decomposition {
/// lower triangle of Choleski decomposition
/// diagonal
Vector D;
///Create decomposition of P
- Choleski_decomposition(Matrix P);
/**
PRE
P needs to be symmetric positive definite
*/
+ Choleski_decomposition(Matrix P);
Vector solve(Vector rhs) const;
- Vector operator * (Vector rhs) const { return solve (rhs); }
- /**
+ /**
solve Px = rhs
*/
-
- Matrix inverse() const;
- /**
+Vector operator * (Vector rhs) const { return solve (rhs); }
+ /**
return the inverse of the matrix P.
*/
- Matrix original() const;
+ Matrix inverse() const;
/**
return P, calc'ed from L and D
*/
+ Matrix original() const;
+
};
-/**
- structure for using the LU decomposition of a positive definite .
-
- #P# is split into
-
- LD transpose(L)
- */
-
-
#endif
#endif
/// handy notations for a signed comparison
+/**
+ make the operators{<,<=,==,>=,>} and the MAX and MIN of two.
+ Please fill a & in the type argument if necessary.
+ */
#define template_instantiate_compare(type, function, prefix) \
prefix one_operator(type, function, >)\
prefix one_operator(type, function, >=)\
prefix inline type min(type t1, type t2) { return (t1 < t2 )? t1 : t2; }\
\
prefix bool operator<(type t1, type t2) /* stupid fix to allow ; */
- /**
- make the operators{<,<=,==,>=,>} and the MAX and MIN of two.
- Please fill a & in the type argument if necessary.
- */
#include "link.hh"
template<class T> class List;
-///
+/// iterator to List
+/**
+ add and insert extend the list
+ items are always stored as copies in List, but:
+ List<String> : copies of String stored
+ List<String*> : copies of String* stored!
+
+ the operations add and insert actually delegate the work to List class.
+ */
template<class T>
class Cursor
{
public:
- Cursor( const List<T>& list, Link<T>* pointer = 0 );
/** this isn't true, actually, #list# surely isn't const, but I get
tired of the warning messages. */
+ Cursor( const List<T>& list, Link<T>* pointer = 0 );
Cursor( const Cursor<T>& cursor );
bool backward();
/// put (copy) after me in List
- void add( const T& thing );
/**
analogously to editor. ok() interpreted as at end
of line.
cursor points to same object, cursor.next() is newly added
object.
*/
+ void add( const T& thing );
/// put (copy) before me in List
- void insert( const T& thing );
/**
analogously to editor. ok() interpreted as at begin of
line.
is newly inserted object.
*/
+ void insert( const T& thing );
///
void backspace();
List<T>& list_;
Link<T>* pointer_;
};
-/**
- add and insert extend the list
- items are always stored as copies in List, but:
- List<String> : copies of String stored
- List<String*> : copies of String* stored!
-
- the operations add and insert actually delegate the work to List class.
- */
/*
#ifndef CURSOR_INL
#define CURSOR_INL
#include <assert.h>
-//#include "list.hh"
+
template<class T>
inline
}
/// get a char.
+/**
+ Only class member who uses text_file::get
+ */
char
Data_file::data_get() {
char c = get();
return c;
}
-/**
- Only class member who uses text_file::get
- */
/// read line, gobble '\n'
String Data_file::get_line()
return false;
return (*silent)[s];
}
-///
+
+/** only output possibility. Delegates all conversion to String class.
+ */
Dstream &
Dstream::operator<<(String s)
{
return *this;
}
-/** only output possibility. Delegates all conversion to String class.
- */
Dstream::Dstream(ostream *r, const char * cfg_nm )
{
struct Assoc;
/// debug stream
+ /**
+ a class for providing debug output of nested structures,
+ with indents according to \{\}()[].
+
+ One can turn on and off specific messages using the Assoc silent.
+ This can be done automatically:
+
+ #define DEBUG dstream_.identify_as(__PRETTY_FUNCTION__)
+
+ DEBUG << "a message\n";
+
+ Init for the class names which should be silent can be given in a rc file.
+
+ */
class Dstream
{
ostream *os;
bool silence(String);
- Dstream(ostream *r, const char * rcfile);
/**
if rcfile == 0, then do not read any rc file
*/
+ Dstream(ostream *r, const char * rcfile);
virtual ~Dstream();
Dstream &identify_as(String s);
Dstream &operator << (String s);
};
- /**
- a class for providing debug output of nested structures,
- with indents according to \{\}()[].
-
- One can turn on and off specific messages using the Assoc silent.
- This can be done automatically:
-
- #define DEBUG dstream_.identify_as(__PRETTY_FUNCTION__)
-
- DEBUG << "a message\n";
-
- Init for the class names which should be silent can be given in a rc file.
-
- */
#endif
/// a T interval
+/**
+ this represents the closed interval [left,right].
+ No invariants. T must be a totally ordered ring
+ */
template<class T>
struct Interval_t {
T left, right;
- /****************/
+ /* ************** */
T center() { return (left + right) / T(2);}
void translate(T t) {
T max()const { return right;}
T min()const{ return left; }
T &min(){ return left; }
- void unite(Interval_t<T> h);
/**
PRE
*this and h are comparable
*/
+ void unite(Interval_t<T> h);
void intersect(Interval_t<T> h);
T length() const;
String str() const;
bool elt_q(T r);
};
-/**
- this represents the closed interval [left,right].
- No invariants. T must be a totally ordered ring
- */
/// partial ordering
template<class T>
};
-///
+/// C++ for version of long_getopt.
+/** For processing GNU style command line arguments. No pointer
+ (return values, arguments) contents are copied. */
class Getopt_long {
public:
- ///
+ /** errorcodes: no error, argument expected, no argument expected,
+ unknown option, illegal argument (eg. int expected). */
enum Errorcod { E_NOERROR = 0, E_ARGEXPECT, E_NOARGEXPECT, E_UNKNOWNOPTION,
E_ILLEGALARG } ;
- /** errorcodes: no error, argument expected, no argument expected,
- unknown option, illegal argument (eg. int expected). */
private:
void report(Errorcod c);
public:
/// what to do with errors
- void seterror(ostream *os);
/**
report messages on #*os#, and abort.
if #os# is null, then do not report nor abort, just set #error#
*/
+ void seterror(ostream *os);
/// argument. Set to 0 if not present
char* optarg;
Getopt_long(int c, char **v, long_option_init *lo);
/// get the next option
- long_option_init *operator()();
/**
- RETURN: pointer to next option found.
+ @return pointer to next option found.
0 if error occurred, or next argument is no option.
*/
+ long_option_init *operator()();
char *current_arg();
char * get_next_arg();
Errorcod error;
};
-/**
- C++ for version of long_getopt. For processing GNU style command line arguments.
- No pointer (return values, arguments) contents are copied.
- */
#endif
template<class T> class Link;
/// all-purpose doubly linked list
+/**
+ a doubly linked list;
+ List can be seen as all items written down on paper,
+ from top to bottom
+
+ class Cursor is used to extend List
+
+ items are always stored as copies in List, but:
+ #List<String># : copies of #String# stored
+ #List<String*># : copies of #String*# stored!
+ (do not use, use \Ref{PointerList} #<String*># instead.)
+
+ {\bf note:}
+ retrieving "invalid" cursors, i.e.
+ #top()/bottom()# from empty list, #find()# without success,
+ results in a nonvalid Cursor ( #!ok()# )
+
+
+ INVARIANTEN!
+*/
+
template<class T>
class List
{
void concatenate(List<T> const &s);
/// make *this empty
- void set_empty();
- /**
+ /**
POST:
size == 0
WARNING:
contents lost, and not deleted.
*/
-
+ void set_empty();
+
/// add after after_me
void add( const T& thing, Cursor<T> &after_me );
/// put thing before #before_me#
void insert( const T& thing, Cursor<T> &before_me );
-
- void remove( Cursor<T> me );
- /** Remove link pointed to by me. Destructor of contents called
+ /** Remove link pointed to by me. Destructor of contents called
(nop for pointers)
POST
WARNING: do not use #me# after calling
*/
+ void remove( Cursor<T> me );
+
- /****************/
+ /* ************** */
int size_;
Link<T>* top_;
Link<T>* bottom_;
};
-/**
- a doubly linked list;
- List can be seen as all items written down on paper,
- from top to bottom
-
- class Cursor is used to extend List
-
- items are always stored as copies in List, but:
- #List<String># : copies of #String# stored
- #List<String*># : copies of #String*# stored!
- (do not use, use \Ref{PointerList} #<String*># instead.)
-
- {\bf note:}
- retrieving "invalid" cursors, i.e.
- #top()/bottom()# from empty list, #find()# without success,
- results in a nonvalid Cursor ( #!ok()# )
-
-
- INVARIANTEN!
-*/
-
#include "list.inl"
#include "cursor.hh"
#include "vector.hh"
/// a Real matrix
+/** This is a class for a nonsquare block of #Real#s. The
+ implementation of sparse matrices is done in the appropriate #smat#
+ class. Matrix only does the mathematical actions (adding,
+ multiplying, etc.)
+
+
+ TODO
+ implement ref counting? */
+
+
class Matrix {
virtual_smat *dat;
int rows() const { return dat->rows(); }
/// return the size of a matrix
- int dim() const;
/**
- PRE
+ @pre
the matrix needs to be square.
*/
+ int dim() const;
// Matrix() { dat = 0; }
~Matrix() { delete dat; }
void operator/=(Real a) { (*this) *= 1/a; }
/// add a row
- void insert_row(Vector v,int k);
/**
add a row to the matrix before row k
v.dim() == cols()
0 <= k <= rows()
*/
+ void insert_row(Vector v,int k);
///
- void delete_row(int k) { dat->delete_row(k); }
/**
delete a row from this matrix.
PRE
0 <= k < rows();
*/
+ void delete_row(int k) { dat->delete_row(k); }
void delete_column(int k) { dat->delete_column(k); }
- ///
- Matrix(int n);
+
/**
square n matrix, initialised to null
*/
- ///
- Matrix(int n, int m);
+ Matrix(int n);
+
/**
n x m matrix, init to 0
*/
+ Matrix(int n, int m);
Matrix(const Matrix &m);
/// dyadic product: v * w.transpose
Real norm() const;
/// swap
- void swap_columns(int c1, int c2);
/**
PRE
0 <= c1,c2 < cols()
*/
+ void swap_columns(int c1, int c2);
/// swap
- void swap_rows(int c1, int c2);
/**
PRE
0 <= c1,c2 < rows()
*/
+ void swap_rows(int c1, int c2);
Vector row(int ) const;
void print() const;
};
-/** This is a class for a nonsquare block of #Real#s. The
- implementation of sparse matrices is done in the appropriate #smat#
- class. Matrix only does the mathematical actions (adding,
- multiplying, etc.)
-
-
- TODO
- implement ref counting? */
-
-
inline Vector
operator *(Vector &v, const Matrix& m) { return m.left_multiply(v); }
Matrix operator *(const Matrix& m1,const Matrix &m2);
#define PATHSEP '/'
#endif
-
+/**
+ INPUT: path the original full filename
+ OUTPUT: 4 components of the path. They can be empty
+*/
void
split_path(String path,
String &drive, String &dirs, String &filebase, String &extension)
filebase = path;
}
}
-/**
- INPUT: path the original full filename
- OUTPUT: 4 components of the path. They can be empty
-*/
-
File_path::File_path(String pref)
{
}
-///
+///find a file
+/**
+ It will search in the current dir, in the construction-arg, and
+ in any other added path, in this order.
+ */
String
File_path::find(String nm)
{
}
return "";
}
-/**
- It will search in the current dir, in the construction-arg, and
- in any other added path, in this order.
- */
operator Real();
operator int();
///
- operator bool() const;
/** perl -like string to bool conversion
*/
+ operator bool() const;
};
{
return new Full_storage(*this);
}
-/****************************************************************/
+
virtual_smat *
virtual_smat::get_full(int n, int m)
#include "stringutil.hh"
/// the smart string class.
+/**
+
+ Intuitive string class. provides
+
+ ref counting through #String_handle#
+
+ conversion from bool, int, double, char *, char.
+
+ conversion to int, upcase, downcase
+
+
+ printable.
+
+ indexing (pos, posAny, lastPos)
+
+ cutting (left, right, mid)
+
+ concat (+=, +)
+
+ signed comparison (<, >, ==, etc)
+
+ No operator[] is provided, since this would be enormously slow. If needed,
+ convert to const char *.
+*/
class String
{
protected:
public:
/// init to ""
- String() { }
/** needed because other constructors are provided.*/
+ String() { }
String(Rational);
/// String s = "abc";
String( const char* source );
int lastPos( const char* string ) const;
/// index of leftmost c
- int pos(char c ) const;
/**
RETURN:
0 if not found, else index + 1
*/
+ int pos(char c ) const;
int pos(const char* string ) const;
int posAny(const char* string ) const;
int len() const;
};
-/**
-
- Intuitive string class. provides
-
- ref counting thru #String_handle#
-
- conversion from bool, int, double, char *, char.
-
- conversion to int, upcase, downcase
-
-
- printable.
-
- indexing (pos, posAny, lastPos)
-
- cutting (left, right, mid)
-
- concat (+=, +)
-
- signed comparison (<, >, ==, etc)
-
- No operator[] is provided, since this would be enormously slow. If needed,
- convert to const char *.
-*/
#include "compare.hh"
const INITIALMAX=8;
class String_handle;
+
/// Internal String struct
+/**
+ the data itself. Handles simple tasks (resizing, resetting)
+ */
+
class StringData {
// GNU malloc: storage overhead is 8 bytes anyway.
}
+ /** POST: maxlen >= j.
+ IN: j, maximum stringlength.
+ contents thrown away.
+ */
void setmax(int j) {
OKW();
if (j > maxlen) {
length = 0;
}
}
+
/** POST: maxlen >= j.
- IN: j, maximum stringlength.
- contents thrown away.
- */
- ///
+ IN: j, maximum stringlength.
+ contents are kept if it grows.
+ */
void remax(int j) {
OKW();
if (j > maxlen) {
// length = strlen(string);
}
}
- /** POST: maxlen >= j.
- IN: j, maximum stringlength.
- contents are kept if it grows.
- */
/// check if writeable.
void OKW() {
}
};
-/**
- the data itself. Handles simple tasks (resizing, resetting)
- */
-/****************************************************************/
/// ref. counting for strings
+/**
+ handles ref. counting, and provides a very thin
+ interface using char *
+ */
class String_handle {
StringData* data;
void trunc(int j) { copy(); data->trunc(j); }
int len() const { return data->length; }
};
-/**
- handles ref. counting, and provides a very thin
- interface using char *
- */
-
#ifdef NDEBUG
#if (NDEBUG == BLONDE)
#include "textstr.hh"
-/**: do "#" comments, read quote enclosed fields */
-
+/** do "#" comments, read quote enclosed fields */
/// a "const" Array. Contents can't be changed.
class Text_record : Array<String>
{
Array<String>::size;
};
+/**
+ add a subrec/fieldsep/record separator
+ */
/// abstraction for a datafile
class Text_db : private Data_file
{
}
};
-
-/**
- add a subrec/fieldsep/record separator
- */
#endif
+
#ifndef TEXTSTR_HH
#define TEXTSTR_HH
#include "varray.hh"
/// line counting input stream.
+/**
+ a stream for textfiles. linecounting. Thin interface getchar and
+ ungetchar. (ungetc is unlimited)
+
+ should protect get and unget against improper use
+*/
+
+
class Text_stream
{
int line_no;
// could just have used streams.
FILE *f;
- Array<char> pushback;
+ Array<char> pushback;
String name;
public:
/// GNU format message.
void message(String s);
};
-/**
- a stream for textfiles. linecounting. Thin interface getchar and
- ungetchar. (ungetc is unlimited)
-
- should protect get and unget against improper use
-*/
-
-
/// read a data file
class Data_file : private Text_stream
{
#include "varray.hh"
/// a matrix storage baseclass.
+/** base class for interface with matrix storageclasses. There are no
+ iterators for matrixclasses, since matrices are (like arrays)
+ explicitly int-indexed.
+
+ Iteration is provided by *_next, *_ok, which update and check both
+ index variables simultaneously.
+
+ TODO
+ determine type of product matrix.
+
+*/
class virtual_smat {
virtual int cols() const = 0;
/// set the size. contents lost
- virtual void set_size(int i, int j) = 0;
/**
PRE
i >=0, j>=0
*/
+ virtual void set_size(int i, int j) = 0;
/// set the size to square dimen. contents lost
virtual void set_size(int i) = 0;
PRE
i>=0
*/
- /// set the size to i
- virtual void resize(int i, int j) = 0;
+ /// set the size to i,j
/**
keep contents. If enlarged contents unspecified
i>=0, j>=0
*/
+ virtual void resize(int i, int j) = 0;
/// set the size to square dimen. contents kept
- virtual void resize(int i) = 0;
/**
Keep contents. If enlarged contents are unspecified
PRE
i>=0
*/
+ virtual void resize(int i) = 0;
/// access an element
- virtual Real& elem(int i,int j) = 0;
/**
access an element.
in the 0-part of a sparse matrix.
*/
+ virtual Real& elem(int i,int j) = 0;
/// access a element, no modify
virtual const Real& elem(int i, int j) const = 0;
#endif
/// add a row
- virtual void insert_row(int k)=0;
/**
add a row to the matrix before row k. Contents
of added row are unspecified
0 <= k <= rows()
*/
-
+ virtual void insert_row(int k)=0;
+
/// delete a row
- virtual void delete_row(int k)=0;
- /**
+ /**
delete a row from this matrix.
PRE
0 <= k < rows();
- */
+ */virtual void delete_row(int k)=0;
+
virtual ~virtual_smat() { }
virtual virtual_smat *clone()=0;
/// is there a next?
- virtual bool mult_ok(int i, int j) const=0;
- /**
+ /**
at end of matrix? when doing loop
for(i=0; i<h; i++)
for(j=0; j<w; j++)
...
- */
+ */ virtual bool mult_ok(int i, int j) const=0;
+
/// iterate
- virtual void mult_next(int &i, int &j) const = 0;
- /**
+ /**
walk through matrix (regular multiply)
get next j for row i, or get next row i and reset j.
this will make sparse matrix implementation easy.
PRE
mult_ok(i,j)
- */
- virtual bool trans_ok(int i, int j) const=0;
- /**
+ */virtual void mult_next(int &i, int &j) const = 0;
+ /**
valid matrix entry. return false if at end of row
*/
- virtual void trans_next(int &i, int &j) const = 0;
+ virtual bool trans_ok(int i, int j) const=0;
+
/**
walk through matrix (transposed multiply).
Get next i (for column j)
PRE
ver_ok(i,j)
*/
+ virtual void trans_next(int &i, int &j) const = 0;
/// generate a "Full_storage" matrix
virtual_smat<Real> *get_full(int n, int m);
};
-/** base class for interface with matrix storageclasses. There are no
- iterators for matrixclasses, since matrices are (like arrays)
- explicitly int-indexed.
-
- Iteration is provided by *_next, *_ok, which update and check both
- index variables simultaneously.
-
- TODO
- determine type of product matrix.
-
-*/
#endif
}
///scaleable array/stack template, for T with def ctor.
+/**
+
+ This template implements a scaleable vector. With (or without) range
+ checking. It may be flaky for objects with complicated con- and
+ destructors. The type T should have a default constructor. It is
+ best suited for simple types, such as int, double or String
+
+ It uses stack terminology, (push, pop, top), and can be used as a stack.
+ */
template<class T>
class Array {
protected:
return r;
}
};
-/**
-
- This template implements a scaleable vector. With (or without) range
- checking. It may be flaky for objects with complicated con- and
- destructors. The type T should have a default constructor. It is
- best suited for simple types, such as int, double or String
-
- It uses stack terminology, (push, pop, top), and can be used as a stack.
- */
#endif
void set_matrix_debug(Dstream&ds);
/// a row of numbers
+/**
+ a vector. Storage is handled in Array, Vector only does the mathematics.
+ */
class Vector {
Array<Real> dat;
public:
/// set to j-th element of unit-base
void set_unit(int j) ;
};
-/**
- a vector. Storage is handled in Array, Vector only does the mathematics.
- */
inline Vector
operator+(Vector a, Vector const &b) {
virtual int cols() const = 0;
/// set the size. contents lost
- virtual void set_size(int i, int j) = 0;
/**
PRE
i >=0, j>=0
*/
+ virtual void set_size(int i, int j) = 0;
/// set the size to square dimen. contents lost
virtual void set_size(int i) = 0;
/**