MI - Fimex
DataIndex.h
Go to the documentation of this file.
1 /*
2  * Fimex, DataIndex.h
3  *
4  * (C) Copyright 2012, met.no
5  *
6  * Project Info: https://wiki.met.no/fimex/start
7  *
8  * This library is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 2.1 of the License, or
11  * (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16  * License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21  * USA.
22  *
23  * Created on: Jul 18, 2012
24  * Author: Heiko Klein
25  */
26 
27 #ifndef DATAINDEX_H_
28 #define DATAINDEX_H_
29 
30 #include <vector>
31 
32 namespace MetNoFimex
33 {
34 
35 
39 class DataIndex
40 {
41 private:
42  static std::size_t MIN_DIMS() {return 10;}
45 public:
46  DataIndex() : dims_(0), slices_(MIN_DIMS(), 0) {}
51  explicit DataIndex(std::vector<std::size_t> dimSizes);
52  ~DataIndex();
56  const std::vector<std::size_t>& getDims() const {return dims_;}
63  std::size_t getPos(std::vector<std::size_t> pos) const {std::size_t p = 0; for (std::size_t i = 0; i < pos.size(); ++i) {p += pos.at(i) * slices_.at(i);} return p;}
64  std::size_t getPos(std::size_t a) const {return a;}
65  std::size_t getPos(std::size_t a, std::size_t b) const {return a + b*slices_.at(1);}
66  std::size_t getPos(std::size_t a, std::size_t b, std::size_t c) const {return a + b*slices_.at(1) + c*slices_.at(2);}
67  std::size_t getPos(std::size_t a, std::size_t b, std::size_t c, std::size_t d) const {return a + b*slices_.at(1) + c*slices_.at(2) + d*slices_.at(3);}
68 
69 };
70 
71 } /* namespace MetNoFimex */
72 #endif /* DATAINDEX_H_ */
const std::vector< std::size_t > & getDims() const
Definition: DataIndex.h:56
std::size_t getPos(std::size_t a) const
Definition: DataIndex.h:64
Definition: DataIndex.h:39
Definition: C_CDMReader.h:35
size_type size() const
const_reference at(size_type __n) const
std::size_t getPos(std::vector< std::size_t > pos) const
Definition: DataIndex.h:63
std::size_t getPos(std::size_t a, std::size_t b, std::size_t c, std::size_t d) const
Definition: DataIndex.h:67
std::size_t getPos(std::size_t a, std::size_t b) const
Definition: DataIndex.h:65
std::size_t getPos(std::size_t a, std::size_t b, std::size_t c) const
Definition: DataIndex.h:66
DataIndex()
Definition: DataIndex.h:46