ndIndex.h
1//-*-C++-*-
2/***************************************************************************
3 *
4 * Copyright (C) 2020 by Willem van Straten
5 * Licensed under the Academic Free License version 2.1
6 *
7 ***************************************************************************/
8
9// psrchive/Util/units/ndIndex.h
10
11#ifndef __ndIndex_H
12#define __ndIndex_H
13
14#include <inttypes.h>
15
16template<unsigned N> class ndIndex
17{
18 ndIndex<N-1> next;
19 uint64_t ndat;
20 mutable uint64_t offset;
21
22 friend class ndIndex<N+1>;
23
24public:
25 ndIndex () { offset = 0; }
27 ndIndex<N-1>& operator* (uint64_t sz) { ndat = sz; return next; }
28
29 const ndIndex<N-1>& operator[] (uint64_t idat) const
30 { next.offset = offset + idat * next.stride(); return next; }
31
32 uint64_t stride () const { return ndat * next.stride(); }
33};
34
35template<>
36class ndIndex<1>
37{
38 uint64_t ndat;
39 mutable uint64_t offset;
40
41 friend class ndIndex<2>;
42
43public:
44 ndIndex () { offset = 0; }
45 void operator* (uint64_t sz) { ndat = sz; }
46 uint64_t operator[] (uint64_t idat) const { return offset + idat; }
47 uint64_t stride () const { return ndat; }
48};
49
50#endif
51

Generated using doxygen 1.14.0