UniqueSet.h

Go to the documentation of this file.
00001 
00007 /*
00008    UniqueSet template - (hashtable)
00009 */
00010 
00011 #ifndef UNIQUESET_H
00012 #define UNIQUESET_H
00013 
00014 #include "UniqueSetRaw.h"
00015 
00016 // Need this juju to use templated friend below
00017 template <class Type> class UniqueSetIter;
00018 
00019 template <class Elem> class UniqueSet {
00020 
00021   friend class UniqueSetIter<Elem>;
00022 
00023   private:
00024 
00025     UniqueSetRaw<Elem> *rep;
00026 
00027   public:
00028 
00029     // Various Constructors
00030     UniqueSet(void) { rep = new UniqueSetRaw<Elem>(); rep->refCount = 1; }
00031 
00032     UniqueSet(int size) { rep=new UniqueSetRaw<Elem>(size); rep->refCount=1; }
00033 
00034     UniqueSet(const UniqueSet<Elem> &us) {
00035       if (!--rep->refCount) delete rep; rep = us.rep; rep->refCount++; 
00036     }
00037 
00038     UniqueSet(const UniqueSet<Elem>* us) { 
00039       if (!--rep->refCount) delete rep; rep = new UniqueSetRaw<Elem>(*us->rep);
00040       rep->refCount = 1;
00041     }
00042 
00043     ~UniqueSet(void) { if (!--rep->refCount) delete rep; }
00044 
00045     UniqueSet<Elem>& operator =(const UniqueSet<Elem>& us) {
00046       if (!--rep->refCount) delete rep; rep = us.rep; rep->refCount++; 
00047       return (*this);
00048     }
00049 
00050     void rehash(void) { rep->rehash(); }
00051   
00052     int add(const Elem &elem) { return rep->add(elem); }
00053 
00054     int load(const Elem &elem) { return rep->load(elem); }
00055 
00056     int del(const Elem &elem) { return rep->del(elem); }
00057 
00058     int size(void) const { return rep->size(); }
00059 
00060     Elem *find(const Elem &elem) { return rep->find(elem); }
00061 
00062     void clear(void) { rep->clear(); }
00063 
00064 #ifdef DEBUG
00065     void status(void) { rep->status(); }
00066 #endif
00067 };
00068 
00069 #endif

Generated on Sat Sep 23 01:17:16 2017 for NAMD by  doxygen 1.4.7