source: XMLIO_V2/external/include/blitz/traversal.h @ 80

Last change on this file since 80 was 80, checked in by ymipsl, 14 years ago

ajout lib externe

  • Property svn:eol-style set to native
File size: 3.8 KB
Line 
1/***************************************************************************
2 * blitz/traversal.h      Declaration of the TraversalOrder classes
3 *
4 * $Id: traversal.h,v 1.5 2003/01/14 11:29:18 patricg Exp $
5 *
6 * Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * Suggestions:          blitz-dev@oonumerics.org
19 * Bugs:                 blitz-bugs@oonumerics.org
20 *
21 * For more information, please see the Blitz++ Home Page:
22 *    http://oonumerics.org/blitz/
23 *
24 ***************************************************************************/
25
26// Fast traversal orders require the ISO/ANSI C++ standard library
27// (particularly set).
28#ifdef BZ_HAVE_STD
29
30#ifndef BZ_TRAVERSAL_H
31#define BZ_TRAVERSAL_H
32
33#ifndef BZ_TINYVEC_H
34 #include <blitz/tinyvec.h>
35#endif
36
37#ifndef BZ_VECTOR_H
38 #include <blitz/vector.h>
39#endif
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.