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>
00016 
00017 namespace shogun
00018 {
00019 #define IGNORE_IN_CLASSLIST
00020 
00028 IGNORE_IN_CLASSLIST template <class T> class CGCArray : public CSGObject
00029 {
00030     public:
00032         CGCArray() : CSGObject()
00033         {
00034             SG_UNSTABLE("CGCArray::CGCArray()", "\n");
00035 
00036             array = NULL;
00037             size=0;
00038         }
00039 
00044         CGCArray(int32_t sz) : CSGObject()
00045         {
00046             ASSERT(sz>0);
00047             array = SG_MALLOC(T, sz);
00048             size=sz;
00049         }
00050 
00052         virtual ~CGCArray()
00053         {
00054             for (int32_t i=0; i<size; i++)
00055                 SG_UNREF(array[i]);
00056             SG_FREE(array);
00057         }
00058 
00064         inline void set(T element, int32_t index)
00065         {
00066             ASSERT(index>=0);
00067             ASSERT(index<size);
00068             SG_UNREF(array[index]);
00069             array[index]=element;
00070             SG_REF(element);
00071         }
00072 
00078         inline T get(int32_t index)
00079         {
00080             ASSERT(index>=0);
00081             ASSERT(index<size);
00082             T element=array[index];
00083             SG_REF(element); //???
00084             return element;
00085         }
00086 
00091         virtual const char* get_name() const { return "GCArray"; }
00092 
00093     protected:
00095         T* array;
00097         int32_t size;
00098 };
00099 }
00100 #endif //__GCARRAY_H__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation