App
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
app::MirroredReindexer Class Reference

Třída pro LUT pro indexy. More...

#include <MirroredReindexer.hpp>

Public Member Functions

 MirroredReindexer (int from, int to, int width)
 Konstruktor.
 
int getCount ()
 Vrátí velikost přeindexované oblasti.
 
int * getVals ()
 Vrátí ukazatel na začátek pole, kde jsou uloženy nové indexy.
 
int reindex (int oldIndex)
 Přeindexuje index.
 
 ~MirroredReindexer ()
 Destruktor.
 

Protected Member Functions

void add (int val)
 Přidá hodnotu do LUT.
 

Protected Attributes

int count
 Velikost LUT.
 
int offset
 Posun souřadnic LUT oproti souřadnicím požadovaným.
 
int * vals
 Pole obsahující LUT.
 
int * ptr
 Pomocný ukazatel pro přidávání hodnot.
 

Detailed Description

Třída pro LUT pro indexy.

Třída vytváří LUT, který umožňuje přeindexovávat pole tak, aby při pokusu o přístup mimo pole se vrátil index odpovídající prvku, který by na požadovaném místě byl, kdyby pole bylo větší a doplněno o prvky, které tvoří zrcadlovou kopii prvků v poli.

Třída je optimalizovaná pro rychlost, tedy nekontroluje při přístupu NULL ani meze!

Definition at line 26 of file MirroredReindexer.hpp.

Constructor & Destructor Documentation

app::MirroredReindexer::MirroredReindexer ( int  from,
int  to,
int  width 
)
inline

Konstruktor.

Vytvoří instanci tak, že je schopná přeindexovat indexy od indexu from (včetně) do indexu to (ten již přeindexovat nelze). Předpokládá se přeindexování indexů pole šířky width, tedy prvním indexem je 0 a posledním přípustným prvkem je prvek o index [width - 1]

Parameters
fromDolní požadovaný index.
toHorní mez požadovaných indexů.
widthŠířka původního pole.

Definition at line 49 of file MirroredReindexer.hpp.

{
vals = NULL;
count = to - from;
if (count <= 0) { count = 0; return; }
vals = (int *) malloc((unsigned long int)(count * sizeof(int))); // ANDROID_SPECIFIC přetypování v malloc
if (vals == NULL) { count = 0; return; }
ptr = vals;
offset = -from;
int i = from;
while (i < 0) {
add((-(i + 1)) % width);
i++;
}
int limit = (to < width) ? to : width;
while (i < limit) {
add(i);
i++;
}
int modWidth = width - 1;
while (i < to) {
add(modWidth - (i % width));
i++;
}
}
app::MirroredReindexer::~MirroredReindexer ( )
inline

Destruktor.

Definition at line 92 of file MirroredReindexer.hpp.

{
if (vals != NULL) { free(vals); }
}

Member Function Documentation

void app::MirroredReindexer::add ( int  val)
inlineprotected

Přidá hodnotu do LUT.

Definition at line 34 of file MirroredReindexer.hpp.

{
*ptr = val; ptr++;
}
int app::MirroredReindexer::getCount ( )
inline

Vrátí velikost přeindexované oblasti.

Definition at line 75 of file MirroredReindexer.hpp.

{ return count; }
int* app::MirroredReindexer::getVals ( )
inline

Vrátí ukazatel na začátek pole, kde jsou uloženy nové indexy.

Definition at line 78 of file MirroredReindexer.hpp.

{ return vals; }
int app::MirroredReindexer::reindex ( int  oldIndex)
inline

Přeindexuje index.

Přeindexuje index.

Parameters
oldIndexPožadovaný index.
Returns
Index použitelný v poli.

Definition at line 87 of file MirroredReindexer.hpp.

{
return vals[oldIndex + offset];
}

Member Data Documentation

int app::MirroredReindexer::count
protected

Velikost LUT.

Definition at line 28 of file MirroredReindexer.hpp.

int app::MirroredReindexer::offset
protected

Posun souřadnic LUT oproti souřadnicím požadovaným.

Definition at line 29 of file MirroredReindexer.hpp.

int* app::MirroredReindexer::ptr
protected

Pomocný ukazatel pro přidávání hodnot.

Definition at line 31 of file MirroredReindexer.hpp.

int* app::MirroredReindexer::vals
protected

Pole obsahující LUT.

Definition at line 30 of file MirroredReindexer.hpp.


The documentation for this class was generated from the following file: