Commit ee0eaabe authored by Fabio D'Urso's avatar Fabio D'Urso Committed by Albert Astals Cid

Added Array::remove (and Object::arrayRemove)

parent d6a1b7dc
......@@ -14,6 +14,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2005 Kristian Høgsberg <krh@redhat.com>
// Copyright (C) 2012 Fabio D'Urso <fabiodurso@hotmail.it>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
......@@ -64,6 +65,18 @@ void Array::add(Object *elem) {
++length;
}
void Array::remove(int i) {
if (i < 0 || i >= length) {
#ifdef DEBUG_MEM
abort();
#else
return;
#endif
}
--length;
memmove( elems + i, elems + i + 1, sizeof(elems[0]) * (length - i) );
}
Object *Array::get(int i, Object *obj) {
if (i < 0 || i >= length) {
#ifdef DEBUG_MEM
......
......@@ -14,6 +14,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2005 Kristian Høgsberg <krh@redhat.com>
// Copyright (C) 2012 Fabio D'Urso <fabiodurso@hotmail.it>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
......@@ -54,6 +55,9 @@ public:
// Add an element.
void add(Object *elem);
// Remove an element by position
void remove(int i);
// Accessors.
Object *get(int i, Object *obj);
Object *getNF(int i, Object *obj);
......
......@@ -17,6 +17,7 @@
// Copyright (C) 2008 Kees Cook <kees@outflux.net>
// Copyright (C) 2008, 2010 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2009 Jakub Wilk <ubanus@users.sf.net>
// Copyright (C) 2012 Fabio D'Urso <fabiodurso@hotmail.it>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
......@@ -205,6 +206,7 @@ public:
// Array accessors.
int arrayGetLength();
void arrayAdd(Object *elem);
void arrayRemove(int i);
Object *arrayGet(int i, Object *obj);
Object *arrayGetNF(int i, Object *obj);
......@@ -273,6 +275,9 @@ inline int Object::arrayGetLength()
inline void Object::arrayAdd(Object *elem)
{ OBJECT_TYPE_CHECK(objArray); array->add(elem); }
inline void Object::arrayRemove(int i)
{ OBJECT_TYPE_CHECK(objArray); array->remove(i); }
inline Object *Object::arrayGet(int i, Object *obj)
{ OBJECT_TYPE_CHECK(objArray); return array->get(i, obj); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment