Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef _DYNAMIC_ARRAY_H_
00012 #define _DYNAMIC_ARRAY_H_
00013
00014 #include <shogun/base/SGObject.h>
00015 #include <shogun/base/DynArray.h>
00016 #include <shogun/base/Parameter.h>
00017
00018 namespace shogun
00019 {
00028 template <class T> class CDynamicArray :public CSGObject
00029 {
00030 public:
00035 CDynamicArray(int32_t p_resize_granularity=128)
00036 : CSGObject()
00037 {
00038 set_generic<T>();
00039
00040 m_parameters->add_vector(&m_array.array,
00041 &m_array.num_elements, "array",
00042 "Memory for dynamic array.");
00043 m_parameters->add(&m_array.last_element_idx,
00044 "last_element_idx",
00045 "Element with largest index.");
00046 m_parameters->add(&m_array.resize_granularity,
00047 "resize_granularity",
00048 "shrink/grow step size.");
00049 }
00050
00051 virtual ~CDynamicArray() {}
00052
00058 inline int32_t set_granularity(int32_t g)
00059 {
00060 return m_array.set_granularity(g);
00061 }
00062
00067 inline int32_t get_array_size()
00068 {
00069 return m_array.get_array_size();
00070 }
00071
00076 inline int32_t get_num_elements() const
00077 {
00078 return m_array.get_num_elements();
00079 }
00080
00088 inline T get_element(int32_t index) const
00089 {
00090 return m_array.get_element(index);
00091 }
00092
00100 inline T get_element_safe(int32_t index) const
00101 {
00102 return m_array.get_element_safe(index);
00103 }
00104
00111 inline bool set_element(T element, int32_t index)
00112 {
00113 return m_array.set_element(element, index);
00114 }
00115
00122 inline bool insert_element(T element, int32_t index)
00123 {
00124 return m_array.insert_element(element, index);
00125 }
00126
00132 inline bool append_element(T element)
00133 {
00134 return m_array.append_element(element);
00135 }
00136
00142 inline void push_back(T element)
00143 { m_array.push_back(element); }
00144
00148 inline void pop_back()
00149 {
00150 m_array.pop_back();
00151 }
00152
00158 inline T back()
00159 {
00160 return m_array.back();
00161 }
00162
00169 inline int32_t find_element(T element)
00170 {
00171 return m_array.find_element(element);
00172 }
00173
00180 inline bool delete_element(int32_t idx)
00181 {
00182 return m_array.delete_element(idx);
00183 }
00184
00190 inline bool resize_array(int32_t n)
00191 {
00192 return m_array.resize_array(n);
00193 }
00194
00202 inline T* get_array() const
00203 {
00204 return m_array.get_array();
00205 }
00206
00213 inline void set_array(T* p_array, int32_t p_num_elements,
00214 int32_t array_size)
00215 {
00216 m_array.set_array(p_array, p_num_elements, array_size);
00217 }
00218
00220 inline void clear_array()
00221 {
00222 m_array.clear_array();
00223 }
00224
00234 inline T operator[](int32_t index) const
00235 {
00236 return m_array[index];
00237 }
00238
00244 inline CDynamicArray<T>& operator=(CDynamicArray<T>& orig)
00245 {
00246 m_array = orig.m_array;
00247 return *this;
00248 }
00249
00251 inline void shuffle() { m_array.shuffle(); }
00252
00254 inline virtual const char* get_name() const
00255 {
00256 return "DynamicArray";
00257 }
00258
00259 protected:
00260
00262 DynArray<T> m_array;
00263 };
00264 }
00265 #endif