Last change
on this file since 1528 was
1528,
checked in by dkearney, 15 years ago
|
updating the objects code and adding some more examples describing how i want developers to use the objects. some of the objects don't work yet, like the tree, anything with an example should work
|
File size:
2.0 KB
|
Line | |
---|
1 | #include <string.h> |
---|
2 | #include "RpChainHelper.h" |
---|
3 | |
---|
4 | #ifdef __cplusplus |
---|
5 | extern "C" { |
---|
6 | #endif |
---|
7 | |
---|
8 | Rp_Chain * |
---|
9 | Rp_ChainJoin ( |
---|
10 | Rp_Chain *c1, |
---|
11 | Rp_Chain *c2) |
---|
12 | { |
---|
13 | Rp_ChainLink *l = NULL; |
---|
14 | |
---|
15 | if (c1 == NULL) { |
---|
16 | return c2; |
---|
17 | } |
---|
18 | |
---|
19 | if (c2 == NULL) { |
---|
20 | return c1; |
---|
21 | } |
---|
22 | |
---|
23 | l = Rp_ChainLastLink(c2); |
---|
24 | while (l != NULL) { |
---|
25 | Rp_ChainUnlinkLink(c2,l); |
---|
26 | Rp_ChainPrependLink(c1,l); |
---|
27 | l = Rp_ChainLastLink(c2); |
---|
28 | } |
---|
29 | |
---|
30 | if (Rp_ChainGetLength(c2) != 0) { |
---|
31 | // FIXME: add error message |
---|
32 | } |
---|
33 | |
---|
34 | Rp_ChainDestroy(c2); |
---|
35 | |
---|
36 | return c1; |
---|
37 | } |
---|
38 | |
---|
39 | Rp_Chain * |
---|
40 | Rp_ChainConcat ( |
---|
41 | Rp_Chain *c1, |
---|
42 | Rp_Chain *c2) |
---|
43 | { |
---|
44 | Rp_ChainLink *l = NULL; |
---|
45 | |
---|
46 | if (c1 == NULL) { |
---|
47 | return c2; |
---|
48 | } |
---|
49 | |
---|
50 | if (c2 == NULL) { |
---|
51 | return c1; |
---|
52 | } |
---|
53 | |
---|
54 | l = Rp_ChainFirstLink(c2); |
---|
55 | while (l != NULL) { |
---|
56 | Rp_ChainUnlinkLink(c2,l); |
---|
57 | Rp_ChainAppendLink(c1,l); |
---|
58 | l = Rp_ChainFirstLink(c2); |
---|
59 | } |
---|
60 | |
---|
61 | return c1; |
---|
62 | } |
---|
63 | |
---|
64 | int |
---|
65 | Rp_ChainCopy ( |
---|
66 | Rp_Chain *c1, |
---|
67 | Rp_Chain *c2, |
---|
68 | int (*cpyFxn)(void **to,void *from)) |
---|
69 | { |
---|
70 | void *origVal = NULL; |
---|
71 | void *copyVal = NULL; |
---|
72 | Rp_ChainLink *lorig = NULL; |
---|
73 | |
---|
74 | if ( ( (c1 == NULL) && (c2 == NULL) ) |
---|
75 | || (cpyFxn == NULL) ) { |
---|
76 | // raise error, improper function call |
---|
77 | return -1; |
---|
78 | } |
---|
79 | |
---|
80 | if (c1 == NULL) { |
---|
81 | // nothing to copy to |
---|
82 | return 0; |
---|
83 | } |
---|
84 | |
---|
85 | if (c2 == NULL) { |
---|
86 | // nothing to copy from |
---|
87 | return 0; |
---|
88 | } |
---|
89 | |
---|
90 | lorig = Rp_ChainFirstLink(c2); |
---|
91 | while (lorig != NULL) { |
---|
92 | origVal = (void*) Rp_ChainGetValue(lorig); |
---|
93 | if (cpyFxn(©Val,origVal) != 0) { |
---|
94 | // error while copying |
---|
95 | return -1; |
---|
96 | } |
---|
97 | Rp_ChainAppend(c1,copyVal); |
---|
98 | lorig = Rp_ChainNextLink(lorig); |
---|
99 | } |
---|
100 | |
---|
101 | return 0; |
---|
102 | } |
---|
103 | |
---|
104 | int |
---|
105 | Rp_ChainCharCpyFxn ( |
---|
106 | void **to, |
---|
107 | void *from) |
---|
108 | { |
---|
109 | size_t len = 0; |
---|
110 | |
---|
111 | len = strlen((char*)from); |
---|
112 | *to = (void*) malloc(len*sizeof(char)+1); |
---|
113 | strncpy((char*)(*to),(char*)from,len+1); |
---|
114 | return 0; |
---|
115 | } |
---|
116 | |
---|
117 | int |
---|
118 | Rp_ChainCharCmpFxn ( |
---|
119 | void *to, |
---|
120 | void *from) |
---|
121 | { |
---|
122 | return strcmp(to,from); |
---|
123 | } |
---|
124 | |
---|
125 | #ifdef __cplusplus |
---|
126 | } |
---|
127 | #endif |
---|
128 | |
---|
Note: See
TracBrowser
for help on using the repository browser.