Skip to content

Commit

Permalink
polymorphic indexed_list fixes:
Browse files Browse the repository at this point in the history
1) indexed_list no longer has virtual methods. It's not actually subclassed
and there is very rarely good reason to subclass collection classes.
2) Added a virtual dtor to indexed_list_object which is intended to be
subclassed. This allows derived dtors to be called if the object is
deleted with a indexed_list_object*.
  • Loading branch information
jesse99 authored and brson committed Dec 16, 2012
1 parent fc740a7 commit cf1c3d2
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/rt/util/indexed_list.h
Expand Up @@ -17,6 +17,7 @@

class indexed_list_object {
public:
virtual ~indexed_list_object() {}
int32_t list_index;
};

Expand All @@ -39,22 +40,22 @@ class indexed_list_element : public indexed_list_object {
template<typename T> class indexed_list {
array_list<T*> list;
public:
virtual int32_t append(T *value);
virtual bool pop(T **value);
int32_t append(T *value);
bool pop(T **value);
/**
* Same as pop(), except that it returns NULL if the list is empty.
*/
virtual T* pop_value();
virtual size_t length() const {
T* pop_value();
size_t length() const {
return list.size();
}
virtual bool is_empty() const {
bool is_empty() const {
return list.is_empty();
}
virtual int32_t remove(T* value);
virtual T * operator[](int32_t index);
virtual const T * operator[](int32_t index) const;
virtual ~indexed_list() {}
int32_t remove(T* value);
T * operator[](int32_t index);
const T * operator[](int32_t index) const;
~indexed_list() {}
};

template<typename T> int32_t
Expand Down

0 comments on commit cf1c3d2

Please sign in to comment.