SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GCArray.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2009 Soeren Sonnenburg, Fabio De Bona
8  * Copyright (C) 2009 Fraunhofer Institute FIRST and Max-Planck-Society
9  */
10 
11 #ifndef __GCARRAY_H__
12 #define __GCARRAY_H__
13 
14 #include <shogun/lib/config.h>
15 
16 #include <shogun/base/SGObject.h>
17 #include <shogun/lib/common.h>
18 #include <shogun/io/SGIO.h>
19 
20 namespace shogun
21 {
22 #define IGNORE_IN_CLASSLIST
23 
31 IGNORE_IN_CLASSLIST template <class T> class CGCArray : public CSGObject
32 {
33  public:
36  {
37  SG_UNSTABLE("CGCArray::CGCArray()", "\n")
38 
39  array = NULL;
40  size=0;
41  }
42 
47  CGCArray(int32_t sz) : CSGObject()
48  {
49  ASSERT(sz>0)
50  array = SG_CALLOC(T, sz);
51  size=sz;
52  }
53 
55  virtual ~CGCArray()
56  {
57  for (int32_t i=0; i<size; i++)
58  SG_UNREF(array[i]);
59  SG_FREE(array);
60  }
61 
67  inline void set(T element, int32_t index)
68  {
69  ASSERT(index>=0)
70  ASSERT(index<size)
71  SG_REF(element);
72  SG_UNREF(array[index]);
73  array[index]=element;
74  }
75 
81  inline T get(int32_t index)
82  {
83  ASSERT(index>=0)
84  ASSERT(index<size)
85  T element=array[index];
86  SG_REF(element); //???
87  return element;
88  }
89 
94  virtual const char* get_name() const { return "GCArray"; }
95 
96  protected:
98  T* array;
100  int32_t size;
101 };
102 }
103 #endif //__GCARRAY_H__

SHOGUN Machine Learning Toolbox - Documentation