00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef _OPFUNCBASE_H
00011 #define _OPFUNCBASE_H
00012
00013 #include "SrcFinfo.h"
00014
00015 extern const unsigned char MooseSendHop;
00016 extern const unsigned char MooseSetHop;
00017 extern const unsigned char MooseSetVecHop;
00018 extern const unsigned char MooseGetHop;
00019 extern const unsigned char MooseGetVecHop;
00020 extern const unsigned char MooseReturnHop;
00021 extern const unsigned char MooseTestHop;
00022
00023 class HopIndex
00024 {
00025 public:
00026 HopIndex( unsigned short bindIndex,
00027 unsigned char hopType = MooseSendHop)
00028 : bindIndex_( bindIndex ),
00029 hopType_( hopType )
00030 {;}
00031
00032 unsigned short bindIndex() const {
00033 return bindIndex_;
00034 }
00035
00036 unsigned char hopType() const {
00037 return hopType_;
00038 }
00039 private:
00040 unsigned short bindIndex_;
00041 unsigned char hopType_;
00042 };
00043
00044 class OpFunc
00045 {
00046 public:
00047 OpFunc();
00048
00049 virtual ~OpFunc()
00050 {;}
00051 virtual bool checkFinfo( const Finfo* s) const = 0;
00052
00053 virtual string rttiType() const = 0;
00054
00055 virtual const OpFunc* makeHopFunc( HopIndex hopIndex) const =0;
00056
00058 virtual void opBuffer( const Eref& e, double* buf ) const = 0;
00059
00061 virtual void opVecBuffer( const Eref& e, double* buf ) const
00062 {;}
00063
00064 static const OpFunc* lookop( unsigned int opIndex );
00065
00066 unsigned int opIndex() const {
00067 return opIndex_;
00068 }
00069
00071 bool setIndex( unsigned int i );
00073 static unsigned int rebuildOpIndex();
00074 private:
00075 unsigned int opIndex_;
00076 static vector< OpFunc* >& ops();
00077 };
00078
00079 class OpFunc0Base: public OpFunc
00080 {
00081 public:
00082 bool checkFinfo( const Finfo* s ) const {
00083 return dynamic_cast< const SrcFinfo0* >( s );
00084 }
00085
00086 virtual void op( const Eref& e ) const = 0;
00087
00088 const OpFunc* makeHopFunc( HopIndex hopIndex) const;
00089
00090 void opBuffer( const Eref& e, double* buf ) const;
00091
00092 string rttiType() const {
00093 return "void";
00094 }
00095 };
00096
00097 template< class A > class OpFunc1Base: public OpFunc
00098 {
00099 public:
00100
00101 bool checkFinfo( const Finfo* s ) const {
00102 return dynamic_cast< const SrcFinfo1< A >* >( s );
00103 }
00104
00105 virtual void op( const Eref& e, A arg ) const = 0;
00106
00107 const OpFunc* makeHopFunc( HopIndex hopIndex) const;
00108
00109 void opBuffer( const Eref& e, double* buf ) const {
00110 op( e, Conv< A >::buf2val( &buf ) );
00111 }
00112
00113 void opVecBuffer( const Eref& e, double* buf ) const {
00114 vector< A > temp = Conv< vector< A > >::buf2val( &buf );
00115 Element* elm = e.element();
00116 if ( elm->hasFields() ) {
00117 unsigned int di = e.dataIndex();
00118 unsigned int nf = elm->numField( di -
00119 elm->localDataStart() );
00120 for ( unsigned int i = 0; i < nf; ++i) {
00121 Eref er( elm, di, i );
00122 op( er, temp[ i % temp.size() ] );
00123 }
00124 } else {
00125 unsigned int k = 0;
00126 unsigned int start = elm->localDataStart();
00127 unsigned int end = start + elm->numLocalData();
00128 for ( unsigned int i = start; i < end; ++i) {
00129 Eref er( elm, i, 0 );
00130 op( er, temp[ k % temp.size() ] );
00131 ++k;
00132 }
00133 }
00134 }
00135
00136 virtual void opVec( const Eref& e, const vector< A >& arg,
00137 const OpFunc1Base< A >* op ) const
00138 { ; }
00139
00140 string rttiType() const {
00141 return Conv< A >::rttiType();
00142 }
00143 };
00144
00145 template< class A1, class A2 > class OpFunc2Base: public OpFunc
00146 {
00147 public:
00148 bool checkFinfo( const Finfo* s ) const {
00149 return dynamic_cast< const SrcFinfo2< A1, A2 >* >( s );
00150 }
00151
00152 virtual void op( const Eref& e, A1 arg1, A2 arg2 )
00153 const = 0;
00154
00155 const OpFunc* makeHopFunc( HopIndex hopIndex) const;
00156
00157 void opBuffer( const Eref& e, double* buf ) const {
00158 const A1& arg1 = Conv< A1 >::buf2val( &buf );
00159 op( e,
00160 arg1, Conv< A2 >::buf2val( &buf ) );
00161 }
00162
00163 void opVecBuffer( const Eref& e, double* buf ) const {
00164 vector< A1 > temp1 = Conv< vector< A1 > >::buf2val( &buf );
00165 vector< A2 > temp2 = Conv< vector< A2 > >::buf2val( &buf );
00166 Element* elm = e.element();
00167 assert( temp1.size() >= elm->numLocalData() );
00168 unsigned int k = 0;
00169 unsigned int start = elm->localDataStart();
00170 unsigned int end = start + elm->numLocalData();
00171 for ( unsigned int i = start; i < end; ++i) {
00172 unsigned int nf = elm->numField( i - start );
00173 for ( unsigned int j = 0; j < nf; ++j) {
00174 Eref er( elm, i, j );
00175 op( er, temp1[ k % temp1.size() ],
00176 temp2[ k % temp2.size() ] );
00177 ++k;
00178 }
00179 }
00180 }
00181
00182 virtual void opVec( const Eref& e,
00183 const vector< A1 >& arg1,
00184 const vector< A2 >& arg2,
00185 const OpFunc2Base< A1, A2 >* op ) const
00186 { ; }
00187
00188 string rttiType() const {
00189 return Conv< A1 >::rttiType() + "," + Conv< A2 >::rttiType();
00190 }
00191 };
00192
00193 template< class A1, class A2, class A3 > class OpFunc3Base:
00194 public OpFunc
00195 {
00196 public:
00197 bool checkFinfo( const Finfo* s ) const {
00198 return dynamic_cast< const SrcFinfo3< A1, A2, A3 >* >( s );
00199 }
00200
00201 virtual void op( const Eref& e, A1 arg1, A2 arg2, A3 arg3 )
00202 const = 0;
00203
00204 const OpFunc* makeHopFunc( HopIndex hopIndex) const;
00205
00206 void opBuffer( const Eref& e, double* buf ) const {
00207 const A1& arg1 = Conv< A1 >::buf2val( &buf );
00208 const A2& arg2 = Conv< A2 >::buf2val( &buf );
00209 op( e,
00210 arg1, arg2, Conv< A3 >::buf2val( &buf ) );
00211 }
00212
00213 string rttiType() const {
00214 return Conv< A1 >::rttiType() + "," + Conv< A2 >::rttiType() +
00215 "," + Conv< A3 >::rttiType();
00216 }
00217 };
00218
00219 template< class A1, class A2, class A3, class A4 >
00220 class OpFunc4Base: public OpFunc
00221 {
00222 public:
00223 bool checkFinfo( const Finfo* s ) const {
00224 return dynamic_cast< const SrcFinfo4< A1, A2, A3, A4 >* >( s );
00225 }
00226
00227 virtual void op( const Eref& e,
00228 A1 arg1, A2 arg2, A3 arg3, A4 arg4 ) const = 0;
00229
00230 const OpFunc* makeHopFunc( HopIndex hopIndex) const;
00231
00232 void opBuffer( const Eref& e, double* buf ) const {
00233 const A1& arg1 = Conv< A1 >::buf2val( &buf );
00234 const A2& arg2 = Conv< A2 >::buf2val( &buf );
00235 const A3& arg3 = Conv< A3 >::buf2val( &buf );
00236 op( e,
00237 arg1, arg2, arg3, Conv< A4 >::buf2val( &buf ) );
00238 }
00239
00240 string rttiType() const {
00241 return Conv< A1 >::rttiType() + "," + Conv< A2 >::rttiType() +
00242 "," + Conv<A3>::rttiType() + "," + Conv<A4>::rttiType();
00243 }
00244 };
00245
00246 template< class A1, class A2, class A3, class A4, class A5 >
00247 class OpFunc5Base: public OpFunc
00248 {
00249 public:
00250 bool checkFinfo( const Finfo* s ) const {
00251 return dynamic_cast< const SrcFinfo5< A1, A2, A3, A4, A5 >* >( s );
00252 }
00253
00254 virtual void op( const Eref& e,
00255 A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5 ) const = 0;
00256
00257 const OpFunc* makeHopFunc( HopIndex hopIndex) const;
00258
00259 void opBuffer( const Eref& e, double* buf ) const {
00260 const A1& arg1 = Conv< A1 >::buf2val( &buf );
00261 const A2& arg2 = Conv< A2 >::buf2val( &buf );
00262 const A3& arg3 = Conv< A3 >::buf2val( &buf );
00263 const A4& arg4 = Conv< A4 >::buf2val( &buf );
00264 op( e,
00265 arg1, arg2, arg3, arg4, Conv< A5 >::buf2val( &buf ) );
00266 }
00267
00268 string rttiType() const {
00269 return Conv< A1 >::rttiType() + "," + Conv< A2 >::rttiType() +
00270 "," + Conv<A3>::rttiType() + "," + Conv<A4>::rttiType() +
00271 "," + Conv<A5>::rttiType();
00272 }
00273 };
00274
00275 template< class A1, class A2, class A3, class A4, class A5, class A6 >
00276 class OpFunc6Base: public OpFunc
00277 {
00278 public:
00279 bool checkFinfo( const Finfo* s ) const {
00280 return dynamic_cast< const SrcFinfo6< A1, A2, A3, A4, A5, A6 >* >( s );
00281 }
00282
00283 virtual void op( const Eref& e, A1 arg1, A2 arg2, A3 arg3, A4 arg4,
00284 A5 arg5, A6 arg6 ) const = 0;
00285
00286 const OpFunc* makeHopFunc( HopIndex hopIndex) const;
00287
00288 void opBuffer( const Eref& e, double* buf ) const {
00289 const A1& arg1 = Conv< A1 >::buf2val( &buf );
00290 const A2& arg2 = Conv< A2 >::buf2val( &buf );
00291 const A3& arg3 = Conv< A3 >::buf2val( &buf );
00292 const A4& arg4 = Conv< A4 >::buf2val( &buf );
00293 const A5& arg5 = Conv< A5 >::buf2val( &buf );
00294 op( e,
00295 arg1, arg2, arg3, arg4, arg5, Conv< A6 >::buf2val( &buf ) );
00296 }
00297
00298 string rttiType() const {
00299 return Conv< A1 >::rttiType() + "," + Conv< A2 >::rttiType() +
00300 "," + Conv<A3>::rttiType() + "," + Conv<A4>::rttiType() +
00301 "," + Conv<A5>::rttiType() + "," + Conv<A6>::rttiType();
00302 }
00303 };
00304
00308 template< class A > class GetOpFuncBase: public OpFunc1Base< vector< A >* >
00309 {
00310 public:
00311
00312
00313
00314
00315
00316
00317
00318 virtual A returnOp( const Eref& e ) const = 0;
00319
00320
00321 const OpFunc* makeHopFunc( HopIndex hopIndex) const;
00322
00323
00324
00325
00326 void opBuffer( const Eref& e, double* buf ) const {
00327 A ret = returnOp( e );
00328 buf[0] = Conv<A>::size( ret );
00329 buf++;
00330 Conv< A >::val2buf( ret, &buf );
00331 }
00332
00333
00334
00335
00336
00337
00338 };
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00362 template< class L, class A > class LookupGetOpFuncBase: public OpFunc
00363 {
00364 public:
00365 bool checkFinfo( const Finfo* s ) const {
00366 return ( dynamic_cast< const SrcFinfo1< A >* >( s )
00367 || dynamic_cast< const SrcFinfo2< FuncId, L >* >( s ) );
00368 }
00369
00370 virtual void op( const Eref& e, L index,
00371 ObjId recipient, FuncId fid ) const = 0;
00372
00373 virtual A returnOp( const Eref& e, const L& index ) const = 0;
00374
00375 const OpFunc* makeHopFunc( HopIndex hopIndex) const
00376 {
00377
00378 return 0;
00379 }
00380
00381 const OpFunc* makeHopFunc( HopIndex hopIndex, const L& index ) const
00382 {
00383
00384
00385 return 0;
00386 }
00387
00388 void opBuffer( const Eref& e, double* buf ) const {
00389
00390 }
00391
00392 string rttiType() const {
00393 return Conv< A >::rttiType();
00394 }
00395 };
00396
00397 #endif // _OPFUNCBASE_H