File: history.C

package info (click to toggle)
xshisen 1:1.51-4.1+deb8u1
  • links: PTS
  • area: main
  • in suites: jessie
  • size: 1,156 kB
  • ctags: 553
  • sloc: cpp: 4,008; sh: 152; perl: 146; makefile: 114
file content (79 lines) | stat: -rw-r--r-- 1,325 bytes parent folder | download | duplicates (8)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "components.h"

History::History(int c)
{
    piece1 = new Point[c];
    piece2 = new Point[c];
    via1   = new Point[c];
    via2   = new Point[c];
    count  = 0;
}

History::~History(void)
{
    delete[] piece1;
    delete[] piece2;
    delete[] via1;
    delete[] via2;
}

void
History::ChangeHistorySize(int c)
{
    delete[] piece1;
    delete[] piece2;
    delete[] via1;
    delete[] via2;
    piece1 = new Point[c];
    piece2 = new Point[c];
    via1   = new Point[c];
    via2   = new Point[c];
    count  = 0;
}

void
History::AddHistory(const Point &a, const Point &b, const Point &c, const Point &d)
{
    piece1[count] = a;   // Pai 1
    piece2[count] = b;   // Pai 2
    via1[count] = c;     // Via point 1
    via2[count] = d;     // Via point 2
    count++;
}

int
History::BackHistory(void)
{
    if (count > 0) {
        count--;
        return 1;
    }
    else
        return 0;  // Cannot back any more
}

void
History::GetXY(int c, Point &a, Point &b)
{
    // c<0 means count back from current
    if (c < 0)
        c = count + c;
    a = piece1[c];
    b = piece2[c];
}

void
History::GetV(int c, Point &a, Point &b)
{
    // c<0 means count back from current
    if (c < 0)
        c = count + c;
    a = via1[c];
    b = via2[c];
}

void
History::ResetHistory(void)
{
    count = 0;
}