GCArray.h

Go to the documentation of this file.
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>
00024 template <class T> class CGCArray : public CSGObject
00025 {
00026     public:
00031         CGCArray(int32_t sz) : CSGObject()
00032         {
00033             ASSERT(sz>0);
00034             array = new T[sz];
00035             size=sz;
00036         }
00037 
00039         virtual ~CGCArray()
00040         {
00041             for (int32_t i=0; i<size; i++)
00042                 SG_UNREF(array[i]);
00043             delete[] array;
00044         }
00045 
00051         inline void set(T element, int32_t index)
00052         {
00053             ASSERT(index>=0);
00054             ASSERT(index<size);
00055             SG_UNREF(array[index]);
00056             array[index]=element;
00057             SG_REF(element);
00058         }
00059 
00065         inline T get(int32_t index)
00066         {
00067             ASSERT(index>=0);
00068             ASSERT(index<size);
00069             T element=array[index];
00070             SG_REF(element); //???
00071             return element;
00072         }
00073 
00078         virtual const char* get_name() const { return "GCArray"; }
00079 
00080     protected:
00082         T* array;
00084         int32_t size;
00085 };
00086 #endif //__GCARRAY_H__

SHOGUN Machine Learning Toolbox - Documentation