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) 2009 Soeren Sonnenburg, Fabio De Bona 00008 * Copyright (C) 2009 Fraunhofer Institute FIRST and Max-Planck-Society 00009 */ 00010 00011 #ifndef __GCARRAY_H__ 00012 #define __GCARRAY_H__ 00013 00014 #include <shogun/base/SGObject.h> 00015 #include <shogun/lib/common.h> 00016 00017 namespace shogun 00018 { 00027 template <class T> class CGCArray : public CSGObject 00028 { 00029 public: 00034 CGCArray(int32_t sz) : CSGObject() 00035 { 00036 ASSERT(sz>0); 00037 array = new T[sz]; 00038 size=sz; 00039 } 00040 00042 virtual ~CGCArray() 00043 { 00044 for (int32_t i=0; i<size; i++) 00045 SG_UNREF(array[i]); 00046 delete[] array; 00047 } 00048 00054 inline void set(T element, int32_t index) 00055 { 00056 ASSERT(index>=0); 00057 ASSERT(index<size); 00058 SG_UNREF(array[index]); 00059 array[index]=element; 00060 SG_REF(element); 00061 } 00062 00068 inline T get(int32_t index) 00069 { 00070 ASSERT(index>=0); 00071 ASSERT(index<size); 00072 T element=array[index]; 00073 SG_REF(element); //??? 00074 return element; 00075 } 00076 00081 virtual const char* get_name() const { return "GCArray"; } 00082 00083 protected: 00085 T* array; 00087 int32_t size; 00088 }; 00089 } 00090 #endif //__GCARRAY_H__