summaryrefslogtreecommitdiff
path: root/src/context/cdlist.h
diff options
context:
space:
mode:
authorTim King <taking@cs.nyu.edu>2012-03-02 16:32:16 +0000
committerTim King <taking@cs.nyu.edu>2012-03-02 16:32:16 +0000
commit730c6a6baa994a646af08c32151ba487d957d383 (patch)
treee076d12c21ed3744047a64e0719d0f86761efc51 /src/context/cdlist.h
parent45a138c326da72890bf889a3670aad503ef4aa1e (diff)
Renamed CDQueue to CDTrailQueue and CDQueue2 to CDQueue. Small changes to function names and documentation.
Diffstat (limited to 'src/context/cdlist.h')
-rw-r--r--src/context/cdlist.h52
1 files changed, 32 insertions, 20 deletions
diff --git a/src/context/cdlist.h b/src/context/cdlist.h
index da101e1a6..cb9be07d3 100644
--- a/src/context/cdlist.h
+++ b/src/context/cdlist.h
@@ -56,15 +56,22 @@ public:
protected:
- static const size_t INITIAL_SIZE = 10;
- static const size_t GROWTH_FACTOR = 2;
-
/**
* d_list is a dynamic array of objects of type T.
*/
T* d_list;
/**
+ * Number of objects in d_list
+ */
+ size_t d_size;
+
+private:
+
+ static const size_t INITIAL_SIZE = 10;
+ static const size_t GROWTH_FACTOR = 2;
+
+ /**
* Whether to call the destructor when items are popped from the
* list. True by default, but can be set to false by setting the
* second argument in the constructor to false.
@@ -72,11 +79,6 @@ protected:
bool d_callDestructor;
/**
- * Number of objects in d_list
- */
- size_t d_size;
-
- /**
* Allocated size of d_list.
*/
size_t d_sizeAlloc;
@@ -86,6 +88,7 @@ protected:
*/
Allocator d_allocator;
+protected:
/**
* Private copy constructor used only by save(). d_list and
* d_sizeAlloc are not copied: only the base class information and
@@ -94,8 +97,8 @@ protected:
CDList(const CDList<T, Allocator>& l) :
ContextObj(l),
d_list(NULL),
- d_callDestructor(false),
d_size(l.d_size),
+ d_callDestructor(false),
d_sizeAlloc(0),
d_allocator(l.d_allocator) {
Debug("cdlist") << "copy ctor: " << this
@@ -103,6 +106,7 @@ protected:
<< " size " << d_size << std::endl;
}
+private:
/**
* Reallocate the array with more space.
* Throws bad_alloc if memory allocation fails.
@@ -163,6 +167,7 @@ protected:
return data;
}
+protected:
/**
* Implementation of mandatory ContextObj method restore: simply
* restores the previous size. Note that the list pointer and the
@@ -174,24 +179,31 @@ protected:
<< " data == " << data
<< " call dtor == " << this->d_callDestructor
<< " d_list == " << this->d_list << std::endl;
- removeLastUntil(((CDList<T, Allocator>*)data)->d_size);
+ truncateList(((CDList<T, Allocator>*)data)->d_size);
Debug("cdlist") << "restore " << this
<< " level " << this->getContext()->getLevel()
<< " size back to " << this->d_size
<< " sizeAlloc at " << this->d_sizeAlloc << std::endl;
}
- /** Remove the elements from the given indices to the last.
- * You should use this function only when you know what you do.
+ /**
+ * Given a size parameter smaller than d_size, truncateList()
+ * removes the elements from the end of the list until d_size equals size.
+ *
+ * WARNING! You should only use this function when you know what you are doing.
+ * This is a primitive operation with strange context dependent behavior!
+ * It is up to the user of the function to ensure that the saved d_size values
+ * at lower context levels are less than or equal to size.
*/
- inline void removeLastUntil(const size_t size){
- if(this->d_callDestructor) {
- while(this->d_size != size) {
- --this->d_size;
- this->d_allocator.destroy(&this->d_list[this->d_size]);
+ void truncateList(const size_t size){
+ Assert(size <= d_size);
+ if(d_callDestructor) {
+ while(d_size != size) {
+ --d_size;
+ d_allocator.destroy(&d_list[d_size]);
}
} else {
- this->d_size = size;
+ d_size = size;
}
}
@@ -205,8 +217,8 @@ public:
const Allocator& alloc = Allocator()) :
ContextObj(context),
d_list(NULL),
- d_callDestructor(callDestructor),
d_size(0),
+ d_callDestructor(callDestructor),
d_sizeAlloc(0),
d_allocator(alloc) {
}
@@ -218,8 +230,8 @@ public:
const Allocator& alloc = Allocator()) :
ContextObj(allocatedInCMM, context),
d_list(NULL),
- d_callDestructor(callDestructor),
d_size(0),
+ d_callDestructor(callDestructor),
d_sizeAlloc(0),
d_allocator(alloc) {
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback