SHOGUN  4.1.0
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
GCArray.h
浏览该文件的文档.
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__
CGCArray(int32_t sz)
Definition: GCArray.h:47
virtual ~CGCArray()
Definition: GCArray.h:55
void set(T element, int32_t index)
Definition: GCArray.h:67
Template class GCArray implements a garbage collecting static array.
Definition: GCArray.h:31
#define SG_REF(x)
Definition: SGObject.h:51
T * array
array
Definition: GCArray.h:98
virtual const char * get_name() const
Definition: GCArray.h:94
#define ASSERT(x)
Definition: SGIO.h:201
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:112
#define IGNORE_IN_CLASSLIST
Definition: GCArray.h:22
int32_t size
size of array
Definition: GCArray.h:100
#define SG_UNREF(x)
Definition: SGObject.h:52
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
#define SG_UNSTABLE(func,...)
Definition: SGIO.h:132

SHOGUN 机器学习工具包 - 项目文档