[80] | 1 | // -*- C++ -*- |
---|
| 2 | /*************************************************************************** |
---|
| 3 | * blitz/array/multi.h Support for multicomponent arrays |
---|
| 4 | * |
---|
| 5 | * Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org> |
---|
| 6 | * |
---|
| 7 | * This program is free software; you can redistribute it and/or |
---|
| 8 | * modify it under the terms of the GNU General Public License |
---|
| 9 | * as published by the Free Software Foundation; either version 2 |
---|
| 10 | * of the License, or (at your option) any later version. |
---|
| 11 | * |
---|
| 12 | * This program is distributed in the hope that it will be useful, |
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | * GNU General Public License for more details. |
---|
| 16 | * |
---|
| 17 | * Suggestions: blitz-dev@oonumerics.org |
---|
| 18 | * Bugs: blitz-bugs@oonumerics.org |
---|
| 19 | * |
---|
| 20 | * For more information, please see the Blitz++ Home Page: |
---|
| 21 | * http://oonumerics.org/blitz/ |
---|
| 22 | * |
---|
| 23 | ****************************************************************************/ |
---|
| 24 | #ifndef BZ_ARRAYMULTI_H |
---|
| 25 | #define BZ_ARRAYMULTI_H |
---|
| 26 | |
---|
| 27 | #ifndef BZ_ARRAY_H |
---|
| 28 | #error <blitz/array/multi.h> must be included via <blitz/array.h> |
---|
| 29 | #endif |
---|
| 30 | |
---|
| 31 | BZ_NAMESPACE(blitz) |
---|
| 32 | |
---|
| 33 | /* |
---|
| 34 | * The multicomponent_traits class provides a mapping from multicomponent |
---|
| 35 | * tuples to the element type they contain. For example: |
---|
| 36 | * |
---|
| 37 | * multicomponent_traits<complex<float> >::T_numtype is float, |
---|
| 38 | * multicomponent_traits<TinyVector<int,3> >::T_numtype is int. |
---|
| 39 | * |
---|
| 40 | * This is used to support Array<T,N>::operator[], which extracts components |
---|
| 41 | * from a multicomponent array. |
---|
| 42 | */ |
---|
| 43 | |
---|
| 44 | // By default, produce a harmless component type, and zero components. |
---|
| 45 | template<typename T_component> |
---|
| 46 | struct multicomponent_traits { |
---|
| 47 | typedef T_component T_element; |
---|
| 48 | static const int numComponents = 0; |
---|
| 49 | }; |
---|
| 50 | |
---|
| 51 | // TinyVector |
---|
| 52 | template<typename T_numtype, int N_rank> |
---|
| 53 | struct multicomponent_traits<TinyVector<T_numtype,N_rank> > { |
---|
| 54 | typedef T_numtype T_element; |
---|
| 55 | static const int numComponents = N_rank; |
---|
| 56 | }; |
---|
| 57 | |
---|
| 58 | #ifdef BZ_HAVE_COMPLEX |
---|
| 59 | // complex<T> |
---|
| 60 | template<typename T> |
---|
| 61 | struct multicomponent_traits<complex<T> > { |
---|
| 62 | typedef T T_element; |
---|
| 63 | static const int numComponents = 2; |
---|
| 64 | }; |
---|
| 65 | #endif |
---|
| 66 | |
---|
| 67 | // This macro is provided so that users can register their own |
---|
| 68 | // multicomponent types. |
---|
| 69 | |
---|
| 70 | #define BZ_DECLARE_MULTICOMPONENT_TYPE(T_tuple,T,N) \ |
---|
| 71 | BZ_NAMESPACE(blitz) \ |
---|
| 72 | template<> \ |
---|
| 73 | struct multicomponent_traits<T_tuple > { \ |
---|
| 74 | typedef T T_element; \ |
---|
| 75 | static const int numComponents = N; \ |
---|
| 76 | }; \ |
---|
| 77 | BZ_NAMESPACE_END |
---|
| 78 | |
---|
| 79 | BZ_NAMESPACE_END |
---|
| 80 | |
---|
| 81 | #endif // BZ_ARRAYMULTI_H |
---|