Debian Codegraph @

src/bin/geomutil/vrml2oogl/lib/QvState.c++

raw
1 #include <QvState.h>
2
3 const char *QvState::stackNames[NumStacks] = {
4 "Camera",
5 "Coordinate3",
6 "FontStyle",
7 "Light",
8 "MaterialBinding",
9 "Material",
10 "NormalBinding",
11 "Normal",
12 "ShapeHints",
13 "Texture2",
14 "Texture2Transformation",
15 "TextureCoordinate2",
16 "Transformation",
17 };
18
19 QvState::QvState()
20 {
21 stacks = new QvElement * [NumStacks];
22
23 for (int i = 0; i < NumStacks; i++)
24 stacks[i] = NULL;
25
26 depth = 0;
27 }
28
29 QvState::~QvState()
30 {
31 while (depth > 0)
32 pop();
33
34 delete [] stacks;
35 }
36
37 void
38 QvState::addElement(StackIndex stackIndex, QvElement *elt)
39 {
40 elt->depth = depth;
41 elt->next = stacks[stackIndex];
42 stacks[stackIndex] = elt;
43 }
44
45 void
46 QvState::push()
47 {
48 depth++;
49 }
50
51 void
52 QvState::pop()
53 {
54 depth--;
55
56 for (int i = 0; i < NumStacks; i++)
57 while (stacks[i] != NULL && stacks[i]->depth > depth)
58 popElement((StackIndex) i);
59 }
60
61 void
62 QvState::popElement(StackIndex stackIndex)
63 {
64 QvElement *elt = stacks[stackIndex];
65 stacks[stackIndex] = elt->next;
66 delete elt;
67 }
68
69 void
70 QvState::print()
71 {
72 printf("Traversal state:\n");
73
74 for (int i = 0; i < NumStacks; i++) {
75
76 printf("\tStack [%2d] (%s):\n", i, stackNames[i]);
77
78 if (stacks[i] == NULL)
79 printf("\t\tNULL\n");
80
81 else
82 for (QvElement *elt = stacks[i]; elt != NULL; elt = elt->next)
83 elt->print();
84 }
85 }