[Scummvm-cvs-logs] SF.net SVN: scummvm:[40163] scummvm/trunk
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Mon Apr 27 16:23:29 CEST 2009
Revision: 40163
http://scummvm.svn.sourceforge.net/scummvm/?rev=40163&view=rev
Author: fingolfin
Date: 2009-04-27 14:23:20 +0000 (Mon, 27 Apr 2009)
Log Message:
-----------
COMMON: Made sure Common::List and Common::array each have all front/back/push_back/push_front, as have their STL counterparts
Modified Paths:
--------------
scummvm/trunk/common/array.h
scummvm/trunk/common/list.h
scummvm/trunk/test/common/array.h
scummvm/trunk/test/common/list.h
scummvm/trunk/test/common/queue.h
Modified: scummvm/trunk/common/array.h
===================================================================
--- scummvm/trunk/common/array.h 2009-04-27 14:21:39 UTC (rev 40162)
+++ scummvm/trunk/common/array.h 2009-04-27 14:23:20 UTC (rev 40163)
@@ -76,6 +76,31 @@
_size += array._size;
}
+ void pop_back() {
+ assert(_size > 0);
+ _size--;
+ }
+
+ T &front() {
+ assert(_size > 0);
+ return _storage[0];
+ }
+
+ const T &front() const {
+ assert(_size > 0);
+ return _storage[0];
+ }
+
+ T &back() {
+ assert(_size > 0);
+ return _storage[_size-1];
+ }
+
+ const T &back() const {
+ assert(_size > 0);
+ return _storage[_size-1];
+ }
+
void insert_at(int idx, const T &element) {
assert(idx >= 0 && (uint)idx <= _size);
ensureCapacity(_size + 1);
Modified: scummvm/trunk/common/list.h
===================================================================
--- scummvm/trunk/common/list.h 2009-04-27 14:21:39 UTC (rev 40162)
+++ scummvm/trunk/common/list.h 2009-04-27 14:23:20 UTC (rev 40163)
@@ -63,14 +63,6 @@
clear();
}
- void push_front(const t_T &element) {
- insert(begin(), element);
- }
-
- void push_back(const t_T &element) {
- insert(end(), element);
- }
-
void insert(iterator pos, const t_T &element) {
ListInternal::NodeBase *newNode = new Node(element);
@@ -127,11 +119,26 @@
++i;
}
+ void push_front(const t_T &element) {
+ // TODO: Bypass iterators here for improved efficency
+ insert(begin(), element);
+ }
+
+ void push_back(const t_T &element) {
+ // TODO: Bypass iterators here for improved efficency
+ insert(end(), element);
+ }
+
void pop_front() {
- iterator i = begin();
- i = erase(i);
+ // TODO: Bypass iterators here for improved efficency
+ erase(begin());
}
+ void pop_back() {
+ // TODO: Bypass iterators here for improved efficency
+ erase(reverse_begin());
+ }
+
t_T &front() {
return static_cast<Node *>(_anchor._next)->_data;
}
@@ -148,7 +155,6 @@
return static_cast<Node *>(_anchor._prev)->_data;
}
-
List<t_T> &operator=(const List<t_T> &list) {
if (this != &list) {
iterator i;
Modified: scummvm/trunk/test/common/array.h
===================================================================
--- scummvm/trunk/test/common/array.h 2009-04-27 14:21:39 UTC (rev 40162)
+++ scummvm/trunk/test/common/array.h 2009-04-27 14:23:20 UTC (rev 40163)
@@ -164,4 +164,24 @@
TS_ASSERT_EQUALS( array2.size(), (unsigned int)3 );
}
+
+ void test_front_back_push_pop() {
+ Common::Array<int> container;
+
+ container.push_back( 42);
+ container.push_back(-23);
+
+ TS_ASSERT_EQUALS(container.front(), 42);
+ TS_ASSERT_EQUALS(container.back(), -23);
+
+ container.front() = -17;
+ container.back() = 163;
+ TS_ASSERT_EQUALS(container.front(), -17);
+ TS_ASSERT_EQUALS(container.back(), 163);
+
+ container.pop_back();
+ TS_ASSERT_EQUALS(container.front(), -17);
+ TS_ASSERT_EQUALS(container.back(), -17);
+ }
+
};
Modified: scummvm/trunk/test/common/list.h
===================================================================
--- scummvm/trunk/test/common/list.h 2009-04-27 14:21:39 UTC (rev 40162)
+++ scummvm/trunk/test/common/list.h 2009-04-27 14:23:20 UTC (rev 40163)
@@ -168,4 +168,23 @@
TS_ASSERT( container.begin() == container.end() );
TS_ASSERT( container.reverse_begin() == container.end() );
}
+
+ void test_front_back_push_pop() {
+ Common::List<int> container;
+
+ container.push_back( 42);
+ container.push_back(-23);
+
+ TS_ASSERT_EQUALS(container.front(), 42);
+ TS_ASSERT_EQUALS(container.back(), -23);
+
+ container.front() = -17;
+ container.back() = 163;
+ TS_ASSERT_EQUALS(container.front(), -17);
+ TS_ASSERT_EQUALS(container.back(), 163);
+
+ container.pop_front();
+ TS_ASSERT_EQUALS(container.front(), 163);
+ TS_ASSERT_EQUALS(container.back(), 163);
+ }
};
Modified: scummvm/trunk/test/common/queue.h
===================================================================
--- scummvm/trunk/test/common/queue.h 2009-04-27 14:21:39 UTC (rev 40162)
+++ scummvm/trunk/test/common/queue.h 2009-04-27 14:23:20 UTC (rev 40163)
@@ -32,22 +32,23 @@
TS_ASSERT_EQUALS(queue.size(), 2);
}
- void test_front_back_pop() {
- Common::Queue<int> queue;
+ void test_front_back_push_pop() {
+ Common::Queue<int> container;
- queue.push( 42);
- queue.push(-23);
+ container.push( 42);
+ container.push(-23);
- TS_ASSERT_EQUALS(queue.front(), 42);
- TS_ASSERT_EQUALS(queue.back(), -23);
+ TS_ASSERT_EQUALS(container.front(), 42);
+ TS_ASSERT_EQUALS(container.back(), -23);
- queue.front() = -23;
- queue.back() = 42;
- TS_ASSERT_EQUALS(queue.front(), -23);
- TS_ASSERT_EQUALS(queue.back(), 42);
+ container.front() = -17;
+ container.back() = 163;
+ TS_ASSERT_EQUALS(container.front(), -17);
+ TS_ASSERT_EQUALS(container.back(), 163);
- queue.pop();
- TS_ASSERT_EQUALS(queue.front(), 42);
+ container.pop();
+ TS_ASSERT_EQUALS(container.front(), 163);
+ TS_ASSERT_EQUALS(container.back(), 163);
}
void test_assign() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list