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

Last change on this file since 1022 was 1022, checked in by mhnguyen, 7 years ago
File size: 3.9 KB
Line 
1// -*- C++ -*-
2/***************************************************************************
3 * blitz/traversal.h      Declaration of the TraversalOrder classes
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
32// Fast traversal orders require the ISO/ANSI C++ standard library
33// (particularly set).
34#ifdef BZ_HAVE_STD
35
36#ifndef BZ_TRAVERSAL_H
37#define BZ_TRAVERSAL_H
38
39#include <blitz/vector2.h>
40
41#include <set>
42
43BZ_NAMESPACE(blitz)
44
45template<int N_dimensions>
46class TraversalOrder {
47
48public:
49    typedef TinyVector<int, N_dimensions> T_coord;
50  typedef Vector<T_coord>               T_traversal;
51
52    TraversalOrder()
53    {
54        size_ = 0;
55    }
56
57    TraversalOrder(const T_coord& size, T_traversal& order)
58        : size_(size), order_(order)
59    { }
60
61    TraversalOrder(const T_coord& size)
62        : size_(size)
63    { }
64
65    T_coord operator[](int i) const
66    { return order_[i]; }
67
68    T_coord& operator[](int i)
69    { return order_[i]; }
70
71    int length() const
72    { return order_.length(); }
73
74    bool operator<(const TraversalOrder<N_dimensions>& x) const
75    {
76        for (int i=0; i < N_dimensions; ++i)
77        {
78            if (size_[i] < x.size_[i])
79                return true;
80            else if (size_[i] > x.size_[i])
81                return false;
82        }
83        return false;
84    }
85
86    bool operator==(const TraversalOrder<N_dimensions>& x) const
87    {
88        for (int i=0; i < N_dimensions; ++i)
89        {
90            if (size_[i] != x.size_[i])
91                return false;
92        }
93
94        return true;
95    }
96
97protected:
98    T_traversal order_;
99    T_coord     size_;
100};
101
102/*
103 * This specialization is provided to avoid problems with zero-length
104 * vectors.
105 */
106template<>
107class TraversalOrder<0> {
108public:
109     TraversalOrder () {} // AJS
110};
111
112template<int N_dimensions>
113class TraversalOrderCollection {
114public:
115    typedef TraversalOrder<N_dimensions>        T_traversal;
116    typedef _bz_typename T_traversal::T_coord   T_coord;
117    typedef set<T_traversal>                    T_set;
118    typedef _bz_typename set<T_traversal>::const_iterator T_iterator;
119
120    const T_traversal* find(const T_coord& size)
121    {
122        T_iterator iter = traversals_.find(T_traversal(size));
123        if (iter != traversals_.end())
124            return &(*iter);
125        return 0;
126    }
127
128    void insert(T_traversal x)
129    {
130        traversals_.insert(x);
131    }
132
133protected:
134    static T_set traversals_;
135};
136
137template<int N_dimensions>
138_bz_typename TraversalOrderCollection<N_dimensions>::T_set
139    TraversalOrderCollection<N_dimensions>::traversals_;
140
141/*
142 * This specialization is provided to avoid problems with zero-length
143 * vectors.
144 */
145
146template<>
147class TraversalOrderCollection<0> {
148public:
149    typedef int T_traversal;
150    typedef int T_coord;
151    typedef int T_set;
152    typedef int T_iterator;
153
154    const T_traversal* find(const T_coord& size)
155    { return 0; }
156};
157
158BZ_NAMESPACE_END
159
160#include <blitz/traversal.cc>
161
162#endif // BZ_TRAVERSAL_H
163
164#endif // BZ_HAVE_STD
165
Note: See TracBrowser for help on using the repository browser.