SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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/config.h>
14 
15 #include <shogun/lib/common.h>
16 
17 namespace shogun
18 {
25 template <class T, class P> class CIndirectObject
26 {
27  public:
32  {
33  }
34 
38  CIndirectObject(int32_t idx)
39  {
40  index=idx;
41  }
42 
47  static void set_array(P a)
48  {
49  array=a;
50  }
51 
56  static P get_array()
57  {
58  return array;
59  }
60 
65  static void init_slice(CIndirectObject<T,P>* a, int32_t len, int32_t start=0, int32_t stop=-1)
66  {
67  if (stop==-1)
68  stop=len;
69 
70  for (int32_t i=start; i<stop && i<len; i++)
71  a[i].index=i;
72  }
73 
78  {
79  index=x.index;
80  return *this;
81  }
82 
87  T operator|(const CIndirectObject<T,P>& x) const
88  {
89  return (*array)[index] | *(x.array)[x.index];
90  }
91 
96  const T operator&(const CIndirectObject<T,P>& x) const
97  {
98  return (*array)[index] & *(x.array)[x.index];
99  }
100 
107  T operator<<(int shift)
108  {
109  return (*array)[index] << shift;
110  }
111 
118  T operator>>(int shift)
119  {
120  return (*array)[index] >> shift;
121  }
122 
127  T operator^(const CIndirectObject<T,P>& x) const
128  {
129  return (*array)[index] ^ *(x.array)[x.index];
130  }
131 
136  T operator+(const CIndirectObject<T,P> &x) const
137  {
138  return (*array)[index] + *(x.array)[x.index];
139  }
140 
145  T operator-(const CIndirectObject<T,P> &x) const
146  {
147  return (*array)[index] - *(x.array)[x.index];
148  }
149 
154  T operator/(const CIndirectObject<T,P> &x) const
155  {
156  return (*array)[index] / *(x.array)[x.index];
157  }
158 
163  T operator*(const CIndirectObject<T,P> &x) const
164  {
165  return (*array)[index] * *(x.array)[x.index];
166  }
167 
173  {
174  (*array)[index]+=*(x.array)[x.index];
175  return *this;
176  }
177 
183  {
184  (*array)[index]-=*(x.array)[x.index];
185  return *this;
186  }
187 
193  {
194  (*array)[index]*=*(x.array)[x.index];
195  return *this;
196  }
197 
203  {
204  (*array)[index]/=*(x.array)[x.index];
205  return *this;
206  }
207 
212  bool operator==(const CIndirectObject<T,P> &x) const
213  {
214  return (*array)[index]==*(x.array)[x.index];
215  }
216 
221  bool operator>=(const CIndirectObject<T,P> &x) const
222  {
223  return (*array)[index]>=*(x.array)[x.index];
224  }
225 
230  bool operator<=(const CIndirectObject<T,P> &x) const
231  {
232  return (*array)[index]<=*(x.array)[x.index];
233  }
234 
239  bool operator>(const CIndirectObject<T,P> &x) const
240  {
241  return (*array)[index]>(*(x.array))[x.index];
242  }
243 
248  bool operator<(const CIndirectObject<T,P> &x) const
249  {
250  return (*array)[index]<(*(x.array))[x.index];
251  }
252 
257  bool operator!=(const CIndirectObject<T,P> &x) const
258  {
259  return (*array)[index]!=(*(x.array))[x.index];
260  }
261 
269  {
270  (*array)[index]|=(*(x.array))[x.index];
271  return *this;
272  }
273 
281  {
282  (*array)[index]&=(*(x.array))[x.index];
283  return *this;
284  }
285 
293  {
294  (*array)[index]^=(*(x.array))[x.index];
295  return *this;
296  }
297 
305  {
306  *this=*this<<shift;
307  return *this;
308  }
309 
317  {
318  *this=*this>>shift;
319  return *this;
320  }
321 
324  {
325  return ~(*array)[index];
326  }
327 
329  operator T() const { return (*array)[index]; }
330 
333  {
334  (*array)[index]--;
335  return *this;
336  }
337 
340  {
341  (*array)[index]++;
342  return *this;
343  }
344 
345  protected:
347  static P array;
348 
350  int32_t index;
351 };
352 
353 template <class T, class P> P CIndirectObject<T,P>::array;
354 }
355 #endif //__INDIRECTOBJECT_H__
CIndirectObject< T, P > & operator*=(const CIndirectObject< T, P > &x)
CIndirectObject< T, P > & operator--()
CIndirectObject(int32_t idx)
T operator|(const CIndirectObject< T, P > &x) const
static void init_slice(CIndirectObject< T, P > *a, int32_t len, int32_t start=0, int32_t stop=-1)
CIndirectObject< T, P > & operator|=(const CIndirectObject< T, P > &x)
bool operator>(const CIndirectObject< T, P > &x) const
an array class that accesses elements indirectly via an index array.
bool operator>=(const CIndirectObject< T, P > &x) const
bool operator==(const CIndirectObject< T, P > &x) const
T operator^(const CIndirectObject< T, P > &x) const
bool operator!=(const CIndirectObject< T, P > &x) const
CIndirectObject< T, P > & operator/=(const CIndirectObject< T, P > &x)
CIndirectObject< T, P > & operator++()
CIndirectObject< T, P > & operator<<=(int shift)
T operator+(const CIndirectObject< T, P > &x) const
CIndirectObject< T, P > & operator+=(const CIndirectObject< T, P > &x)
CIndirectObject< T, P > & operator^=(const CIndirectObject< T, P > &x)
CIndirectObject< T, P > & operator=(const CIndirectObject< T, P > &x)
T operator/(const CIndirectObject< T, P > &x) const
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
CIndirectObject< T, P > & operator&=(const CIndirectObject< T, P > &x)
static void set_array(P a)
T operator-(const CIndirectObject< T, P > &x) const
T operator*(const CIndirectObject< T, P > &x) const
CIndirectObject< T, P > & operator>>=(int shift)
const T operator&(const CIndirectObject< T, P > &x) const
CIndirectObject< T, P > & operator-=(const CIndirectObject< T, P > &x)

SHOGUN Machine Learning Toolbox - Documentation