00001 /*MT* 00002 00003 MediaTomb - http://www.mediatomb.cc/ 00004 00005 array.h - this file is part of MediaTomb. 00006 00007 Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>, 00008 Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc> 00009 00010 Copyright (C) 2006-2010 Gena Batyan <bgeradz@mediatomb.cc>, 00011 Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>, 00012 Leonhard Wimmer <leo@mediatomb.cc> 00013 00014 MediaTomb is free software; you can redistribute it and/or modify 00015 it under the terms of the GNU General Public License version 2 00016 as published by the Free Software Foundation. 00017 00018 MediaTomb is distributed in the hope that it will be useful, 00019 but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 GNU General Public License for more details. 00022 00023 You should have received a copy of the GNU General Public License 00024 version 2 along with MediaTomb; if not, write to the Free Software 00025 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 00026 00027 $Id: array.h 2081 2010-03-23 20:18:00Z lww $ 00028 */ 00029 00031 00032 #ifndef __ZMMF_ARRAY_H__ 00033 #define __ZMMF_ARRAY_H__ 00034 00035 #include "zmm/zmm.h" 00036 00037 #define DEFAULT_ARRAY_CAPACITY 16 00038 00039 namespace zmm 00040 { 00041 00042 class ArrayBase 00043 { 00044 public: 00045 ArrayBase(); 00046 ~ArrayBase(); 00047 void init(int capacity); 00048 void append(Object *el); 00049 void set(Object *el, int index); 00050 Object *get(int index); 00051 void remove(int index, int count); 00052 void removeUnordered(int index); 00053 void clear(); 00054 void insert(int index, Object *el); 00055 inline int size() { return siz; } 00056 void optimize(); 00057 protected: 00058 void resize(int requiredSize); 00059 public: 00060 Object **arr; 00061 protected: 00062 int siz; 00063 int capacity; 00064 }; 00065 00066 00067 template <class T> 00068 class Array : public Object 00069 { 00070 protected: 00071 ArrayBase base; 00072 00073 public: 00074 inline Array() : Object() 00075 { 00076 base.init(DEFAULT_ARRAY_CAPACITY); 00077 } 00078 inline Array(int capacity) : Object() 00079 { 00080 base.init(capacity); 00081 } 00082 00083 inline void append(Ref<T> el) 00084 { 00085 base.append(el.getPtr()); 00086 } 00087 inline void set(Ref<T> el, int index) 00088 { 00089 base.set(el.getPtr(), index); 00090 } 00091 inline Ref<T> get(int index) 00092 { 00093 return Ref<T>( (T *)base.get(index) ); 00094 } 00095 inline void remove(int index, int count=1) 00096 { 00097 base.remove(index, count); 00098 } 00099 inline void removeUnordered(int index) 00100 { 00101 base.removeUnordered(index); 00102 } 00103 inline void insert(int index, Ref<T> el) 00104 { 00105 base.insert(index, el.getPtr()); 00106 } 00107 inline int size() 00108 { 00109 return base.size(); 00110 } 00111 inline void clear() 00112 { 00113 return base.clear(); 00114 } 00115 inline void optimize() 00116 { 00117 base.optimize(); 00118 } 00119 00120 inline Object **getObjectArray() 00121 { 00122 return base.arr; 00123 } 00124 }; 00125 00126 00127 } // namespace 00128 00129 #endif // __ZMMF_ARRAY_H__
1.6.1