SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IndirectObject.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
8  * Copyright (C) 2009 Fraunhofer Institute FIRST and Max Planck Society
9  */
10 #ifndef __INDIRECTOBJECT_H__
11 #define __INDIRECTOBJECT_H__
12 
13 #include <shogun/lib/common.h>
14 
15 namespace shogun
16 {
23 template <class T, class P> class CIndirectObject
24 {
25  public:
30  {
31  }
32 
36  CIndirectObject(int32_t idx)
37  {
38  index=idx;
39  }
40 
45  static void set_array(P a)
46  {
47  array=a;
48  }
49 
54  static P get_array()
55  {
56  return array;
57  }
58 
63  static void init_slice(CIndirectObject<T,P>* a, int32_t len, int32_t start=0, int32_t stop=-1)
64  {
65  if (stop==-1)
66  stop=len;
67 
68  for (int32_t i=start; i<stop && i<len; i++)
69  a[i].index=i;
70  }
71 
76  {
77  index=x.index;
78  return *this;
79  }
80 
85  T operator|(const CIndirectObject<T,P>& x) const
86  {
87  return (*array)[index] | *(x.array)[x.index];
88  }
89 
94  const T operator&(const CIndirectObject<T,P>& x) const
95  {
96  return (*array)[index] & *(x.array)[x.index];
97  }
98 
105  T operator<<(int shift)
106  {
107  return (*array)[index] << shift;
108  }
109 
116  T operator>>(int shift)
117  {
118  return (*array)[index] >> shift;
119  }
120 
125  T operator^(const CIndirectObject<T,P>& x) const
126  {
127  return (*array)[index] ^ *(x.array)[x.index];
128  }
129 
134  T operator+(const CIndirectObject<T,P> &x) const
135  {
136  return (*array)[index] + *(x.array)[x.index];
137  }
138 
143  T operator-(const CIndirectObject<T,P> &x) const
144  {
145  return (*array)[index] - *(x.array)[x.index];
146  }
147 
152  T operator/(const CIndirectObject<T,P> &x) const
153  {
154  return (*array)[index] / *(x.array)[x.index];
155  }
156 
161  T operator*(const CIndirectObject<T,P> &x) const
162  {
163  return (*array)[index] * *(x.array)[x.index];
164  }
165 
171  {
172  (*array)[index]+=*(x.array)[x.index];
173  return *this;
174  }
175 
181  {
182  (*array)[index]-=*(x.array)[x.index];
183  return *this;
184  }
185 
191  {
192  (*array)[index]*=*(x.array)[x.index];
193  return *this;
194  }
195 
201  {
202  (*array)[index]/=*(x.array)[x.index];
203  return *this;
204  }
205 
210  bool operator==(const CIndirectObject<T,P> &x) const
211  {
212  return (*array)[index]==*(x.array)[x.index];
213  }
214 
219  bool operator>=(const CIndirectObject<T,P> &x) const
220  {
221  return (*array)[index]>=*(x.array)[x.index];
222  }
223 
228  bool operator<=(const CIndirectObject<T,P> &x) const
229  {
230  return (*array)[index]<=*(x.array)[x.index];
231  }
232 
237  bool operator>(const CIndirectObject<T,P> &x) const
238  {
239  return (*array)[index]>(*(x.array))[x.index];
240  }
241 
246  bool operator<(const CIndirectObject<T,P> &x) const
247  {
248  return (*array)[index]<(*(x.array))[x.index];
249  }
250 
255  bool operator!=(const CIndirectObject<T,P> &x) const
256  {
257  return (*array)[index]!=(*(x.array))[x.index];
258  }
259 
267  {
268  (*array)[index]|=(*(x.array))[x.index];
269  return *this;
270  }
271 
279  {
280  (*array)[index]&=(*(x.array))[x.index];
281  return *this;
282  }
283 
291  {
292  (*array)[index]^=(*(x.array))[x.index];
293  return *this;
294  }
295 
303  {
304  *this=*this<<shift;
305  return *this;
306  }
307 
315  {
316  *this=*this>>shift;
317  return *this;
318  }
319 
322  {
323  return ~(*array)[index];
324  }
325 
327  operator T() const { return (*array)[index]; }
328 
331  {
332  (*array)[index]--;
333  return *this;
334  }
335 
338  {
339  (*array)[index]++;
340  return *this;
341  }
342 
343  protected:
345  static P array;
346 
348  int32_t index;
349 };
350 
351 template <class T, class P> P CIndirectObject<T,P>::array;
352 }
353 #endif //__INDIRECTOBJECT_H__

SHOGUN Machine Learning Toolbox - Documentation