Generated on Tue Dec 16 13:34:02 2008 for ell-3.0.0 by doxygen 1.5.1

src/ell/SC_Listing.cc

Go to the documentation of this file.
00001 #include "ell/StateCollector.hh"
00002 
00003 namespace ell {
00004     
00005     SC_Listing::SC_Listing()
00006       : stateList() 
00007     {}
00008     
00009     SC_Listing::~SC_Listing()
00010     {
00011           // delete all collected State objects
00012         for (   List::iterator it = stateList.begin();
00013                 it != stateList.end(); it++ ) 
00014         {
00015             delete *it;
00016         }
00017           // clear NULL pointer list
00018         stateList.clear();
00019     }
00020 
00021       // This function is used to track all added intermediate States.
00022       // @param s the added State
00023     void 
00024     SC_Listing::add(const State& s) {
00025           // store a copy of s
00026         stateList.push_back(s.clone());
00027     }
00028     
00029       // Returns number of added States.
00030       // @return the number of added states
00031     size_t 
00032     SC_Listing::size() const {
00033         return stateList.size();
00034     }
00035      
00036       // Returns last added State.
00037       // @return the last added State
00038     const State* const 
00039     SC_Listing::getLastAdded() const {
00040         return *(stateList.rbegin());
00041     }
00042     
00044 
00045       // Returns a list of all added States.
00046       // @return the State list
00047     const SC_Listing::List&
00048     SC_Listing::getList() const {
00049         return stateList;
00050     }
00051     
00052 
00053 } // namespace ell
00054 
00055 namespace ell {
00056     
00057     SC_ListingK::SC_ListingK(const size_t length)
00058       : stateList(length,NULL)
00059         , curEnd(0)
00060         , addedTotal(0)
00061     {
00062         assertbiu(length > 0, "the minimal list length should be 1");
00063     }
00064     
00065     SC_ListingK::~SC_ListingK()
00066     {
00067           // delete all collected State objects
00068         for (   List::iterator it = stateList.begin();
00069                 it != stateList.end(); it++ ) 
00070         {
00071             delete *it;
00072         }
00073           // clear NULL pointer list
00074         stateList.clear();
00075     }
00076 
00077       // This function is used to track all added intermediate States.
00078       // @param s the added State
00079     void 
00080     SC_ListingK::add(const State& s) {
00081           // count add
00082         addedTotal++;
00083         
00084           // get index of next position to overwrite
00085         curEnd = (curEnd+1) % stateList.size();
00086         
00087           // store a copy of s
00088         stateList[curEnd] = s.clone(stateList[curEnd]);
00089     }
00090     
00091       // Returns number of added States.
00092       // @return the number of added states
00093     size_t 
00094     SC_ListingK::size() const {
00095         return addedTotal;
00096     }
00097      
00098       // Returns last added State.
00099       // @return the last added State
00100     const State* const 
00101     SC_ListingK::getLastAdded() const {
00102         return stateList[curEnd];
00103     }
00104 
00105     SC_ListingK::iterator 
00106     SC_ListingK::getList() const {
00107         return iterator( (curEnd+1)%stateList.size(), this);
00108     }
00109 
00110 } // namespace ell