source: XIOS/dev/dev_olga/src/extern/blitz/include/blitz/array/multi.h @ 1022

Last change on this file since 1022 was 1022, checked in by mhnguyen, 7 years ago
File size: 3.1 KB
Line 
1// -*- C++ -*-
2/***************************************************************************
3 * blitz/array/multi.h  Support for multicomponent arrays
4 *
5 * $Id$
6 *
7 * Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
8 *
9 * This file is a part of Blitz.
10 *
11 * Blitz is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation, either version 3
14 * of the License, or (at your option) any later version.
15 *
16 * Blitz is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with Blitz.  If not, see <http://www.gnu.org/licenses/>.
23 *
24 * Suggestions:          blitz-devel@lists.sourceforge.net
25 * Bugs:                 blitz-support@lists.sourceforge.net   
26 *
27 * For more information, please see the Blitz++ Home Page:
28 *    https://sourceforge.net/projects/blitz/
29 *
30 ****************************************************************************/
31#ifndef BZ_ARRAYMULTI_H
32#define BZ_ARRAYMULTI_H
33
34#ifndef BZ_ARRAY_H
35 #error <blitz/array/multi.h> must be included via <blitz/array.h>
36#endif
37
38BZ_NAMESPACE(blitz)
39
40/*
41 * The multicomponent_traits class provides a mapping from multicomponent
42 * tuples to the element type they contain.  For example:
43 *
44 * multicomponent_traits<complex<float> >::T_numtype is float,
45 * multicomponent_traits<TinyVector<int,3> >::T_numtype is int.
46 *
47 * This is used to support Array<T,N>::operator[], which extracts components
48 * from a multicomponent array.
49 */
50
51// By default, produce a harmless component type, and zero components.
52template<typename T_component>
53struct multicomponent_traits {
54    typedef T_component T_element;
55    static const int numComponents = 0;
56};
57
58// TinyVector
59template<typename T_numtype, int N_rank>
60struct multicomponent_traits<TinyVector<T_numtype,N_rank> > {
61    typedef T_numtype T_element;
62    static const int numComponents = N_rank;
63};
64
65// TinyMatrix
66template<typename T_numtype, int N_rows, int N_cols>
67struct multicomponent_traits<TinyMatrix<T_numtype,N_rows, N_cols> > {
68    typedef T_numtype T_element;
69    static const int numComponents = N_rows*N_cols;
70};
71
72#ifdef BZ_HAVE_COMPLEX
73// complex<T>
74template<typename T>
75struct multicomponent_traits<complex<T> > {
76    typedef T T_element;
77    static const int numComponents = 2;
78};
79#endif
80
81// This macro is provided so that users can register their own
82// multicomponent types.
83
84#define BZ_DECLARE_MULTICOMPONENT_TYPE(T_tuple,T,N)          \
85  BZ_NAMESPACE(blitz)                                        \
86  template<>                                                 \
87  struct multicomponent_traits<T_tuple > {                   \
88    typedef T T_element;                                     \
89    static const int numComponents = N;                      \
90  };                                                         \
91  BZ_NAMESPACE_END
92
93BZ_NAMESPACE_END
94
95#endif // BZ_ARRAYMULTI_H
Note: See TracBrowser for help on using the repository browser.