]> git.donarmstrong.com Git - lilypond.git/commitdiff
flower-1.0.1
authorfred <fred>
Wed, 9 Oct 1996 11:42:13 +0000 (11:42 +0000)
committerfred <fred>
Wed, 9 Oct 1996 11:42:13 +0000 (11:42 +0000)
flower/Makefile
flower/handle.hh [new file with mode: 0644]

index 39e1cd78120ba1e9dd1866f45456f72a9f4bd5e5..5fb4f2a5b66257150c389ba630c9a751d5794521 100644 (file)
@@ -1,5 +1,9 @@
+MAJVER=1
+MINVER=0
+PATCHLEVEL=1
+
 PACKAGENAME=flower
-VERSION=1.0
+VERSION=$(MAJVER).$(MINVER).$(PATCHLEVEL)
 DNAME=$(PACKAGENAME)-$(VERSION)
 CXXFLAGS+=-g -Wall
 
@@ -9,7 +13,7 @@ templatecc=cursor.cc list.cc
 inl=findcurs.inl link.inl list.inl
 hh=cursor.hh cursor.inl lgetopt.hh link.hh list.hh \
        string.hh stringutil.hh vray.hh textdb.hh textstr.hh  assoc.hh\
-       findcurs.hh unionfind.hh compare.hh
+       findcurs.hh unionfind.hh compare.hh handle.hh
 
 
 
diff --git a/flower/handle.hh b/flower/handle.hh
new file mode 100644 (file)
index 0000000..3257399
--- /dev/null
@@ -0,0 +1,57 @@
+#ifndef HANDLE_HH
+#define HANDLE_HH
+/// reference counting handle
+template<class T>
+class Handle {
+    T *obj;
+    int *refs;
+
+    /// let go of ref. Delete if necessary
+    void down() {
+       if (!(*refs--)) {
+           delete obj;
+           delete refs;
+       }
+       obj = 0;
+       refs = 0;
+    }
+    /// point to new object. 
+    void up(T *t, int *r=0) {
+       if (!r) {
+           refs = new int;
+           *refs = 1;
+       } else {
+           refs =r;
+           *refs++;
+       }
+       obj = t;
+    }
+    /// POST: *refs == 1
+    void copy() {
+       if(*refs != 1){
+           T * newobj = new T(*obj );
+           down();
+           up(newobj);
+       }
+    }
+    Handle(Handle const &src) {
+       up(src.obj, src.refs);
+    }
+    Handle(T & o) {
+       up (&o);
+    }
+    void operator=(Handle const& src) {
+       if (this == &src)
+           return;
+       down();
+       up(src.o, src.refs);
+    }
+    operator const T&() {
+       return *obj;
+    }
+    operator T&() {
+       copy();
+       return *obj;
+    }
+}
+#endif