OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
Odometer.cc
Go to the documentation of this file.
1 // -*- mode: c++; c-basic-offset:4 -*-
2 
3 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
4 // Access Protocol.
5 
6 // Copyright (c) 2015 OPeNDAP, Inc.
7 // Author: James Gallagher <jgallagher@opendap.org>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 //
23 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24 
25 #include "config.h"
26 
27 #include <vector>
28 
29 #include <Error.h>
30 
31 #include "Odometer.h"
32 
33 using namespace std;
34 
35 namespace libdap {
36 
37 // documentation in the header file
38 unsigned int Odometer::next_safe()
39 {
40  if (d_offset == end()) throw Error("Attempt to move beyond the end of an array in the indexing software.");
41 
42  // About 3.3 seconds for 10^9 elements
43  vector<unsigned int>::reverse_iterator si = d_shape.rbegin();
44  for (vector<unsigned int>::reverse_iterator i = d_indices.rbegin(), e = d_indices.rend(); i != e; ++i, ++si) {
45  if (++(*i) == *si) {
46  *i = 0;
47  }
48  else {
49  break;
50  }
51  }
52 
53  return ++d_offset;
54 }
55 
56 #if 0
57 unsigned int Odometer::next_2()
58 {
59  if (d_offset == end()) throw Error("Attempt to move beyond the end of an array in the indexing software.");
60 
61  // ... about 3.5 seconds for this code
62  // TODO Unroll this using a switch()
63  unsigned int i = d_rank - 1;
64  do {
65  if (++d_indices[i] == d_shape[i]) {
66  d_indices[i] = 0;
67  }
68  else {
69  break;
70  }
71 
72  } while (i-- > 0);
73 
74  return ++d_offset;
75 }
76 #endif
77 
78 } // namespace libdap
STL namespace.
static class NCMLUtil overview