4#ifndef CONTAINER_CLASSES_H_
5#define CONTAINER_CLASSES_H_
7void do_dump_state(
const void* buf,
size_t nelem,
size_t size, FILE* out, int32 magic);
8void do_restore_state(
void* buf,
size_t nelem,
size_t size, FILE *in, int32 magic);
18static const int32
MA_VERS[
ML_TOP] = { 120070905, 220070803, 320071126 };
21#define MEM_LAYOUT_VAL C_TYPE
23#define MEM_LAYOUT_VAL ARPA_TYPE
27#define lgBOUNDSCHECKVAL true
29#define lgBOUNDSCHECKVAL false
34template<
class T,
bool lgBC>
37 static const int p_nd = lgBC ? 3 : 1;
45# pragma warning( disable : 4127 )
49 if( t <
p_p[1] || t >=
p_p[2] )
58# pragma warning( disable : 4127 )
139template<
class T,
bool lgBC>
160template<
class T,
bool lgBC>
169template<
class T,
bool lgBC>
207template<
class T,
bool lgBC>
280 return getvec(i-1,index).
d[index[i-1]];
287 return getvec(i-1,index).
d[index[i-1]];
293template<
int d,mem_layout ALLOC=MEM_LAYOUT_VAL>
314 for(
int i=0; i < d; ++i )
348 for(
int i=0; i < d; ++i )
360 return (
lgInbounds(n-1,index) && index[n-1] <
v.getvec(n-1,index).n );
375 s[n-1] =
max(
s[n-1],index[n-1]);
376 nsl[n-1] += index[n-1];
403# pragma warning( disable : 4127 )
411 for(
int dim=0; dim < d; ++dim )
412 n1[dim] = n2[dim] = 0L;
415 for(
int dim=0; dim < d-1; ++dim )
419 else if( ALLOC ==
C_TYPE )
422 for(
int i = d-2; i >= 0; --i )
423 st[i] =
st[i+1]*
s[i];
555template<
class T,
int N, mem_layout ALLOC,
bool lgBC>
class n_pointer;
558template<
class T,
int N>
573template<
class T,
int N>
618template<
class T,
int N>
635template<
class T,
int N>
686template<
class T,
int N>
701template<
class T,
int N>
746template<
class T,
int N>
763template<
class T,
int N>
940template<
class T,
int d, mem_layout ALLOC=MEM_LAYOUT_VAL,
bool lgBC=lgBOUNDSCHECKVAL>
972 for(
int i=0; i < d-1; ++i )
978 for(
int i=0; i < d-1; ++i )
1019 size_type index[] = { d1, d2, d3, d4, d5 };
1025 size_type index[] = { d1, d2, d3, d4, d5, d6 };
1055 memset(
data(), 0,
p_g.size*
sizeof(T) );
1084 p_g.reserve( 1, index );
1090 p_g.reserve( 2, index );
1095 const size_type index[] = { i1, i2, i3 };
1096 p_g.reserve( 3, index );
1101 const size_type index[] = { i1, i2, i3, i4 };
1102 p_g.reserve( 4, index );
1107 const size_type index[] = { i1, i2, i3, i4, i5 };
1108 p_g.reserve( 5, index );
1113 const size_type index[] = { i1, i2, i3, i4, i5, i6 };
1114 p_g.reserve( 6, index );
1121# pragma warning( disable : 4127 )
1129 for(
int dim=0; dim < d; ++dim )
1131 n1[dim] = n2[dim] = 0L;
1135 if(
p_g.nsl[dim] > 0 )
1136 p_psl[dim] =
new T*[
p_g.nsl[dim] ];
1148 else if( ALLOC ==
C_TYPE )
1150 for(
int i=0; i < d-1; ++i )
1194 size_type index[] = { d1, d2, d3, d4, d5 };
1199 size_type index[] = { d1, d2, d3, d4, d5, d6 };
1204 for(
int n=0; n < d; n++ )
1207 p_g.reserve_recursive( 0, index );
1240# pragma warning( disable : 4127 )
1253 if(
p_g.lgInbounds( 1, index ) )
1257 T* s = ( n > 0 ) ? &(*t)[i1][0] : NULL;
1270# pragma warning( disable : 4127 )
1277 return iterator( &(*t)[i1][i2][i3] );
1283 if(
p_g.lgInbounds( 2, index ) )
1287 T* s = ( n > 0 ) ? &(*t)[i1][i2][0] : NULL;
1300# pragma warning( disable : 4127 )
1307 return iterator( &(*t)[i1][i2][i3][i4] );
1313 if(
p_g.lgInbounds( 3, index ) )
1317 T* s = ( n > 0 ) ? &(*t)[i1][i2][i3][0] : NULL;
1330# pragma warning( disable : 4127 )
1337 return iterator( &(*t)[i1][i2][i3][i4][i5] );
1343 if(
p_g.lgInbounds( 4, index ) )
1347 T* s = ( n > 0 ) ? &(*t)[i1][i2][i3][i4][0] : NULL;
1360# pragma warning( disable : 4127 )
1367 return iterator( &(*t)[i1][i2][i3][i4][i5][i6] );
1372 size_type index[] = { i1, i2, i3, i4, i5 };
1373 if(
p_g.lgInbounds( 5, index ) )
1377 T* s = ( n > 0 ) ? &(*t)[i1][i2][i3][i4][i5][0] : NULL;
1410 if( !
p_g.lgInbounds( 2, index ) )
1412 return (*
this)[i1][i2];
1417 if( !
p_g.lgInbounds( 2, index ) )
1419 return (*
this)[i1][i2];
1424 if( !
p_g.lgInbounds( 3, index ) )
1426 return (*
this)[i1][i2][i3];
1431 if( !
p_g.lgInbounds( 3, index ) )
1433 return (*
this)[i1][i2][i3];
1438 if( !
p_g.lgInbounds( 4, index ) )
1440 return (*
this)[i1][i2][i3][i4];
1445 if( !
p_g.lgInbounds( 4, index ) )
1447 return (*
this)[i1][i2][i3][i4];
1451 size_type index[] = { i1, i2, i3, i4, i5 };
1452 if( !
p_g.lgInbounds( 5, index ) )
1454 return (*
this)[i1][i2][i3][i4][i5];
1458 size_type index[] = { i1, i2, i3, i4, i5 };
1459 if( !
p_g.lgInbounds( 5, index ) )
1461 return (*
this)[i1][i2][i3][i4][i5];
1465 size_type index[] = { i1, i2, i3, i4, i5, i6 };
1466 if( !
p_g.lgInbounds( 6, index ) )
1468 return (*
this)[i1][i2][i3][i4][i5][i6];
1472 size_type index[] = { i1, i2, i3, i4, i5, i6 };
1473 if( !
p_g.lgInbounds( 6, index ) )
1475 return (*
this)[i1][i2][i3][i4][i5][i6];
1564# pragma warning( disable : 4127 )
1575# pragma warning( disable : 4127 )
1586# pragma warning( disable : 4127 )
1597# pragma warning( disable : 4127 )
1608# pragma warning( disable : 4127 )
1619# pragma warning( disable : 4127 )
1630# pragma warning( disable : 4127 )
1635 return p_iterator(i1, i2, i3, i4,
p_g.v.d[i1].d[i2].d[i3].d[i4].n);
1641# pragma warning( disable : 4127 )
1646 return p_iterator(i1, i2, i3, i4,
p_g.v.d[i1].d[i2].d[i3].d[i4].n);
1652# pragma warning( disable : 4127 )
1657 return p_iterator(i1, i2, i3, i4, i5,
p_g.v.d[i1].d[i2].d[i3].d[i4].d[i5].n);
1663# pragma warning( disable : 4127 )
1668 return p_iterator(i1, i2, i3, i4, i5,
p_g.v.d[i1].d[i2].d[i3].d[i4].d[i5].n);
1681 return *
begin(i1, i2);
1685 return *
begin(i1, i2);
1689 return *
begin(i1, i2, i3);
1693 return *
begin(i1, i2, i3);
1697 return *
begin(i1, i2, i3, i4);
1701 return *
begin(i1, i2, i3, i4);
1705 return *
begin(i1, i2, i3, i4, i5);
1709 return *
begin(i1, i2, i3, i4, i5);
1714 return *(
end(i1) - 1);
1718 return *(
end(i1) - 1);
1722 return *(
end(i1, i2) - 1);
1726 return *(
end(i1, i2) - 1);
1730 return *(
end(i1, i2, i3) - 1);
1734 return *(
end(i1, i2, i3) - 1);
1738 return *(
end(i1, i2, i3, i4) - 1);
1742 return *(
end(i1, i2, i3, i4) - 1);
1746 return *(
end(i1, i2, i3, i4, i5) - 1);
1750 return *(
end(i1, i2, i3, i4, i5) - 1);
1763 for(
int i=0; i < d-1; ++i )
1764 if(
p_psl[i] != NULL )
1766 return (
p_g.size == 0UL &&
p_dsl.size() == 0 );
1845#define INSTANTIATE_MULTI_ARR( TYPE, BC ) \
1846template class pntr<TYPE,BC>; \
1847template class const_pntr<TYPE,BC>;
1849template<
class T,
bool lgBC=lgBOUNDSCHECKVAL>
1967# pragma warning( disable : 4127 )
2006 T* nptr = nptr_alloc -
p_begin;
2035# pragma warning( disable : 4127 )
2052# pragma warning( disable : 4127 )
2142 return (
size() == 0 );
NORETURN void OUT_OF_RANGE(const char *str)
NORETURN void TotalInsanity(void)
void invalidate_array(T *p, size_t size)
bool operator<(const basic_pntr &t) const
basic_pntr & operator-=(const ptrdiff_t n)
bool operator<=(const basic_pntr &t) const
void p_set_vals(T *p0, T *p1, T *p2)
bool operator!=(const basic_pntr &t) const
basic_pntr(T *p0, T *p1, T *p2)
bool operator>(const basic_pntr &t) const
random_access_iterator_tag iterator_category
basic_pntr & operator++()
bool operator>=(const basic_pntr &t) const
bool operator==(const basic_pntr &t) const
const T & const_reference
T & operator[](const ptrdiff_t n) const
T * p_index_checked(const ptrdiff_t n) const
basic_pntr(const basic_pntr &t)
basic_pntr & operator+=(const ptrdiff_t n)
basic_pntr & operator--()
ptrdiff_t difference_type
const_n_pointer(const T *p, const size_t *st=NULL, const tree_vec *v=NULL)
const_n_pointer(const T *p, const size_t *st, const tree_vec *v)
const_n_pointer(const T *p, const size_t *st, const tree_vec *v=NULL)
const_n_pointer(const T *p, const size_t *st, const tree_vec *v)
const_n_pointer(const T *p, const size_t *st=NULL, const tree_vec *v=NULL)
const_n_pointer< T, N-1, ARPA_TYPE, false > value_type
const_n_pointer(const T *p, const size_t *st, const tree_vec *v)
const_n_pointer< T, N-1, ARPA_TYPE, true > value_type
const_n_pointer< T, N-1, C_TYPE, false > value_type
const_n_pointer(const T *p, const size_t *st, const tree_vec *v=NULL)
const_n_pointer< T, N-1, C_TYPE, true > value_type
const_n_pointer(const T *p, const size_t *st, const tree_vec *v)
const_pntr - same as pntr, except that it replaces const pointers rather than normal pointers
const T * operator->() const
const T & operator[](const ptrdiff_t n) const
const_pntr & operator++()
const T & operator*() const
const_pntr(const pntr< T, lgBC > &t)
const_pntr & operator+=(const ptrdiff_t n)
const_pntr & operator-=(const ptrdiff_t n)
const const_pntr operator-(const ptrdiff_t n) const
const_pntr(T *p0, T *p1, T *p2)
const const_pntr operator+(const ptrdiff_t n) const
const_pntr & operator--()
void reserve(size_type size)
reference at(size_type i)
flex_arr(const flex_arr &f)
void restore_state(FILE *in)
const T & const_reference
void realloc(size_type end)
iterator p_iterator(size_type i) const
random_access_iterator_tag iterator_category
const flex_arr & operator=(const flex_arr &f)
reference operator[](size_type i)
ptrdiff_t difference_type
size_type capacity() const
const_pointer data() const
const_iterator end() const
const_reference at(size_type i) const
bool p_lgInbounds(size_type i) const
pointer p_pointer(size_type i) const
const_pntr< T, lgBC > const_iterator
void state_do(FILE *out, bool lgGet)
iterator ptr(size_type i)
const_iterator ptr(size_type i) const
void alloc(size_type begin, size_type end)
const_iterator begin() const
const_reference front() const
flex_arr(size_type begin, size_type end)
void dump_state(FILE *out) const
const_reference back() const
reference p_index(size_type i) const
const_iterator begin(size_type i1) const
void alloc(size_type d1, size_type d2, size_type d3, size_type d4)
const valarray< T > & vals() const
const_iterator ptr(size_type i1, size_type i2) const
void restore_state(FILE *in)
iterator p_iterator_bc(size_type i1, size_type i2, size_type i3, size_type i4, size_type i5, size_type i6) const
const_iterator begin(size_type i1, size_type i2, size_type i3, size_type i4) const
const_reference at(size_type i1, size_type i2, size_type i3, size_type i4) const
iterator begin(size_type i1, size_type i2, size_type i3)
iterator ptr(size_type i1, size_type i2, size_type i3)
const_iterator begin(size_type i1, size_type i2, size_type i3, size_type i4, size_type i5) const
const_reference back(size_type i1, size_type i2, size_type i3, size_type i4, size_type i5) const
iterator p_iterator_bc(size_type i1, size_type i2, size_type i3) const
void reserve(size_type i1, size_type i2, size_type i3, size_type i4, size_type i5)
iterator ptr(size_type i1, size_type i2)
void state_do(FILE *io, bool lgGet)
const_reference front(size_type i1, size_type i2, size_type i3, size_type i4, size_type i5) const
iterator end(size_type i1, size_type i2, size_type i3)
reference front(size_type i1, size_type i2)
const_reference at(size_type i1, size_type i2, size_type i3) const
const_pntr< T, lgBC > const_iterator
const_reference at(size_type i1, size_type i2, size_type i3, size_type i4, size_type i5) const
reference back(size_type i1, size_type i2, size_type i3, size_type i4, size_type i5)
reference front(size_type i1, size_type i2, size_type i3, size_type i4, size_type i5)
const_iterator end(size_type i1, size_type i2, size_type i3) const
static const size_type npos
iterator p_iterator(size_type i1, size_type i2, size_type i3) const
reference back(size_type i1, size_type i2)
multi_arr(size_type d1, size_type d2, size_type d3, size_type d4)
reference back(size_type i1)
iterator p_iterator_bc(size_type i1, size_type i2, size_type i3, size_type i4, size_type i5) const
random_access_iterator_tag iterator_category
const n_pointer< T, d, ALLOC, lgBC > n_ptr()
const_reference back(size_type i1, size_type i2) const
void alloc(size_type d1, size_type d2)
multi_arr(size_type d1, size_type d2, size_type d3, size_type d4, size_type d5, size_type d6)
const_reference at(size_type i1, size_type i2) const
iterator ptr(size_type i1, size_type i2, size_type i3, size_type i4, size_type i5, size_type i6)
const_reference back(size_type i1, size_type i2, size_type i3, size_type i4) const
void alloc(const multi_geom< d, ALLOC > &g)
const_reference front(size_type i1, size_type i2, size_type i3, size_type i4) const
iterator begin(size_type i1, size_type i2, size_type i3, size_type i4, size_type i5)
iterator end(size_type i1, size_type i2)
const_iterator ptr(size_type i1, size_type i2, size_type i3) const
reference at(size_type i1, size_type i2, size_type i3)
iterator p_iterator(size_type i1, size_type i2, size_type i3, size_type i4, size_type i5) const
multi_geom< d, MEM_LAYOUT_VAL > p_g
iterator p_iterator(size_type i1, size_type i2, size_type i3, size_type i4) const
void dump_state(FILE *out) const
reference at(size_type i1, size_type i2, size_type i3, size_type i4, size_type i5, size_type i6)
reference at(size_type i1, size_type i2, size_type i3, size_type i4)
const_n_pointer< T, d-1, ALLOC, lgBC > const_indexed_type
const_iterator begin(size_type i1, size_type i2) const
iterator begin(size_type i1, size_type i2)
const T & const_reference
iterator ptr(size_type i1, size_type i2, size_type i3, size_type i4)
reference at(size_type i1, size_type i2, size_type i3, size_type i4, size_type i5)
iterator p_iterator(size_type i1, size_type i2) const
void reserve(size_type i1, size_type i2, size_type i3, size_type i4)
void reserve(size_type i1)
iterator p_iterator(size_type i1, size_type i2, size_type i3, size_type i4, size_type i5, size_type i6) const
const_reference front(size_type i1, size_type i2, size_type i3) const
reference back(size_type i1, size_type i2, size_type i3, size_type i4)
iterator end(size_type i1, size_type i2, size_type i3, size_type i4)
const_iterator ptr(size_type i1, size_type i2, size_type i3, size_type i4) const
iterator begin(size_type i1)
const_pointer data() const
multi_arr(const multi_arr &m)
const_reference front(size_type i1, size_type i2) const
iterator p_iterator_bc(size_type i1, size_type i2, size_type i3, size_type i4) const
multi_arr(size_type d1, size_type d2, size_type d3)
multi_arr(const multi_geom< d, ALLOC > &g)
void reserve(size_type i1, size_type i2, size_type i3)
void p_setupArray(size_type n1[], size_type n2[], const tree_vec *g, int l)
const_reference back(size_type i1, size_type i2, size_type i3) const
void alloc(size_type index[])
const const_n_pointer< T, d, ALLOC, lgBC > n_ptr() const
iterator p_iterator_bc(size_type i1, size_type i2) const
const_iterator begin(size_type i1, size_type i2, size_type i3) const
const_iterator end(size_type i1, size_type i2, size_type i3, size_type i4) const
void alloc(size_type d1, size_type d2, size_type d3, size_type d4, size_type d5, size_type d6)
const_iterator end(size_type i1, size_type i2, size_type i3, size_type i4, size_type i5) const
const_iterator end(size_type i1, size_type i2) const
const_iterator ptr(size_type i1, size_type i2, size_type i3, size_type i4, size_type i5, size_type i6) const
const indexed_type operator[](size_type i)
const_reference at(size_type i1, size_type i2, size_type i3, size_type i4, size_type i5, size_type i6) const
iterator end(size_type i1)
void reserve(size_type i1, size_type i2)
reference front(size_type i1)
multi_arr(size_type d1, size_type d2, size_type d3, size_type d4, size_type d5)
reference front(size_type i1, size_type i2, size_type i3, size_type i4)
reference at(size_type i1, size_type i2)
ptrdiff_t difference_type
const multi_geom< d, ALLOC > & clone() const
void alloc(size_type d1, size_type d2, size_type d3)
iterator end(size_type i1, size_type i2, size_type i3, size_type i4, size_type i5)
multi_arr(size_type d1, size_type d2)
iterator ptr(size_type i1, size_type i2, size_type i3, size_type i4, size_type i5)
const_iterator end(size_type i1) const
const_reference front(size_type i1) const
reference back(size_type i1, size_type i2, size_type i3)
size_type capacity() const
void reserve(size_type i1, size_type i2, size_type i3, size_type i4, size_type i5, size_type i6)
void alloc(size_type d1, size_type d2, size_type d3, size_type d4, size_type d5)
reference front(size_type i1, size_type i2, size_type i3)
const_iterator ptr(size_type i1, size_type i2, size_type i3, size_type i4, size_type i5) const
const multi_arr & operator=(const multi_arr &m)
n_pointer< T, d-1, ALLOC, lgBC > indexed_type
const_reference back(size_type i1) const
iterator begin(size_type i1, size_type i2, size_type i3, size_type i4)
size_type st[d]
size of each dimension (only used in C_TYPE layout)
void p_clear0()
sizes of each of the pointer arrays
const multi_geom & operator=(const multi_geom &m)
bool lgInbounds(const size_type n, const size_type index[]) const
void p_setupArray(size_type n1[], size_type n2[], const tree_vec *w, int l)
void reserve(const size_type n, const size_type index[])
size_type nsl[d]
stride for each dimension (only used in C_TYPE layout)
void reserve_recursive(const size_type n, size_type index[])
multi_geom(const multi_geom &m)
size_type s[d]
allocated size (number of data elements, pointers are not counted)
n_pointer(T *p, const size_t *st=NULL, const tree_vec *v=NULL)
n_pointer(T *p, const size_t *st, const tree_vec *v)
n_pointer(T *p, const size_t *st, const tree_vec *v=NULL)
n_pointer(T *p, const size_t *st, const tree_vec *v)
n_pointer< T, N-1, ARPA_TYPE, false > value_type
n_pointer(T *p, const size_t *st=NULL, const tree_vec *v=NULL)
n_pointer(T *p, const size_t *st, const tree_vec *v)
n_pointer< T, N-1, ARPA_TYPE, true > value_type
n_pointer< T, N-1, C_TYPE, false > value_type
n_pointer(T *p, const size_t *st, const tree_vec *v=NULL)
n_pointer< T, N-1, C_TYPE, true > value_type
n_pointer(T *p, const size_t *st, const tree_vec *v)
pntr - interface class to replace normal pointers
pntr(T *p0, T *p1, T *p2)
const pntr operator+(const ptrdiff_t n) const
const pntr operator-(const ptrdiff_t n) const
multi_arr< long, 6 >::const_iterator ml6ci
flex_arr< realnum >::iterator fari
multi_arr< double, 3 >::iterator md3i
void do_restore_state(void *buf, size_t nelem, size_t size, FILE *in, int32 magic)
multi_arr< realnum, 6 >::const_iterator mr6ci
multi_arr< bool, 2 >::const_iterator mb2ci
multi_arr< bool, 4 >::iterator mb4i
flex_arr< long >::iterator fali
multi_arr< double, 2 >::const_iterator md2ci
flex_arr< realnum >::const_iterator farci
flex_arr< bool >::const_iterator fabci
multi_arr< long, 3 >::const_iterator ml3ci
multi_arr< long, 4 >::const_iterator ml4ci
flex_arr< long >::const_iterator falci
multi_arr< realnum, 4 >::const_iterator mr4ci
multi_arr< bool, 6 >::const_iterator mb6ci
multi_arr< bool, 2 >::iterator mb2i
multi_arr< realnum, 5 >::iterator mr5i
flex_arr< double >::const_iterator fadci
multi_arr< long, 2 >::iterator ml2i
multi_arr< long, 2 >::const_iterator ml2ci
multi_arr< long, 4 >::iterator ml4i
multi_arr< long, 5 >::const_iterator ml5ci
multi_arr< double, 4 >::iterator md4i
multi_arr< realnum, 4 >::iterator mr4i
multi_arr< realnum, 6 >::iterator mr6i
multi_arr< long, 5 >::iterator ml5i
multi_arr< realnum, 2 >::const_iterator mr2ci
flex_arr< bool >::iterator fabi
flex_arr< double >::iterator fadi
const pntr< T, lgBC > operator+(const ptrdiff_t n, const pntr< T, lgBC > &t)
multi_arr< double, 2 >::iterator md2i
multi_arr< double, 6 >::const_iterator md6ci
multi_arr< double, 4 >::const_iterator md4ci
multi_arr< bool, 5 >::const_iterator mb5ci
void do_dump_state(const void *buf, size_t nelem, size_t size, FILE *out, int32 magic)
multi_arr< bool, 6 >::iterator mb6i
multi_arr< realnum, 5 >::const_iterator mr5ci
multi_arr< realnum, 3 >::iterator mr3i
multi_arr< bool, 3 >::iterator mb3i
multi_arr< realnum, 3 >::const_iterator mr3ci
multi_arr< long, 6 >::iterator ml6i
multi_arr< bool, 4 >::const_iterator mb4ci
multi_arr< double, 3 >::const_iterator md3ci
multi_arr< bool, 5 >::iterator mb5i
multi_arr< double, 6 >::iterator md6i
multi_arr< double, 5 >::iterator md5i
multi_arr< bool, 3 >::const_iterator mb3ci
static const int32 MA_VERS[ML_TOP]
multi_arr< realnum, 2 >::iterator mr2i
multi_arr< double, 5 >::const_iterator md5ci
multi_arr< long, 3 >::iterator ml3i
tree_vec - a simple class to store the bounds checking information for multi_arr
const tree_vec & getvec(const size_type i, const size_type index[]) const
tree_vec & getvec(const size_type i, const size_type index[])
tree_vec(const tree_vec &m)
const tree_vec & operator=(const tree_vec &m)