Commits

Lenard Lindstrom committed 22106a2

Remove unnecessary base class _Reference

The Reference class directly befriends the ClassReference class template, not
the base class of all ClassReference instantiations.

Comments (0)

Files changed (1)

include/imgblit/memory.hpp

         static void dec_ref(Datum *r);
         static Datum *add_ref(Datum *d) { inc_ref(d); return d; }
         Datum *ref_datum_p;
-        friend class _Reference;
+        template<class D> friend class ClassReference;
     };
 
     std::ostream &operator <<(std::ostream &os, const Reference &rhs_ref);
 
 
-    class _Reference {
-
-    public:
-        virtual ~_Reference() { }
-    protected:
-        static void inc_ref(Datum *d) { Reference::inc_ref(d); }
-        static void dec_ref(Datum *d) { Reference::dec_ref(d); }
-        static Datum *as_ptr(const Reference &r) { return r.ref_datum_p; }
-    };
-
-
-    template<class D> class ClassReference : protected _Reference {
+    template<class D> class ClassReference {
         D *ref_datum_p;
     public:
         ClassReference() : ref_datum_p(0) { }
         ClassReference(const ClassReference<D> &other) :
             ref_datum_p(add_ref(other.ref_datum_p)) { }
         ClassReference(const Reference &other) :
-            ref_datum_p(add_ref(dynamic_cast<D *>(as_ptr(other)))) { }
+            ref_datum_p(add_ref(dynamic_cast<D *>(other.ref_datum_p))) { }
         virtual ~ClassReference();
         ClassReference<D> &operator =(const ClassReference<D> &rvalue);
         ClassReference<D> &operator =(const Reference &rvalue);
         D *operator ->() const { assert(ref_datum_p); return ref_datum_p; }
         bool operator !() const { return ref_datum_p == 0; }
     protected:
+        static void inc_ref(Datum *r) { Reference::inc_ref(r); }
+        static void dec_ref(Datum *r) { Reference::dec_ref(r); }
         static D *add_ref(D *d) { inc_ref(d); return d; }
     };
 
     template<class D> ClassReference<D> &
     ClassReference<D>::operator =(const Reference &rvalue)
     {
-        D *next = add_ref(dynamic_cast<D *>(as_ptr(rvalue)));
+        D *next = add_ref(dynamic_cast<D *>(rvalue.ref_datum_p));
         D *prev = ref_datum_p;
         ref_datum_p = next;
         dec_ref(prev);