1 #ifndef __OV_ArraySimple_H__
2 #define __OV_ArraySimple_H__
4 #define WAS_NOT_DETEMPLIFIED
11 #ifndef WAS_DETEMPLIFIED
23 #ifdef TEST_AS_REFCOUNTING
24 cout<<
"building referenced object at "<<long(
this)<<endl;
32 #ifdef TEST_AS_REFCOUNTING
33 cout<<
"copy constructor called for object at "<<long(
this)<<endl;
41 #ifdef TEST_AS_REFCOUNTING
42 cout<<
"destructor called for object at "<<long(
this)<<endl;
43 cout<<
" ncreated = "<<ncreated<<
" ndeleted = "<<ndeleted<<endl;
51 #ifdef TEST_AS_REFCOUNTING
52 cout<<
"operator= called for object at "<<long(
this)<<endl;
85 #ifdef TEST_AS_REFCOUNTING
87 cout<<
"decrementing object at "<<long(
this)<<
" to "<<*r-1<<
" counts"<<endl;
89 cout<<
"decrement called on non-counted object at "<<long(
this)<<endl;
96 #ifdef TEST_AS_REFCOUNTING
114 #ifdef TEST_AS_REFCOUNTING
119 #ifdef TEST_AS_REFCOUNTING
120 cout<<
"incrementing object at "<<long(
this)<<
" to "<<*r<<
" counts"<<endl;
127 #ifdef TEST_AS_REFCOUNTING
129 static int ncreated, ndeleted;
174 for (
int i=0; i<
size(); i++ ) data[i] = a.data[i];
179 #ifndef WAS_DETEMPLIFIED
180 #ifndef OV_NO_DEFAULT_TEMPL_ARGS
182 template<
int d1,
int d2,
int d3,
int d4,
int d5>
192 if ( n[1]==1 && n[2]==1 && n[3]==1 && n[4]==1 ) nrank = 1;
193 else if ( n[2]==1 && n[3]==1 && n[4]==1 ) nrank = 2;
194 else if ( n[3]==1 && n[4]==1 ) nrank = 3;
195 else if ( n[4]==1 ) nrank = 4;
267 for (
int r=0;
r<nrank;
r++ )
270 return nrank==0 ? 0 :
s;
274 inline int size(
const int &r_ )
const
309 for (
int i=0; i<
s; i++ ) data[i] = a.data[i];
316 #ifdef TEST_AS_REFCOUNTING
317 cout<<
"instance at "<<long(
this)<<
" is referencing instance at "<<long(&a)<<endl;
371 for (
int i=0; i<
size(); i++ ) data[i] = a.data[i];
380 for (
int i=0; i<
size(); i++ ) data[i] = a;
422 return data[ i0 + i1*n[0] ];
425 inline const T &
operator() (
const int &i0,
const int &i1)
const
430 return data[ i0 + i1*n[0] ];
439 return data[ i0 + n[0]*(i1 + i2*n[1]) ];
449 return data[ i0 + n[0]*(i1 + i2*n[1]) ];
460 return data[ i0 + n[0]*(i1 + n[1]*(i2 + i3*n[2])) ];
471 return data[ i0 + n[0]*(i1 + n[1]*(i2 + i3*n[2])) ];
483 return data[ i0 + n[0]*(i1 + n[1]*(i2 + n[2]*(i3 + n[3]*i4))) ];
488 inline const T &
operator() (
int i0,
int i1,
int i2,
int i3,
int i4)
const
496 return data[ i0 + n[0]*(i1 + n[1]*(i2 + n[2]*(i3 + n[3]*i4))) ];
501 void resize(
int n1,
int n2=-1,
int n3=-1,
int n4=-1,
int n5=-1)
511 int tmp_size =
size();
519 while ( n[i]>0 && i<
MAXRANK ) i++;
522 for ( i=nrank; i<
MAXRANK; i++ ) n[i] = 1;
527 for (
int i=0; i<
min(tmp_size,
size()); i++ )
528 data[i] = tmp_data[i];
530 if ( oldRefs<2 && tmp_data )
533 #ifdef TEST_AS_REFCOUNTING
534 cout<<
"DELETING ARRAY DATA DURING RESIZE FOR INSTANCE "<<long(
this)<<endl;
536 cout<<
" nalloc = "<<nalloc<<
" ndel "<<ndel<<endl;
541 void redim(
int n1,
int n2=-1,
int n3=-1,
int n4=-1,
int n5=-1)
559 while ( n[i]>0 && i<
MAXRANK ) i++;
562 for ( i=nrank; i<
MAXRANK; i++ ) n[i] = 1;
569 #ifdef TEST_AS_REFCOUNTING
570 static int nalloc, ndel;
582 #ifdef TEST_AS_REFCOUNTING
585 cout<<
"ALLOCATING ARRAY DATA FOR INSTANCE "<<long(
this)<<endl;
587 cout<<
" nalloc = "<<nalloc<<
" ndel "<<ndel<<endl;
602 #ifdef TEST_AS_REFCOUNTING
605 cout<<
"DESTROYING ARRAY DATA FOR INSTANCE "<<long(
this)<<endl;
607 cout<<
" nalloc = "<<nalloc<<
" ndel "<<ndel<<endl;
611 if ( data!=0 )
delete [] data;
627 #ifndef WAS_DETEMPLIFIED
634 ostream & operator<< (ostream &os, ArraySimple<T> &sa)
638 int rank = sa.rank();
640 os<<
"********** ArraySimple( ";
642 for (
int r=0;
r<rank-1;
r++ )
643 os<<sa.size(
r)<<
", ";
649 os<<
" ) **********\n";
657 for (
int i=0; i<sa.size(); i++ )
658 os<<
"a( "<<i<<
" ) = "<<sa(i)<<endl;
663 for (
int i1=0; i1<sa.size(0); i1++ )
664 for (
int i2=0;
i2<sa.size(1);
i2++ )
665 os<<
"a( "<<i1<<
", "<<
i2<<
" ) = "<<sa(i1,
i2)<<endl;
670 for (
int i1=0; i1<sa.size(0); i1++ )
671 for (
int i2=0;
i2<sa.size(1);
i2++ )
672 for (
int i3=0; i3<sa.size(2); i3++ )
673 os<<
"a( "<<i1<<
", "<<
i2<<
", "<<i3<<
" ) = "<<sa(i1,
i2,i3)<<endl;
678 for (
int i1=0; i1<sa.size(0); i1++ )
679 for (
int i2=0;
i2<sa.size(1);
i2++ )
680 for (
int i3=0; i3<sa.size(2); i3++ )
681 for (
int i4=0; i4<sa.size(3); i4++ )
682 os<<
"a( "<<i1<<
", "<<
i2<<
", "<<i3<<
", "<<i4<<
" ) = "<<sa(i1,
i2,i3,i4)<<endl;
687 for (
int i1=0; i1<sa.size(0); i1++ )
688 for (
int i2=0;
i2<sa.size(1);
i2++ )
689 for (
int i3=0; i3<sa.size(2); i3++ )
690 for (
int i4=0; i4<sa.size(3); i4++ )
691 for (
int i5=0; i5<sa.size(4); i5++ )
692 os<<
"a( "<<i1<<
", "<<
i2<<
", "<<i3<<
", "<<i4<<
", "<<i5<<
" ) = "<<sa(i1,
i2,i3,i4,i5)<<endl;
697 os<<
"RANK "<<rank<<
" ARRAYS ARE NOT SUPPORTED"<<endl;