summaryrefslogtreecommitdiff
path: root/flower
diff options
context:
space:
mode:
authorHan-Wen Nienhuys <hanwen@xs4all.nl>1996-11-30 12:09:32 +0100
committerHan-Wen Nienhuys <hanwen@xs4all.nl>1996-11-30 12:09:32 +0100
commitcd6fbd39e456ab3ff353c38fc5ae1997e61390f2 (patch)
tree7b15d4c85e5aa027942420d220fa1dd7c09f22d1 /flower
parentfc22f69328fd2d5030bb1feff8d0f6da37e8217d (diff)
release: 0.0.9
Diffstat (limited to 'flower')
-rw-r--r--flower/Makefile6
-rw-r--r--flower/README4
-rw-r--r--flower/TODO2
-rw-r--r--flower/dstream.cc5
-rw-r--r--flower/list.cc40
-rw-r--r--flower/list.hh18
-rw-r--r--flower/list.inl7
-rw-r--r--flower/pcursor.hh7
-rw-r--r--flower/plist.hh4
9 files changed, 56 insertions, 37 deletions
diff --git a/flower/Makefile b/flower/Makefile
index dffea2fb37..b39b1f213d 100644
--- a/flower/Makefile
+++ b/flower/Makefile
@@ -1,6 +1,6 @@
MAJVER=1
MINVER=0
-PATCHLEVEL=8
+PATCHLEVEL=10
PACKAGENAME=flower
VERSION=$(MAJVER).$(MINVER).$(PATCHLEVEL)
@@ -13,6 +13,7 @@ include Sources.make
obs=$(cc:.cc=.o)
staticlib=libflower.a
+
$(staticlib): $(obs)
$(AR) cr libflower.a $(obs)
@@ -24,8 +25,10 @@ depend: Sources.make
clean:
rm -f $(obs) $(staticlib)
+
realclean: clean
rm -f depend
+
DFILES=$(hh) $(cc) $(inl) $(templatecc) Makefile Sources.make TODO README
DDIR=$(DNAME)
@@ -34,6 +37,7 @@ dist:
ln $(DFILES) $(DDIR)/
tar cfz $(DNAME).tar.gz $(DDIR)/*
rm -rf $(DDIR)/
+
TAGS:
etags -CT $(inl) $(cc) $(hh)
diff --git a/flower/README b/flower/README
index d33c68f3df..6706447fcf 100644
--- a/flower/README
+++ b/flower/README
@@ -1,5 +1,7 @@
This library contains some general purpose routines which aren't
-standardised yet. It was written by:
+standardised libraries yet. It may be replaced by STL in time
+
+It was written by:
Han-Wen Nienhuys <hanwen@stack.nl>
diff --git a/flower/TODO b/flower/TODO
index ef0ab6bac6..9d4ade3bcd 100644
--- a/flower/TODO
+++ b/flower/TODO
@@ -1,7 +1,5 @@
* PCursor -> Pointer_cursor / PointerCursor ?
- * remove List::List(element)
-
* efficient copy cons for List
* extend Interval
diff --git a/flower/dstream.cc b/flower/dstream.cc
index 8540e734cf..6cfc62eb3d 100644
--- a/flower/dstream.cc
+++ b/flower/dstream.cc
@@ -114,7 +114,10 @@ Dstream::Dstream(ostream *r, const char * cfg_nm )
Text_db cfg(fn);
while (! cfg.eof()){
Text_record r( cfg++);
- assert(r.sz() == 2);
+ if (r.sz() != 2) {
+ r.message("not enough fields in Dstream init.");
+ continue;
+ }
(*silent)[r[0]] = r[1].to_bool();
}
diff --git a/flower/list.cc b/flower/list.cc
index ce5e366cc8..55e1e20507 100644
--- a/flower/list.cc
+++ b/flower/list.cc
@@ -36,7 +36,6 @@ List<T>::OK() const
template<class T>
-inline
List<T>::~List()
{
Cursor<T> next(*this);
@@ -48,14 +47,17 @@ List<T>::~List()
}
template<class T>
-inline void
-List<T>::add( const T& thing, Cursor<T> after_me )
+void
+List<T>::add( const T& thing, Cursor<T> &after_me )
{
if (!size_) { // not much choice if list is empty
bottom_ = top_ = new Link<T>( thing );
+ if (!after_me.ok())
+ after_me = bottom();
} else { // add at aprioprate place
- Link<T> *p = ( after_me.ok() ) ?
- after_me.pointer() : bottom().pointer();
+ if (!after_me.ok())
+ after_me = bottom();
+ Link<T> *p =after_me.pointer();
p->add(thing);
if (p == bottom_) // adjust bottom_ if necessary.
bottom_ = p->next();
@@ -75,23 +77,37 @@ List<T>::add( const T& thing, Cursor<T> after_me )
*/
template<class T>
-inline void
-List<T>::insert( const T& thing, Cursor<T> before_me )
+void
+List<T>::insert( const T& thing, Cursor<T> &before_me )
{
if (!size_) {
bottom_ = top_ = new Link<T>( thing );
+ if (!before_me.ok())
+ before_me = top();
+
} else {
- Link<T> *p =
- (before_me.ok())?
- before_me.pointer() : top().pointer();
+ if (!before_me.ok())
+ before_me = top();
+
+ Link<T> *p = before_me.pointer() ;
p->insert(thing);
if (p == top_)
top_ = p->previous();
}
-
- size_++;
+ size_++;
}
+
+template<class T>
+void
+List<T>::concatenate(List<T> const&s)
+{
+ Cursor<T> b(bottom());
+ for (Cursor<T> c(s); c.ok(); c++) {
+ b.add(c);
+ b++;
+ }
+}
#endif
diff --git a/flower/list.hh b/flower/list.hh
index 1516e16642..117e1862e4 100644
--- a/flower/list.hh
+++ b/flower/list.hh
@@ -1,5 +1,3 @@
-// list.hh
-
#ifndef __LIST_HH
#define __LIST_HH
@@ -7,7 +5,7 @@ class ostream;
template<class T> class Cursor;
template<class T> class Link;
-/// all purpose list
+/// all-purpose doubly linked list
template<class T>
class List
{
@@ -15,11 +13,7 @@ class List
List(List const&src);
/// construct empty list
- List();
-
- /// construct list from first item.
- List( const T& thing );
-
+ List();
virtual ~List();
Cursor<T> bottom();
@@ -30,6 +24,10 @@ class List
protected:
friend class Cursor<T>;
friend class Link<T>;
+
+ void concatenate(List<T> const &s);
+
+
/// make *this empty
void set_empty();
/**
@@ -37,10 +35,10 @@ class List
*/
/// add after after_me
- void add( const T& thing, Cursor<T> 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 insert( const T& thing, Cursor<T> &before_me );
virtual void remove( Cursor<T> me );
/**
Remove link pointed to by me.
diff --git a/flower/list.inl b/flower/list.inl
index d71e947050..c3ee7e2948 100644
--- a/flower/list.inl
+++ b/flower/list.inl
@@ -19,13 +19,6 @@ List<T>::set_empty()
}
template<class T>
-inline
-List<T>::List( const T& thing )
-{
- set_empty();
- add( thing, Cursor<T>( *this, bottom_ ) );
-}
-template<class T>
inline void
List<T>::remove( Cursor<T> me )
{
diff --git a/flower/pcursor.hh b/flower/pcursor.hh
index 5e535300d7..c9cc53411f 100644
--- a/flower/pcursor.hh
+++ b/flower/pcursor.hh
@@ -24,6 +24,7 @@ struct PCursor : public Cursor<void *> {
PCursor<T> operator +( int no) const {
return PCursor<T> (Cursor<void*>::operator+(no));
}
+
PCursor(const PointerList<T> & l) : Cursor<void*> (l) {}
PCursor( const Cursor<void*>& cursor ) : Cursor<void*>(cursor) { }
@@ -34,13 +35,17 @@ struct PCursor : public Cursor<void *> {
T operator ->() const { return ptr(); }
operator T() { return ptr(); }
T operator *() { return ptr(); }
+ void add(const T& p ) { Cursor<void*>::add((void*) p); }
+ void insert(const T& p ) { Cursor<void*>::insert((void*) p);}
private:
// Cursor<void*>::operator void*;
// sigh
};
/**
-don't create PointerList<void*>'s
+ don't create PointerList<void*>'s.
+ This cursor is just an interface class for Cursor. It takes care of the
+ appropriate type casts
*/
diff --git a/flower/plist.hh b/flower/plist.hh
index 78df40cb17..ea2c0ecdae 100644
--- a/flower/plist.hh
+++ b/flower/plist.hh
@@ -16,8 +16,8 @@ class PointerList : public List<void *>
public:
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 ) { }
+ void concatenate(PointerList<T> const &s) { List<void*>::concatenate(s); }
+// PointerList( const T& thing ) : List<void*>( thing ) { }
PointerList() {}
};