summaryrefslogtreecommitdiff
path: root/flower
diff options
context:
space:
mode:
Diffstat (limited to 'flower')
-rw-r--r--flower/Makefile2
-rw-r--r--flower/Sources.make3
-rw-r--r--flower/TODO1
-rw-r--r--flower/assoc.hh2
-rw-r--r--flower/associter.hh42
-rw-r--r--flower/dstream.cc26
-rw-r--r--flower/dstream.hh6
-rw-r--r--flower/plist.hh2
-rw-r--r--flower/plist.inl13
9 files changed, 74 insertions, 23 deletions
diff --git a/flower/Makefile b/flower/Makefile
index 4533783563..5b40b40629 100644
--- a/flower/Makefile
+++ b/flower/Makefile
@@ -1,6 +1,6 @@
MAJVER=1
MINVER=0
-PATCHLEVEL=4
+PATCHLEVEL=5
PACKAGENAME=flower
VERSION=$(MAJVER).$(MINVER).$(PATCHLEVEL)
diff --git a/flower/Sources.make b/flower/Sources.make
index fd5dcf4146..e8b2250ad1 100644
--- a/flower/Sources.make
+++ b/flower/Sources.make
@@ -9,4 +9,5 @@ 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\
smat.hh vsmat.hh vector.hh real.hh choleski.hh\
- tsmat.hh tvsmat.hh plist.hh\
+ tsmat.hh tvsmat.hh plist.hh associter.hh\
+
diff --git a/flower/TODO b/flower/TODO
index 6f0f451cce..bcb4e27042 100644
--- a/flower/TODO
+++ b/flower/TODO
@@ -1,3 +1,4 @@
+ * PointerList<T>:List<T> -> PointerList<T>:List<T*>
* efficient copy cons for List
diff --git a/flower/assoc.hh b/flower/assoc.hh
index 84a54c9a72..2409985668 100644
--- a/flower/assoc.hh
+++ b/flower/assoc.hh
@@ -2,6 +2,7 @@
#define ASSOC_HH
#include "vray.hh"
+#include <assert.h>
template<class K,class V>
struct Assoc_ent_ {
@@ -72,4 +73,5 @@ public:
};
/** mindblowingly stupid Associative array implementation
*/
+
#endif
diff --git a/flower/associter.hh b/flower/associter.hh
new file mode 100644
index 0000000000..6103f2266c
--- /dev/null
+++ b/flower/associter.hh
@@ -0,0 +1,42 @@
+/*
+ associter.hh -- part of flowerlib
+
+ (c) 1996 Han-Wen Nienhuys
+*/
+
+#ifndef ASSOCITER_HH
+#define ASSOCITER_HH
+
+#include "assoc.hh"
+
+/// an iterator for the #Assoc# class
+template<class K, class V>
+struct Assoc_iter {
+ int i;
+ Assoc<K,V> &assoc_;
+
+ Assoc_iter(Assoc<K,V> &a) :
+ assoc_(a)
+ {
+ i= next(0);
+ }
+ int next(int j) {
+ while (j < assoc_.arr.sz() && assoc_.arr[j].free)
+ j++;
+ return j;
+ }
+ bool ok() const {
+ return i < assoc_.arr.sz();
+ }
+ void OK()const {
+ assert(!ok() || !assoc_.arr[i].free);
+ }
+ void operator++(int) { i++; i = next(i); }
+ K key() { return assoc_.arr[i].key; }
+ V &val() { return assoc_.arr[i].val; }
+};
+/*
+ Iterator
+ */
+
+#endif
diff --git a/flower/dstream.cc b/flower/dstream.cc
index d8cff69041..8540e734cf 100644
--- a/flower/dstream.cc
+++ b/flower/dstream.cc
@@ -1,5 +1,5 @@
#include <fstream.h>
-
+#include "assoc.hh"
#include "dstream.hh"
#include "string.hh"
#include "textdb.hh"
@@ -36,14 +36,14 @@ Dstream::identify_as(String name)
String cl(strip_member(mem));
String idx = cl;
- if (silent.elt_query(mem))
+ if (silent->elt_query(mem))
idx = mem;
- else if (silent.elt_query(cl))
+ else if (silent->elt_query(cl))
idx = cl;
else {
- silent[idx] = false;
+ (*silent)[idx] = false;
}
- local_silence = silent[idx];
+ local_silence = (*silent)[idx];
if (classname != idx && !local_silence) {
classname=idx;
*os << "[" << classname << ":]";
@@ -54,9 +54,9 @@ Dstream::identify_as(String name)
bool
Dstream::silence(String s)
{
- if (!silent.elt_query(s))
+ if (!silent->elt_query(s))
return false;
- return silent[s];
+ return (*silent)[s];
}
///
Dstream &
@@ -99,6 +99,7 @@ Dstream::operator<<(String s)
Dstream::Dstream(ostream *r, const char * cfg_nm )
{
os = r;
+ silent = new Assoc<String,bool>;
if (!os)
return;
indentlvl = 0;
@@ -109,15 +110,18 @@ Dstream::Dstream(ostream *r, const char * cfg_nm )
if (!ifs)
return;
}
- // cerr << "(" << fn;
+
Text_db cfg(fn);
while (! cfg.eof()){
Text_record r( cfg++);
assert(r.sz() == 2);
- silent[r[0]] = r[1].to_bool();
+ (*silent)[r[0]] = r[1].to_bool();
}
- // cerr <<")";
-}
+}
+Dstream::~Dstream()
+{
+ delete silent;
+}
diff --git a/flower/dstream.hh b/flower/dstream.hh
index 72d0897201..aae52a7838 100644
--- a/flower/dstream.hh
+++ b/flower/dstream.hh
@@ -4,10 +4,12 @@
#define DSTREAM_HH
#include "string.hh"
-#include "assoc.hh"
const char eol= '\n';
+template<class K,class V>
+struct Assoc;
+
/// debug stream
class Dstream
{
@@ -16,7 +18,7 @@ class Dstream
bool local_silence;
String classname;
- Assoc<String, bool> silent;
+ Assoc<String, bool> *silent;
public:
bool silence(String);
diff --git a/flower/plist.hh b/flower/plist.hh
index 3660968a47..8fa126b527 100644
--- a/flower/plist.hh
+++ b/flower/plist.hh
@@ -44,7 +44,7 @@ class PointerList : public List<T>
template<class T>
-void PL_copy(PointerList<T> &dst,PointerList<T> const&src);
+void PL_copy(PointerList<T*> &dst,PointerList<T*> const&src);
#define PL_instantiate(a) L_instantiate(a *); template class PointerList<a*>
diff --git a/flower/plist.inl b/flower/plist.inl
index fb18c87241..b8cd8d6020 100644
--- a/flower/plist.inl
+++ b/flower/plist.inl
@@ -25,18 +25,17 @@ template<class T>
inline void
PointerList_print( PointerList<T> const & l )
{
- List<T>& promises_to_be_const = (List<T>&) l;
- for ( Cursor<T> c( promises_to_be_const ); c.ok(); c++ )
- (*c)->print();
+ for (PCursor<T> c(l ); c.ok(); c++ )
+ c->print();
}
template<class T>
inline void
-PL_copy(PointerList<T> &to,PointerList<T> const&src)
+PL_copy(PointerList<T*> &to,PointerList<T*> const&src)
{
- for (PCursor<T> pc(src); pc.ok(); pc++) {
- T q = pc;
- T p=new typeof(*q) (*q) ; // argh, how do i do this in ANSI-C++
+ 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++
to.bottom().add(p);
}
}