summaryrefslogtreecommitdiff
path: root/src/T2HUnknown.cpp
blob: 2ca8ab6224e78ebf03e42b524944e0c8ccdb89c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "T2HUnknown.h"

T2HUnknown::T2HUnknown(int capacity) {
    mData = (int *) malloc(sizeof(int) * capacity);
    mLength = 0;
    mCapacity = capacity;
}

T2HUnknown::~T2HUnknown() {
    free(mData);
}

int T2HUnknown::GetLength() const {
    return mLength;
}

void T2HUnknown::AddValue(int value) {
    if (mLength == mCapacity) {
        mLength--;
        memmove(mData, mData + 1, (mCapacity - 1) * sizeof(int));
    }

    mData[mLength] = value;
    mLength++;
}

int T2HUnknown::GetFirst() const {
    if (mLength == 0)
        return -1;
    return 0;
}

int T2HUnknown::GetNext(int &position) const {
    if (position == -1 || position == mLength) {
        position = -1;
        return 0;
    }

    int value = mData[position];
    position++;
    if (position == mLength)
        position = -1;
    return value;
}

void T2HUnknown::SetAll(int value) {
    for (int i = 0; i < mCapacity; i++)
        mData[i] = value;
}