IndirectObject.h

Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 2009 Soeren Sonnenburg
00008  * Copyright (C) 2009 Fraunhofer Institute FIRST and Max Planck Society
00009  */
00010 #ifndef __INDIRECTOBJECT_H__
00011 #define __INDIRECTOBJECT_H__
00012 
00013 #include <shogun/lib/common.h>
00014 
00021 template <class T, class P> class CIndirectObject
00022 {
00023     public:
00027         CIndirectObject() : index(-1)
00028         {
00029         }
00030 
00034         CIndirectObject(int32_t idx)
00035         {
00036             index=idx;
00037         }
00038 
00043         static void set_array(P a)
00044         {
00045             array=a;
00046         }
00047 
00052         static P get_array()
00053         {
00054             return array;
00055         }
00056 
00061         static void init_slice(CIndirectObject<T,P>* a, int32_t len, int32_t start=0, int32_t stop=-1)
00062         {
00063             if (stop==-1)
00064                 stop=len;
00065 
00066             for (int32_t i=start; i<stop && i<len; i++)
00067                 a[i].index=i;
00068         }
00069 
00073         CIndirectObject<T,P>& operator=(const CIndirectObject<T,P>& x)
00074         { 
00075             index=x.index;
00076             return *this; 
00077         }
00078 
00083         T operator|(const CIndirectObject<T,P>& x) const
00084         {
00085             return (*array)[index] | *(x.array)[x.index];
00086         }
00087 
00092         const T operator&(const CIndirectObject<T,P>& x) const
00093         {
00094             return (*array)[index] & *(x.array)[x.index];
00095         }
00096 
00103         T operator<<(int shift)
00104         {
00105             return (*array)[index] << shift;
00106         }
00107 
00114         T operator>>(int shift)
00115         {
00116             return (*array)[index] >> shift;
00117         }
00118 
00123         T operator^(const CIndirectObject<T,P>& x) const
00124         {
00125             return (*array)[index] ^ *(x.array)[x.index];
00126         }
00127 
00132         T operator+(const CIndirectObject<T,P> &x) const
00133         {
00134             return (*array)[index] + *(x.array)[x.index];
00135         }
00136 
00141         T operator-(const CIndirectObject<T,P> &x) const
00142         {
00143             return (*array)[index] - *(x.array)[x.index];
00144         }
00145 
00150         T operator/(const CIndirectObject<T,P> &x) const
00151         {
00152             return (*array)[index] / *(x.array)[x.index];
00153         }
00154 
00159         T operator*(const CIndirectObject<T,P> &x) const
00160         {
00161             return (*array)[index] * *(x.array)[x.index];
00162         }
00163 
00168         CIndirectObject<T,P>& operator+=(const CIndirectObject<T,P> &x)
00169         {
00170             (*array)[index]+=*(x.array)[x.index];
00171             return *this;
00172         }
00173 
00178         CIndirectObject<T,P>& operator-=(const CIndirectObject<T,P> &x)
00179         {
00180             (*array)[index]-=*(x.array)[x.index];
00181             return *this;
00182         }
00183 
00188         CIndirectObject<T,P>& operator*=(const CIndirectObject<T,P> &x)
00189         {
00190             (*array)[index]*=*(x.array)[x.index];
00191             return *this;
00192         }
00193 
00198         CIndirectObject<T,P>& operator/=(const CIndirectObject<T,P> &x)
00199         {
00200             (*array)[index]/=*(x.array)[x.index];
00201             return *this;
00202         }
00203 
00208         bool operator==(const CIndirectObject<T,P> &x) const
00209         {
00210             return (*array)[index]==*(x.array)[x.index];
00211         }
00212 
00217         bool operator>=(const CIndirectObject<T,P> &x) const
00218         {
00219             return (*array)[index]>=*(x.array)[x.index];
00220         }
00221 
00226         bool operator<=(const CIndirectObject<T,P> &x) const
00227         {
00228             return (*array)[index]<=*(x.array)[x.index];
00229         }
00230 
00235         bool operator>(const CIndirectObject<T,P> &x) const
00236         {
00237             return (*array)[index]>(*(x.array))[x.index];
00238         }
00239 
00244         bool operator<(const CIndirectObject<T,P> &x) const
00245         {
00246             return (*array)[index]<(*(x.array))[x.index];
00247         }
00248 
00253         bool operator!=(const CIndirectObject<T,P> &x) const
00254         {
00255             return (*array)[index]!=(*(x.array))[x.index];
00256         }
00257 
00264         CIndirectObject<T,P>& operator|=(const CIndirectObject<T,P>& x)
00265         {
00266             (*array)[index]|=(*(x.array))[x.index];
00267             return *this;
00268         }
00269 
00276         CIndirectObject<T,P>& operator&=(const CIndirectObject<T,P>& x)
00277         {
00278             (*array)[index]&=(*(x.array))[x.index];
00279             return *this;
00280         }
00281 
00288         CIndirectObject<T,P>& operator^=(const CIndirectObject<T,P>& x)
00289         {
00290             (*array)[index]^=(*(x.array))[x.index];
00291             return *this;
00292         }
00293 
00300         CIndirectObject<T,P>& operator<<=(int shift)
00301         {
00302             *this=*this<<shift;
00303             return *this;
00304         }
00305 
00312         CIndirectObject<T,P>& operator>>=(int shift)
00313         {
00314             *this=*this>>shift;
00315             return *this;
00316         }
00317 
00319         T operator~()
00320         {
00321             return ~(*array)[index];
00322         }
00323 
00325         operator T() const { return (*array)[index]; }
00326 
00328         CIndirectObject<T,P>& operator--()
00329         {
00330             (*array)[index]--;
00331             return *this;
00332         }
00333 
00335         CIndirectObject<T,P>& operator++()
00336         {
00337             (*array)[index]++;
00338             return *this;
00339         }
00340 
00341     protected:
00343         static P array;
00344 
00346         int32_t index;
00347 };
00348 
00349 template <class T, class P> P CIndirectObject<T,P>::array;
00350 
00351 #endif //__INDIRECTOBJECT_H__

SHOGUN Machine Learning Toolbox - Documentation