App
MirroredReindexer.hpp
Go to the documentation of this file.
1 
6 namespace app {
7  class MirroredReindexer;
8 }
9 
10 #ifndef MIRROREDREINDEXER_HPP_
11 #define MIRROREDREINDEXER_HPP_
12 
13 #include <cstdlib>
14 
15 namespace app {
16 
18 
27 protected:
28  int count;
29  int offset;
30  int * vals;
31  int * ptr;
32 
34  void add(int val) {
35  *ptr = val; ptr++;
36  }
37 
38 public:
40 
49  MirroredReindexer(int from, int to, int width) {
50  vals = NULL;
51  count = to - from;
52  if (count <= 0) { count = 0; return; }
53  vals = (int *) malloc((unsigned long int)(count * sizeof(int))); // ANDROID_SPECIFIC přetypování v malloc
54  if (vals == NULL) { count = 0; return; }
55  ptr = vals;
56  offset = -from;
57  int i = from;
58  while (i < 0) {
59  add((-(i + 1)) % width);
60  i++;
61  }
62  int limit = (to < width) ? to : width;
63  while (i < limit) {
64  add(i);
65  i++;
66  }
67  int modWidth = width - 1;
68  while (i < to) {
69  add(modWidth - (i % width));
70  i++;
71  }
72  }
73 
75  int getCount() { return count; }
76 
78  int * getVals() { return vals; }
79 
80 
82 
87  int reindex(int oldIndex) {
88  return vals[oldIndex + offset];
89  }
90 
93  if (vals != NULL) { free(vals); }
94  }
95 };
96 
97 } /* namespace app */
98 #endif /* MIRROREDREINDEXER_HPP_ */