diff options
author | Han-Wen Nienhuys <hanwen@xs4all.nl> | 1996-10-29 00:49:49 +0100 |
---|---|---|
committer | Han-Wen Nienhuys <hanwen@xs4all.nl> | 1996-10-29 00:49:49 +0100 |
commit | 4fac7cb7f554ad08c06225c985c7ddbcee1006dc (patch) | |
tree | 09114152c9f6651f599c5370789ce2ff33282155 /flower | |
parent | 727cdcbadf23c1986b0aed547aa645c9813f351b (diff) |
release: 0.0.3
Diffstat (limited to 'flower')
-rw-r--r-- | flower/Makefile | 7 | ||||
-rw-r--r-- | flower/Sources.make | 2 | ||||
-rw-r--r-- | flower/TODO | 4 | ||||
-rw-r--r-- | flower/compare.hh | 21 | ||||
-rw-r--r-- | flower/cursor.cc | 26 | ||||
-rw-r--r-- | flower/cursor.hh | 45 | ||||
-rw-r--r-- | flower/pcursor.hh | 26 |
7 files changed, 88 insertions, 43 deletions
diff --git a/flower/Makefile b/flower/Makefile index 9db4fbf5e8..aff8ac8f14 100644 --- a/flower/Makefile +++ b/flower/Makefile @@ -1,12 +1,13 @@ MAJVER=1 MINVER=0 -PATCHLEVEL=2 +PATCHLEVEL=3 PACKAGENAME=flower VERSION=$(MAJVER).$(MINVER).$(PATCHLEVEL) DNAME=$(PACKAGENAME)-$(VERSION) -#DEFINES=-DNDEBUG -CXXFLAGS+=$(DEFINES) -g -Wall -W -pedantic +DEFINES=-DNDEBUG -DNPRINT -O2 +#DEFINES=-g +CXXFLAGS+=$(DEFINES) -Wall -W -pedantic include Sources.make diff --git a/flower/Sources.make b/flower/Sources.make index 18fb18cb24..6521100b3b 100644 --- a/flower/Sources.make +++ b/flower/Sources.make @@ -5,7 +5,7 @@ cc=lgetopt.cc string.cc dataf.cc textdb.cc unionfind.cc \ templatecc=cursor.cc list.cc tsmat.cc inl=findcurs.inl link.inl list.inl -hh=cursor.hh cursor.inl lgetopt.hh link.hh list.hh dstream.hh \ +hh=cursor.hh pcursor.hh cursor.inl lgetopt.hh link.hh list.hh dstream.hh \ string.hh stringutil.hh vray.hh textdb.hh textstr.hh assoc.hh\ findcurs.hh unionfind.hh compare.hh handle.hh matrix.hh\ smat.hh vsmat.hh vector.hh real.hh choleski.hh\ diff --git a/flower/TODO b/flower/TODO index c8f3e5ad52..8d6e50591d 100644 --- a/flower/TODO +++ b/flower/TODO @@ -9,10 +9,6 @@ * Restricted cursor/list: make sublist from a list, and use rcursor as if list is as big as the sublist. - * Cursor signedcompare - - * int Cursor::op-(Cursor) - * move towards gnu? parsestream.h diff --git a/flower/compare.hh b/flower/compare.hh index 05b6e89e41..47c7101c87 100644 --- a/flower/compare.hh +++ b/flower/compare.hh @@ -2,21 +2,24 @@ #define COMPARE_HH /// handy notations for a signed comparison -#define instantiate_compare(type, function) \ -inline bool operator>(type t1, type t2) { return function(t1, t2) > 0; } \ - inline bool operator>=(type t1, type t2) { return function(t1, t2) >= 0; } \ - inline bool operator==(type t1, type t2) { return function(t1, t2) == 0; } \ - inline bool operator<=(type t1, type t2) { return function(t1, t2) <= 0; } \ - inline bool operator<(type t1, type t2) { return function(t1, t2) < 0; } \ - inline type MAX(type t1, type t2) { return (t1 > t2 )? t1 : t2; }\ - inline type MIN(type t1, type t2) { return (t1 < t2 )? t1 : t2; }\ +#define template_instantiate_compare(type, function, prefix) \ +prefix inline bool operator>(type t1, type t2) { return function(t1, t2) > 0; } \ +prefix inline bool operator>=(type t1, type t2) { return function(t1, t2) >= 0; } \ +prefix inline bool operator==(type t1, type t2) { return function(t1, t2) == 0; } \ +prefix inline bool operator<=(type t1, type t2) { return function(t1, t2) <= 0; } \ +prefix inline bool operator<(type t1, type t2) { return function(t1, t2) < 0; } \ +prefix inline type MAX(type t1, type t2) { return (t1 > t2 )? t1 : t2; }\ +prefix inline type MIN(type t1, type t2) { return (t1 < t2 )? t1 : t2; }\ \ - bool operator<(type t1, type t2) /* stupid fix to allow ; */ +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. */ + + +#define instantiate_compare(type, func) template_instantiate_compare(type,func, ) diff --git a/flower/cursor.cc b/flower/cursor.cc index 10e90de919..2a9f885689 100644 --- a/flower/cursor.cc +++ b/flower/cursor.cc @@ -1,10 +1,7 @@ -// cursor.cc #ifndef CURSOR_CC #define CURSOR_CC #include "cursor.hh" -//#define inline -//#include "cursor.inl" #include <assert.h> template<class T> @@ -72,4 +69,27 @@ Cursor<T>::operator -( int i ) const return r; } +template<class T> +int +Cursor<T>::operator-(Cursor<T> c) const +{ + assert(c.list == list); + int dif = 0; + Cursor<T> upward(c); + while (upward.ok() && upward.pointer_ != pointer_) { + upward++; + dif++; + } + + if (upward.ok()) + return dif; + dif =0; + while (c.ok()&& c.pointer_ != pointer_) { + dif --; + c--; + } + assert(c.ok()); + return dif; +} + #endif diff --git a/flower/cursor.hh b/flower/cursor.hh index 45c02aea15..cff93c68ce 100644 --- a/flower/cursor.hh +++ b/flower/cursor.hh @@ -24,7 +24,7 @@ class Cursor /// make cursor with #no# items further Cursor<T> operator +( int no) const; - + int operator -(Cursor<T> op) const; Cursor<T> operator -=(int); Cursor<T> operator +=(int); @@ -80,13 +80,11 @@ class Cursor /// access the list this came from const List<T>& list() const ; Link<T>* pointer(); - + private: List<T>& list_; Link<T>* pointer_; }; - - /** add and insert extend the list items are always stored as copies in List, but: @@ -98,31 +96,32 @@ private: -/// cursor which feels like a pointer -template<class T> -struct PCursor : public Cursor<T> { - /// make cursor with #no# items back - PCursor<T> operator -( int no) const { - return PCursor<T> (Cursor<T>::operator-(no)); - } - /// make cursor with #no# items further - PCursor<T> operator +( int no) const { - return PCursor<T> (Cursor<T>::operator+(no)); - } - PCursor(List<T> & l) : Cursor<T> (l) {} - PCursor( const Cursor<T>& cursor ) : Cursor<T>(cursor) { } - T operator ->() { return *(*this); } +/* + comparations. + */ -}; -/** - HWN: I'd like an operator->(), so here it is. - Cursor to go with pointer list. - */ + + + + + + +#include "compare.hh" + +template<class T> +inline int cursor_compare(Cursor<T> a,Cursor<T>b) +{ + return b-a; +} + +template_instantiate_compare(Cursor<T>, cursor_compare, template<class T>); + +#include "pcursor.hh" #include "list.hh" #include "cursor.inl" diff --git a/flower/pcursor.hh b/flower/pcursor.hh new file mode 100644 index 0000000000..8b0b179b4f --- /dev/null +++ b/flower/pcursor.hh @@ -0,0 +1,26 @@ + + +/// cursor which feels like a pointer +template<class T> +struct PCursor : public Cursor<T> { + + /// make cursor with #no# items back + PCursor<T> operator -( int no) const { + return PCursor<T> (Cursor<T>::operator-(no)); + } + + /// make cursor with #no# items further + PCursor<T> operator +( int no) const { + return PCursor<T> (Cursor<T>::operator+(no)); + } + PCursor(List<T> & l) : Cursor<T> (l) {} + + PCursor( const Cursor<T>& cursor ) : Cursor<T>(cursor) { } + T operator ->() { return *(*this); } + +}; +/** + HWN: I'd like an operator->(), so here it is. + + Cursor to go with pointer list. + */ |