SHOGUN v0.9.0
|
00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 1999-2009 Soeren Sonnenburg 00008 * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society 00009 */ 00010 00011 #ifndef _DYNAMIC_ARRAY_H_ 00012 #define _DYNAMIC_ARRAY_H_ 00013 00014 #include "base/SGObject.h" 00015 #include "base/DynArray.h" 00016 #include "base/Parameter.h" 00017 00018 namespace shogun 00019 { 00028 template <class T> class CDynamicArray :public CSGObject 00029 { 00030 DynArray<T> m_array; 00031 00032 public: 00037 CDynamicArray(int32_t p_resize_granularity=128) 00038 : CSGObject() 00039 { 00040 set_generic<T>(); 00041 00042 m_parameters->add_vector(&m_array.array, 00043 &m_array.num_elements, "array", 00044 "Memory for dynamic array."); 00045 m_parameters->add(&m_array.last_element_idx, 00046 "last_element_idx", 00047 "Element with largest index."); 00048 m_parameters->add(&m_array.resize_granularity, 00049 "resize_granularity", 00050 "shrink/grow step size."); 00051 } 00052 00053 virtual ~CDynamicArray() {} 00054 00060 inline int32_t set_granularity(int32_t g) 00061 { return m_array.set_granularity(g); } 00062 00067 inline int32_t get_array_size(void) 00068 { return m_array.get_array_size(); } 00069 00074 inline int32_t get_num_elements(void) const 00075 { return m_array.get_num_elements(); } 00076 00084 inline T get_element(int32_t index) const 00085 { return m_array.get_element(index); } 00086 00094 inline T get_element_safe(int32_t index) const 00095 { return m_array.get_element_safe(index); } 00096 00103 inline bool set_element(T element, int32_t index) 00104 { return m_array.set_element(element, index); } 00105 00112 inline bool insert_element(T element, int32_t index) 00113 { return m_array.insert_element(element, index); } 00114 00120 inline bool append_element(T element) 00121 { return m_array.append_element(element); } 00122 00128 inline void push_back(T element) 00129 { m_array.push_back(element); } 00130 00134 inline void pop_back(void) 00135 { m_array.pop_back(); } 00136 00142 inline T back(void) 00143 { return m_array.back(); } 00144 00151 inline int32_t find_element(T element) 00152 { return m_array.find_element(element); } 00153 00160 inline bool delete_element(int32_t idx) 00161 { return m_array.delete_element(idx); } 00162 00168 inline bool resize_array(int32_t n) 00169 { return m_array.resize_array(n); } 00170 00178 inline T* get_array(void) 00179 { return m_array.get_array(); } 00180 00187 inline void set_array(T* p_array, int32_t p_num_elements, 00188 int32_t array_size) 00189 { m_array.set_array(p_array, p_num_elements, array_size); } 00190 00192 inline void clear_array(void) 00193 { m_array.clear_array(); } 00194 00204 inline T operator[](int32_t index) const 00205 { return m_array[index]; } 00206 00212 inline CDynamicArray<T>& operator=(CDynamicArray<T>& orig) 00213 { 00214 m_array = orig.m_array; 00215 return *this; 00216 } 00217 00219 inline virtual const char* get_name() const 00220 { return "DynamicArray"; } 00221 }; 00222 } 00223 #endif /* _DYNAMIC_ARRAY_H_ */