Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef __INDIRECTOBJECT_H__
00011 #define __INDIRECTOBJECT_H__
00012
00013 #include <shogun/lib/common.h>
00014
00015 namespace shogun
00016 {
00023 template <class T, class P> class CIndirectObject
00024 {
00025 public:
00029 CIndirectObject() : index(-1)
00030 {
00031 }
00032
00036 CIndirectObject(int32_t idx)
00037 {
00038 index=idx;
00039 }
00040
00045 static void set_array(P a)
00046 {
00047 array=a;
00048 }
00049
00054 static P get_array()
00055 {
00056 return array;
00057 }
00058
00063 static void init_slice(CIndirectObject<T,P>* a, int32_t len, int32_t start=0, int32_t stop=-1)
00064 {
00065 if (stop==-1)
00066 stop=len;
00067
00068 for (int32_t i=start; i<stop && i<len; i++)
00069 a[i].index=i;
00070 }
00071
00075 CIndirectObject<T,P>& operator=(const CIndirectObject<T,P>& x)
00076 {
00077 index=x.index;
00078 return *this;
00079 }
00080
00085 T operator|(const CIndirectObject<T,P>& x) const
00086 {
00087 return (*array)[index] | *(x.array)[x.index];
00088 }
00089
00094 const T operator&(const CIndirectObject<T,P>& x) const
00095 {
00096 return (*array)[index] & *(x.array)[x.index];
00097 }
00098
00105 T operator<<(int shift)
00106 {
00107 return (*array)[index] << shift;
00108 }
00109
00116 T operator>>(int shift)
00117 {
00118 return (*array)[index] >> shift;
00119 }
00120
00125 T operator^(const CIndirectObject<T,P>& x) const
00126 {
00127 return (*array)[index] ^ *(x.array)[x.index];
00128 }
00129
00134 T operator+(const CIndirectObject<T,P> &x) const
00135 {
00136 return (*array)[index] + *(x.array)[x.index];
00137 }
00138
00143 T operator-(const CIndirectObject<T,P> &x) const
00144 {
00145 return (*array)[index] - *(x.array)[x.index];
00146 }
00147
00152 T operator/(const CIndirectObject<T,P> &x) const
00153 {
00154 return (*array)[index] / *(x.array)[x.index];
00155 }
00156
00161 T operator*(const CIndirectObject<T,P> &x) const
00162 {
00163 return (*array)[index] * *(x.array)[x.index];
00164 }
00165
00170 CIndirectObject<T,P>& operator+=(const CIndirectObject<T,P> &x)
00171 {
00172 (*array)[index]+=*(x.array)[x.index];
00173 return *this;
00174 }
00175
00180 CIndirectObject<T,P>& operator-=(const CIndirectObject<T,P> &x)
00181 {
00182 (*array)[index]-=*(x.array)[x.index];
00183 return *this;
00184 }
00185
00190 CIndirectObject<T,P>& operator*=(const CIndirectObject<T,P> &x)
00191 {
00192 (*array)[index]*=*(x.array)[x.index];
00193 return *this;
00194 }
00195
00200 CIndirectObject<T,P>& operator/=(const CIndirectObject<T,P> &x)
00201 {
00202 (*array)[index]/=*(x.array)[x.index];
00203 return *this;
00204 }
00205
00210 bool operator==(const CIndirectObject<T,P> &x) const
00211 {
00212 return (*array)[index]==*(x.array)[x.index];
00213 }
00214
00219 bool operator>=(const CIndirectObject<T,P> &x) const
00220 {
00221 return (*array)[index]>=*(x.array)[x.index];
00222 }
00223
00228 bool operator<=(const CIndirectObject<T,P> &x) const
00229 {
00230 return (*array)[index]<=*(x.array)[x.index];
00231 }
00232
00237 bool operator>(const CIndirectObject<T,P> &x) const
00238 {
00239 return (*array)[index]>(*(x.array))[x.index];
00240 }
00241
00246 bool operator<(const CIndirectObject<T,P> &x) const
00247 {
00248 return (*array)[index]<(*(x.array))[x.index];
00249 }
00250
00255 bool operator!=(const CIndirectObject<T,P> &x) const
00256 {
00257 return (*array)[index]!=(*(x.array))[x.index];
00258 }
00259
00266 CIndirectObject<T,P>& operator|=(const CIndirectObject<T,P>& x)
00267 {
00268 (*array)[index]|=(*(x.array))[x.index];
00269 return *this;
00270 }
00271
00278 CIndirectObject<T,P>& operator&=(const CIndirectObject<T,P>& x)
00279 {
00280 (*array)[index]&=(*(x.array))[x.index];
00281 return *this;
00282 }
00283
00290 CIndirectObject<T,P>& operator^=(const CIndirectObject<T,P>& x)
00291 {
00292 (*array)[index]^=(*(x.array))[x.index];
00293 return *this;
00294 }
00295
00302 CIndirectObject<T,P>& operator<<=(int shift)
00303 {
00304 *this=*this<<shift;
00305 return *this;
00306 }
00307
00314 CIndirectObject<T,P>& operator>>=(int shift)
00315 {
00316 *this=*this>>shift;
00317 return *this;
00318 }
00319
00321 T operator~()
00322 {
00323 return ~(*array)[index];
00324 }
00325
00327 operator T() const { return (*array)[index]; }
00328
00330 CIndirectObject<T,P>& operator--()
00331 {
00332 (*array)[index]--;
00333 return *this;
00334 }
00335
00337 CIndirectObject<T,P>& operator++()
00338 {
00339 (*array)[index]++;
00340 return *this;
00341 }
00342
00343 protected:
00345 static P array;
00346
00348 int32_t index;
00349 };
00350
00351 template <class T, class P> P CIndirectObject<T,P>::array;
00352 }
00353 #endif //__INDIRECTOBJECT_H__