|
Last change
on this file was
2,
checked in by oldcode, 25 years ago
|
|
Initial revision
|
-
Property svn:eol-style set to
native
-
Property svn:keywords set to
Author Date Id Revision
|
|
File size:
1.8 KB
|
| Line | |
|---|
| 1 | #include <stdio.h> |
|---|
| 2 | #include "d_classes.hxx" |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | Element::Element() { |
|---|
| 7 | int i; |
|---|
| 8 | contents = 0; |
|---|
| 9 | marked = FALSE; |
|---|
| 10 | |
|---|
| 11 | first_son = 0; |
|---|
| 12 | last_son = 0; |
|---|
| 13 | left_brother = 0; |
|---|
| 14 | right_brother = 0; |
|---|
| 15 | |
|---|
| 16 | width = 50; // currently fixed |
|---|
| 17 | height = 20; // currently fixed |
|---|
| 18 | width_of_sons = 0; |
|---|
| 19 | height_of_sons = 0; |
|---|
| 20 | number_of_sons = 0; |
|---|
| 21 | } |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | Element::~Element() { |
|---|
| 25 | |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | class Element *Element::set_contents(int v) { |
|---|
| 30 | contents = v; |
|---|
| 31 | |
|---|
| 32 | return this; |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | class Element *Element::get_contents(int &v) { |
|---|
| 37 | v = contents; |
|---|
| 38 | |
|---|
| 39 | return this; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | class Element *Element::print_contents(void) { |
|---|
| 44 | printf("contents:%i\n", contents); |
|---|
| 45 | |
|---|
| 46 | return this; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | class Element *Element::print_contents_recursive(int depth) { |
|---|
| 51 | class Element *tmp = first_son; |
|---|
| 52 | |
|---|
| 53 | printf("depth:%i ",depth); |
|---|
| 54 | this->print_contents(); |
|---|
| 55 | while(tmp) { |
|---|
| 56 | tmp->print_contents_recursive(depth+1); |
|---|
| 57 | tmp = tmp->right_brother; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | return this; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | class Element *Element::dump(void) { |
|---|
| 65 | |
|---|
| 66 | printf("DUMP:: contents: %i width of sons: %i\n",contents,width_of_sons); |
|---|
| 67 | |
|---|
| 68 | return this; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | class Element *Element::dump_recursive(void) { |
|---|
| 73 | class Element *tmp = first_son; |
|---|
| 74 | |
|---|
| 75 | this->dump(); |
|---|
| 76 | |
|---|
| 77 | while(tmp) { |
|---|
| 78 | tmp->dump_recursive(); |
|---|
| 79 | tmp = tmp->right_brother; |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | return this; |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | class Element *Element::calculate_sizes(void) { |
|---|
| 87 | class Element *_tmp = first_son; |
|---|
| 88 | int _width = 0; |
|---|
| 89 | int _height = 0; |
|---|
| 90 | |
|---|
| 91 | while(_tmp) { |
|---|
| 92 | _tmp->calculate_sizes(); |
|---|
| 93 | _width += width; |
|---|
| 94 | _tmp = _tmp->right_brother; |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | width_of_sons = _width; |
|---|
| 98 | |
|---|
| 99 | return this; |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | class Element *Element::add_son(void) { |
|---|
| 104 | class Element *tmp; |
|---|
| 105 | |
|---|
| 106 | tmp = new Element; |
|---|
| 107 | |
|---|
| 108 | if(!first_son) { |
|---|
| 109 | first_son = tmp; |
|---|
| 110 | tmp->left_brother = 0; |
|---|
| 111 | }else{ |
|---|
| 112 | tmp->left_brother = last_son; |
|---|
| 113 | last_son->right_brother = tmp; |
|---|
| 114 | } |
|---|
| 115 | last_son = tmp; |
|---|
| 116 | tmp->right_brother = 0; |
|---|
| 117 | |
|---|
| 118 | number_of_sons++; |
|---|
| 119 | |
|---|
| 120 | return tmp; |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | class Element *Element::get_number_of_sons(int &n) { |
|---|
| 125 | n = number_of_sons; |
|---|
| 126 | |
|---|
| 127 | return this; |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | class Element **Element::get_sons(void) { |
|---|
| 132 | return 0; // not finished |
|---|
| 133 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.