| 1 | // Support for multicomponent arrays | 
|---|
| 2 |  | 
|---|
| 3 | #ifndef BZ_ARRAYMULTI_H | 
|---|
| 4 | #define BZ_ARRAYMULTI_H | 
|---|
| 5 |  | 
|---|
| 6 | #ifndef BZ_ARRAY_H | 
|---|
| 7 | #error <blitz/array/multi.h> must be included via <blitz/array.h> | 
|---|
| 8 | #endif | 
|---|
| 9 |  | 
|---|
| 10 | BZ_NAMESPACE(blitz) | 
|---|
| 11 |  | 
|---|
| 12 | /* | 
|---|
| 13 | * The multicomponent_traits class provides a mapping from multicomponent | 
|---|
| 14 | * tuples to the element type they contain.  For example: | 
|---|
| 15 | * | 
|---|
| 16 | * multicomponent_traits<complex<float> >::T_numtype is float, | 
|---|
| 17 | * multicomponent_traits<TinyVector<int,3> >::T_numtype is int. | 
|---|
| 18 | * | 
|---|
| 19 | * This is used to support Array<T,N>::operator[], which extracts components | 
|---|
| 20 | * from a multicomponent array. | 
|---|
| 21 | */ | 
|---|
| 22 |  | 
|---|
| 23 | // By default, produce a harmless component type, and zero components. | 
|---|
| 24 | template<class T_component> | 
|---|
| 25 | struct multicomponent_traits { | 
|---|
| 26 | typedef T_component T_element; | 
|---|
| 27 | enum { numComponents = 0 }; | 
|---|
| 28 | }; | 
|---|
| 29 |  | 
|---|
| 30 | // TinyVector | 
|---|
| 31 | template<class T_numtype, int N_rank> | 
|---|
| 32 | struct multicomponent_traits<TinyVector<T_numtype,N_rank> > { | 
|---|
| 33 | typedef T_numtype T_element; | 
|---|
| 34 | enum { numComponents = N_rank }; | 
|---|
| 35 | }; | 
|---|
| 36 |  | 
|---|
| 37 | // complex<T> | 
|---|
| 38 | template<class T> | 
|---|
| 39 | struct multicomponent_traits<complex<T> > { | 
|---|
| 40 | typedef T T_element; | 
|---|
| 41 | enum { numComponents = 2 }; | 
|---|
| 42 | }; | 
|---|
| 43 |  | 
|---|
| 44 | // This macro is provided so that users can register their own | 
|---|
| 45 | // multicomponent types. | 
|---|
| 46 |  | 
|---|
| 47 | #define BZ_DECLARE_MULTICOMPONENT_TYPE(T_tuple,T,N)          \ | 
|---|
| 48 | template<>                                                 \ | 
|---|
| 49 | struct multicomponent_traits<T_tuple > {                   \ | 
|---|
| 50 | typedef T T_element;                                     \ | 
|---|
| 51 | enum { numComponents = N };                              \ | 
|---|
| 52 | }; | 
|---|
| 53 |  | 
|---|
| 54 | BZ_NAMESPACE_END | 
|---|
| 55 |  | 
|---|
| 56 | #endif // BZ_ARRAYMULTI_H | 
|---|