WorkList.hxx

Go to the documentation of this file.
00001 #ifndef WORKLIST_HXX
00002 #define WORKLIST_HXX
00003 
00004 /**************************************************************************
00005  *
00006  * Copyright (C) 2008, Johns Hopkins University.
00007  * All rights reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or
00010  * without modification, are permitted provided that the following
00011  * conditions are met:
00012  *
00013  *   - Redistributions of source code must contain the above 
00014  *     copyright notice, this list of conditions, and the following
00015  *     disclaimer. 
00016  *
00017  *   - Redistributions in binary form must reproduce the above
00018  *     copyright notice, this list of conditions, and the following
00019  *     disclaimer in the documentation and/or other materials 
00020  *     provided with the distribution.
00021  *
00022  *   - Neither the names of the copyright holders nor the names of any
00023  *     of any contributors may be used to endorse or promote products
00024  *     derived from this software without specific prior written
00025  *     permission. 
00026  *
00027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00028  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00029  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00030  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00031  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00032  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00033  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00034  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00035  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00036  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00037  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038  *
00039  **************************************************************************/
00040 
00041 #include <stdlib.h>
00042 #include <assert.h>
00043 #include <iostream>
00044 #include <string>
00045 #include <vector>
00046 #include "shared_ptr.hxx"
00047 
00048 // This is intentionally not a subclass of Donelist. 
00049 // There should be no compatibility.
00050 
00051 template <class T, const bool isDoneSet>
00052 struct BaseWorkList {
00053   typedef std::set<T, std::less<T> > WorkSet;
00054   WorkSet set;
00055   
00056   typedef typename WorkSet::iterator iterator;
00057 
00058   BaseWorkList()
00059   {
00060   }
00061 
00062   bool 
00063   contains(const T &probe) const
00064   {
00065     return (set.find(probe) != set.end());
00066   }
00067 
00068   inline iterator begin() { return set.begin(); }
00069   inline iterator end() {   return set.end(); }
00070 
00071   inline void erase(const iterator& itr) {
00072     return set.erase(itr);
00073   }
00074 
00075   inline void erase(const T& key) {
00076     set.erase(key);
00077   }
00078 
00079   inline void find(const T& key) {
00080     return set.find(key);
00081   }
00082 
00083   void insert(const T &probe) {
00084     set.insert(probe);
00085   }
00086 
00087   inline void clear() { set.clear(); }
00088 
00089   inline size_t size() { return set.size(); }
00090 
00091   inline size_t count() { return set.count(); }
00092 
00093   inline bool empty() { return set.empty(); }
00094 };
00095 
00096 template <class T>
00097 struct WorkList : public BaseWorkList<T, false> {
00098   static inline boost::shared_ptr<WorkList<T> >
00099   make() {
00100     WorkList<T> *tmp = new WorkList<T>();
00101     return boost::shared_ptr<WorkList<T> >(tmp);
00102   }
00103 };
00104 
00105 template <class T>
00106 struct DoneList : public BaseWorkList<T, true> {
00107   static inline boost::shared_ptr<DoneList<T> >
00108   make() {
00109     DoneList<T> *tmp = new DoneList<T>();
00110     return boost::shared_ptr<DoneList<T> >(tmp);
00111   }
00112 };
00113 
00114 #endif /* WORKLIST_HXX */
00115 

Generated on Thu May 17 23:59:16 2012 for BitC Compiler by  doxygen 1.4.7