diff options
Diffstat (limited to 'flower')
-rw-r--r-- | flower/Makefile | 2 | ||||
-rw-r--r-- | flower/Sources.make | 2 | ||||
-rw-r--r-- | flower/TODO | 4 | ||||
-rw-r--r-- | flower/compare.hh | 20 | ||||
-rw-r--r-- | flower/cursor.hh | 13 | ||||
-rw-r--r-- | flower/cursor.inl | 10 | ||||
-rw-r--r-- | flower/list.cc | 87 | ||||
-rw-r--r-- | flower/list.hh | 2 | ||||
-rw-r--r-- | flower/list.inl | 93 | ||||
-rw-r--r-- | flower/pcursor.hh | 38 | ||||
-rw-r--r-- | flower/plist.cc | 10 | ||||
-rw-r--r-- | flower/plist.hh | 34 | ||||
-rw-r--r-- | flower/plist.inl | 29 | ||||
-rw-r--r-- | flower/vray.hh | 2 |
14 files changed, 152 insertions, 194 deletions
diff --git a/flower/Makefile b/flower/Makefile index 3e9a70ce15..e17cbdb0d8 100644 --- a/flower/Makefile +++ b/flower/Makefile @@ -1,6 +1,6 @@ MAJVER=1 MINVER=0 -PATCHLEVEL=6 +PATCHLEVEL=7 PACKAGENAME=flower VERSION=$(MAJVER).$(MINVER).$(PATCHLEVEL) diff --git a/flower/Sources.make b/flower/Sources.make index e8b2250ad1..8016e67323 100644 --- a/flower/Sources.make +++ b/flower/Sources.make @@ -4,7 +4,7 @@ cc=lgetopt.cc string.cc dataf.cc textdb.cc unionfind.cc \ matdebug.cc templatecc=cursor.cc list.cc tsmat.cc plist.cc -inl=findcurs.inl link.inl list.inl plist.inl cursor.inl +inl=findcurs.inl link.inl list.inl cursor.inl plist.inl hh=cursor.hh pcursor.hh 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\ diff --git a/flower/TODO b/flower/TODO index f7070ecd07..4d0774ff7c 100644 --- a/flower/TODO +++ b/flower/TODO @@ -1,7 +1,7 @@ - * PointerList<T>:List<T> -> PointerList<T>:List<T*> - * PCursor -> Pointer_cursor / PointerCursor ? + * remove List::List(element) + * efficient copy cons for List * change String::pos diff --git a/flower/compare.hh b/flower/compare.hh index 47c7101c87..9f9d4e5906 100644 --- a/flower/compare.hh +++ b/flower/compare.hh @@ -1,13 +1,23 @@ +/* + flowerlib + + (c) 1996 Han-Wen Nienhuys + */ #ifndef COMPARE_HH #define COMPARE_HH + +#define one_operator(type, function, op) \ +inline bool operator op (type t1, type t2) { return function(t1, t2) op 0; } + /// handy notations for a signed comparison #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 one_operator(type, function, >)\ +prefix one_operator(type, function, >=)\ +prefix one_operator(type, function, ==)\ +prefix one_operator(type, function, !=)\ +prefix one_operator(type, function, <)\ +prefix one_operator(type, function, <=)\ 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; }\ \ diff --git a/flower/cursor.hh b/flower/cursor.hh index 1c61b1a76c..4babf96545 100644 --- a/flower/cursor.hh +++ b/flower/cursor.hh @@ -16,10 +16,11 @@ class Cursor tired of the warning messages. */ Cursor( const Cursor<T>& cursor ); - + + T& thing(); /// return current T - T& operator *(); - operator T() { return *(*this); } + T& operator *() { return thing(); } + operator T() { return thing(); } Cursor<T> operator =( const Cursor<T>& c ); /// make cursor with #no# items back @@ -98,10 +99,6 @@ private: */ - - - - /* comparisons. */ @@ -119,4 +116,4 @@ template_instantiate_compare(Cursor<T>, cursor_compare, template<class T>); #include "list.hh" #include "cursor.inl" -#endif // __CURSOR_HH // +#endif // CURSOR_HH diff --git a/flower/cursor.inl b/flower/cursor.inl index bdc242590f..0b077bd811 100644 --- a/flower/cursor.inl +++ b/flower/cursor.inl @@ -25,7 +25,7 @@ Cursor<T>::Cursor( const Cursor<T>& cursor ) : template<class T> inline T& -Cursor<T>::operator *() +Cursor<T>::thing() { assert( pointer_ ); return pointer_->thing(); @@ -42,16 +42,16 @@ Cursor<T>::operator =( const Cursor<T>& c ) template<class T> inline void -Cursor<T>::add( const T& thing ) +Cursor<T>::add( const T& th ) { - list_.add( thing, *this ); + list_.add( th, *this ); } template<class T> inline void -Cursor<T>::insert( const T& thing ) +Cursor<T>::insert( const T& th ) { - list_.insert( thing, *this ); + list_.insert( th, *this ); } template<class T> diff --git a/flower/list.cc b/flower/list.cc index 741e4ee97c..ce5e366cc8 100644 --- a/flower/list.cc +++ b/flower/list.cc @@ -34,51 +34,64 @@ List<T>::OK() const assert(!lp); } + template<class T> -Cursor<T> -List<T>::top() +inline +List<T>::~List() { -#if 0 - // ?? waarvoor is deze if ? - if ( top_ ) // equivalent: if ( size_ ) - { - Link<T>* t = top_->previous(); - assert( t != top_ ); // silly link - while ( t ) - { - assert(false); // this is even more silly. - top_ = t; - t = top_->previous(); - } - } -#endif - -// list empty: Cursor not ok() - return Cursor<T>( *this, top_ ); + Cursor<T> next(*this); + for ( Cursor<T> c( *this ); c.ok(); c = next ) { + next = c; + next++; + remove( c ); + } } - template<class T> -Cursor<T> -List<T>::bottom() +inline void +List<T>::add( const T& thing, Cursor<T> after_me ) { - /* wat is dit voor zooi? kan dit niet weg? + if (!size_) { // not much choice if list is empty + bottom_ = top_ = new Link<T>( thing ); + } else { // add at aprioprate place + Link<T> *p = ( after_me.ok() ) ? + after_me.pointer() : bottom().pointer(); + p->add(thing); + if (p == bottom_) // adjust bottom_ if necessary. + bottom_ = p->next(); + } - (invarianten!) - */ - if ( bottom_ ) // equivalent: if ( size_ ) - { - Link<T>* b = bottom_->next(); - assert( b != bottom_ ); // silly link - while ( b ) - { - bottom_ = b; - b = bottom_->next(); - } - } - // list empty: Cursor not ok() - return Cursor<T>( *this, bottom_ ); + size_++; } +/** + + Procedure: + \begin{itemize} + \item if #after_me# is #ok()#, add after #after_me#, else + \item if list !empty simply add to bottom, else + \item list is empty: create first \Ref{Link} and initialize + #bottom_# and #top_#. + \end{itemize} +*/ +template<class T> +inline void +List<T>::insert( const T& thing, Cursor<T> before_me ) +{ + if (!size_) { + bottom_ = top_ = new Link<T>( thing ); + } else { + Link<T> *p = + (before_me.ok())? + before_me.pointer() : top().pointer(); + + p->insert(thing); + if (p == top_) + top_ = p->previous(); + } + + size_++; + +} #endif diff --git a/flower/list.hh b/flower/list.hh index 5a825fa89e..1516e16642 100644 --- a/flower/list.hh +++ b/flower/list.hh @@ -62,7 +62,7 @@ class 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.) + (do not use, use \Ref{PointerList} #<String*># instead.) {\bf note:} retrieving "invalid" cursors, i.e. diff --git a/flower/list.inl b/flower/list.inl index 8bdcf15877..d71e947050 100644 --- a/flower/list.inl +++ b/flower/list.inl @@ -1,6 +1,8 @@ // -*-c++-*- + #ifndef LIST_INL #define LIST_INL + template<class T> inline List<T>::List() @@ -23,83 +25,6 @@ List<T>::List( const T& thing ) set_empty(); add( thing, Cursor<T>( *this, bottom_ ) ); } - -template<class T> -inline -List<T>::~List() -{ - Cursor<T> next(*this); - for ( Cursor<T> c( *this ); c.ok(); c = next ) { - next = c; - next++; - remove( c ); - } -} - -template<class T> -inline void -List<T>::add( const T& thing, Cursor<T> after_me ) -{ -#if 0 - if ( after_me.ok() ) - after_me.pointer()->add( thing ); - else if ( size_ ) - bottom().pointer()->add( thing ); - else - bottom_ = top_ = new Link<T>( thing ); -#endif - - if (!size_) { // not much choice if list is empty - bottom_ = top_ = new Link<T>( thing ); - } else { // add at aprioprate place - Link<T> *p = ( after_me.ok() ) ? - after_me.pointer() : bottom().pointer(); - p->add(thing); - if (p == bottom_) // adjust bottom_ if necessary. - bottom_ = p->next(); - } - - size_++; -} -/** - - Procedure: - \begin{itemize} - \item if #after_me# is #ok()#, add after #after_me#, else - \item if list !empty simply add to bottom, else - \item list is empty: create first \Ref{Link} and initialize - #bottom_# and #top_#. - \end{itemize} -*/ - -template<class T> -inline void -List<T>::insert( const T& thing, Cursor<T> before_me ) -{ - if (!size_) { - bottom_ = top_ = new Link<T>( thing ); - } else { - Link<T> *p = - (before_me.ok())? - before_me.pointer() : top().pointer(); - - p->insert(thing); - if (p == top_) - top_ = p->previous(); - } - - size_++; -#if 0 // rewrite hwn 16/9 - if ( before_me.ok() ) - before_me.pointer()->insert( thing ); - else if ( size_ ) - top().pointer()->insert( thing ); - else - bottom_ = top_ = new Link<T>( thing ); - size_++; -#endif -} - template<class T> inline void List<T>::remove( Cursor<T> me ) @@ -119,6 +44,20 @@ List<T>::size() const return size_; } +template<class T> +inline Cursor<T> +List<T>::top() +{ + return Cursor<T>( *this, top_ ); +} + + +template<class T> +inline Cursor<T> +List<T>::bottom() +{ + return Cursor<T>( *this, bottom_ ); +} #endif diff --git a/flower/pcursor.hh b/flower/pcursor.hh index 095bcc45bf..6cc3433e25 100644 --- a/flower/pcursor.hh +++ b/flower/pcursor.hh @@ -9,28 +9,46 @@ #define PCURSOR_HH -/// cursor which feels like a pointer +/// cursor to go with PointerList template<class T> -struct PCursor : public Cursor<T> { +struct PCursor : public Cursor<void *> { /// make cursor with #no# items back PCursor<T> operator -( int no) const { - return PCursor<T> (Cursor<T>::operator-(no)); + return PCursor<T> (Cursor<void*>::operator-(no)); } /// make cursor with #no# items further PCursor<T> operator +( int no) const { - return PCursor<T> (Cursor<T>::operator+(no)); + return PCursor<T> (Cursor<void*>::operator+(no)); } - PCursor(const List<T> & l) : Cursor<T> (l) {} + PCursor(const PointerList<T> & l) : Cursor<void*> (l) {} - PCursor( const Cursor<T>& cursor ) : Cursor<T>(cursor) { } - T operator ->() const { return *(*(Cursor<T> *)this); } + PCursor( const Cursor<void*>& cursor ) : Cursor<void*>(cursor) { } + void* vptr() const { return * ((Cursor<void*> &) *this); } + // should return T& ? + T ptr() const { return (T) vptr(); } + T operator ->() const { return ptr(); } + operator T() { return ptr(); } + T operator *() { return ptr(); } + +private: +// Cursor<void*>::operator void*; + // sigh }; /** - I like operator->(), so here it is. - - Cursor to go with pointer list. +don't create PointerList<void*>'s */ + + +template<class T> +inline int pcursor_compare(PCursor<T> a,PCursor<T>b) +{ + return cursor_compare(Cursor<void*>(b),Cursor<void*> (a)); +} + +#include "compare.hh" +template_instantiate_compare(PCursor<T>, pcursor_compare, template<class T>); + #endif diff --git a/flower/plist.cc b/flower/plist.cc index bbb0e7428f..5c8e47093c 100644 --- a/flower/plist.cc +++ b/flower/plist.cc @@ -3,14 +3,10 @@ // not inlined since it assumes knowledge of destructor. template<class T> void -PointerList<T>::remove( Cursor<T> me ) +IPointerList<T>::remove(PCursor<T> me ) { if ( me.ok() ) { - delete *me; - List<T>::remove( me ); + delete me.ptr(); + List<void*>::remove(me); } } - - - - diff --git a/flower/plist.hh b/flower/plist.hh index 8fa126b527..1bfc2d4ab4 100644 --- a/flower/plist.hh +++ b/flower/plist.hh @@ -11,21 +11,25 @@ /// Use for list of pointers, e.g. PointerList<AbstractType*>. template<class T> -class PointerList : public List<T> +class PointerList : public List<void *> { public: - PointerList(PointerList&) { set_empty(); } - PointerList( const T& thing ) : List<T>( thing ) { } + PCursor<T> top() { return PCursor<T> (List<void*>::top()); } + PCursor<T> bottom() { return PCursor<T> (List<void*>::bottom()); } + + PointerList( const T& thing ) : List<void*>( thing ) { } PointerList() {} - /// - virtual ~PointerList(); - /** - This function deletes deletes the allocated pointers of all links. - #\Ref{~List}# is used to delete the links themselves. - */ - - protected: - virtual void remove( Cursor<T> me ); +}; + + +/// intrusive pl. deletes pointers given to it. +template<class T> +struct IPointerList : public PointerList<T> { + IPointerList(IPointerList&) { set_empty(); } + IPointerList() { } +protected: + virtual void remove( Cursor<void*> me ) { remove (PCursor<T>(me)); } + virtual void remove( PCursor<T> me ); }; /** NOTE: @@ -37,16 +41,18 @@ class PointerList : public List<T> You have to copy this yourself, or use the macro PointerList__copy */ -#define PointerList__copy(T, to, from, op) \ +#define IPointerList__copy(T, to, from, op) \ for (PCursor<T> _pc_(from); _pc_.ok(); _pc_++)\ to.bottom().add(_pc_->op)\ \ template<class T> -void PL_copy(PointerList<T*> &dst,PointerList<T*> const&src); +void PL_copy(IPointerList<T*> &dst,IPointerList<T*> const&src); + #define PL_instantiate(a) L_instantiate(a *); template class PointerList<a*> +#define IPL_instantiate(a) PL_instantiate(a); template class IPointerList<a*> #include "plist.inl" diff --git a/flower/plist.inl b/flower/plist.inl index b8cd8d6020..82be364334 100644 --- a/flower/plist.inl +++ b/flower/plist.inl @@ -7,36 +7,15 @@ #ifndef PLIST_INL #define PLIST_INL - - -template<class T> -inline -PointerList<T>::~PointerList() -{ - Cursor<T> next(*this); - for ( Cursor<T> c( *this ); c.ok(); c = next ) { - next = c; - next++; - remove( c ); // PointerList::remove deletes the real data - } -} - -template<class T> -inline void -PointerList_print( PointerList<T> const & l ) -{ - for (PCursor<T> c(l ); c.ok(); c++ ) - c->print(); -} - template<class T> -inline void -PL_copy(PointerList<T*> &to,PointerList<T*> const&src) +void +PL_copy(IPointerList<T*> &to, IPointerList<T*> const&src) { for (PCursor<T*> pc(src); pc.ok(); pc++) { T *q = pc; - T *p=new T(*q) ; // argh, how do i do this in ANSI-C++ + T *p=new T(*q) ; to.bottom().add(p); } } + #endif diff --git a/flower/vray.hh b/flower/vray.hh index c03e651034..ab6255109b 100644 --- a/flower/vray.hh +++ b/flower/vray.hh @@ -128,7 +128,7 @@ public: int lower = -1, int upper = -1 ) { if (lower < 0) { lower = 0 ; - upper = sz(); + upper = sz()-1; } if (lower >= upper) return; |