1 | // standard headers
|
---|
2 | #if defined(GSDL_USE_STL_H)
|
---|
3 | #include <iostream.h>
|
---|
4 | #include <fstream.h>
|
---|
5 | #include <vector.h>
|
---|
6 | #else
|
---|
7 | #include <iostream>
|
---|
8 | #include <fstream>
|
---|
9 | #include <vector>
|
---|
10 | #endif
|
---|
11 |
|
---|
12 | // protocol headers
|
---|
13 | #include "corbaiface.h"
|
---|
14 | using namespace gsdlInterface;
|
---|
15 |
|
---|
16 | // greenstone headers
|
---|
17 | #include "corbaconv_text_t.h"
|
---|
18 |
|
---|
19 | //local headers
|
---|
20 | #include "corbatext_t.h"
|
---|
21 |
|
---|
22 | void corbatext_fillChar(corbatext_t *t, char *text)
|
---|
23 | {
|
---|
24 | unsigned int i;
|
---|
25 |
|
---|
26 | t->text.length(0);
|
---|
27 | if (text == NULL)
|
---|
28 | {
|
---|
29 | return;
|
---|
30 | }
|
---|
31 | for (i = 0; i < strlen(text); i ++)
|
---|
32 | {
|
---|
33 | t->text[i] = text[i];
|
---|
34 | }
|
---|
35 | t->encoding = 0;
|
---|
36 | }
|
---|
37 |
|
---|
38 | void corbatext_usvector(corbatext_t t, usvector& us)
|
---|
39 | {
|
---|
40 | unsigned int i;
|
---|
41 |
|
---|
42 | for (i = 0; i < t.text.length(); i ++)
|
---|
43 | {
|
---|
44 | us.push_back(t.text[i]);
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | char *corbatext_string(corbatext_t t)
|
---|
49 | {
|
---|
50 | char *lcopy;
|
---|
51 | unsigned int i;
|
---|
52 | lcopy = (char *) malloc(t.text.length() + 1);
|
---|
53 | for (i = 0; i < t.text.length(); i ++)
|
---|
54 | {
|
---|
55 | lcopy[i] = (char) t.text[i];
|
---|
56 | }
|
---|
57 | lcopy[i] = '\0';
|
---|
58 | return lcopy;
|
---|
59 | }
|
---|
60 |
|
---|
61 | corbatext_t_var corbatext_corbatext(text_t t)
|
---|
62 | { corbatext_t_var ct;
|
---|
63 | // usString_var us;
|
---|
64 |
|
---|
65 | // cout << "Making text\n";
|
---|
66 | ct = new corbatext_t;
|
---|
67 | // ct->text.length(20);
|
---|
68 | // us = new usString(20);
|
---|
69 | // cout << ct->text.length() << endl;
|
---|
70 | // cout << ct->text.maximum() << endl;
|
---|
71 | corbaconv_text_t::fillUsString(t,&ct->text);
|
---|
72 | //t.fillUsString(us);
|
---|
73 | // delete us;
|
---|
74 | // cout << "Encoding text\n";
|
---|
75 | ct->encoding = 0;
|
---|
76 | // cout << "Encoding text\n";
|
---|
77 | return ct;
|
---|
78 | }
|
---|
79 |
|
---|
80 | int corbatext_corbatext(text_t t, corbatext_t_var ct)
|
---|
81 | {
|
---|
82 | cout << "A" << endl;
|
---|
83 | corbaconv_text_t::fillUsString(t,&ct->text);
|
---|
84 | cout << "B" << endl;
|
---|
85 | ct->encoding = 0;
|
---|
86 | cout << "C" << endl;
|
---|
87 |
|
---|
88 | return 0;
|
---|
89 | }
|
---|
90 |
|
---|
91 | void corbatext_corbaArrayToArray(corbatext_tarray ca, text_tarray *ta)
|
---|
92 | {
|
---|
93 | unsigned int i;
|
---|
94 | corbaconv_text_t *cct;
|
---|
95 |
|
---|
96 | ta->clear();
|
---|
97 | ta->reserve(ca.length());
|
---|
98 | for (i = 0; i < ca.length(); i ++)
|
---|
99 | {
|
---|
100 | cct = new corbaconv_text_t(ca[i]);
|
---|
101 | ta->push_back(*cct); // cast to text_t
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 | void corbatext_arrayToCorbaArray(text_tarray ta, corbatext_tarray *_ca)
|
---|
106 | {
|
---|
107 | text_tarray::iterator here = ta.begin();
|
---|
108 | text_tarray::iterator end = ta.end();
|
---|
109 | corbatext_tarray ca(end - here);
|
---|
110 | unsigned int i;
|
---|
111 |
|
---|
112 | i = 0;
|
---|
113 | (*_ca).length(end - here);
|
---|
114 |
|
---|
115 | while (here != end)
|
---|
116 | {
|
---|
117 | corbatext_t_var ptr;
|
---|
118 | // cout << "Array: " << (*_ca).maximum() << " " << (*_ca).length() << endl;
|
---|
119 | ptr = corbatext_corbatext(*here);
|
---|
120 | (*_ca)[i] = ptr;
|
---|
121 | here ++;
|
---|
122 | i++;
|
---|
123 | }
|
---|
124 | }
|
---|
125 |
|
---|
126 | void corbatext_corbaArrayToSet(corbatext_tarray t, text_tset *ts)
|
---|
127 | { unsigned int i;
|
---|
128 |
|
---|
129 | for (i = 0; i < t.length(); i ++)
|
---|
130 | {
|
---|
131 | ts->insert((corbaconv_text_t) t[i]); // further typecast to text_t
|
---|
132 | }
|
---|
133 |
|
---|
134 | return;
|
---|
135 | }
|
---|
136 |
|
---|
137 | void corbatext_setToCorbaArray(text_tset ts, corbatext_tarray *t)
|
---|
138 | {
|
---|
139 | corbatext_t str;
|
---|
140 | text_tset::iterator here = ts.begin();
|
---|
141 | text_tset::iterator end = ts.end();
|
---|
142 | unsigned int i;
|
---|
143 |
|
---|
144 | i = 0;
|
---|
145 | while (here != end)
|
---|
146 | {
|
---|
147 | (*t).length(i+1);
|
---|
148 | (*t)[i] = *corbatext_corbatext(*here);
|
---|
149 | here ++;
|
---|
150 | i ++;
|
---|
151 | }
|
---|
152 | }
|
---|
153 |
|
---|
154 | void corbatext_mapToCorbaMap(text_tmap map, corbatext_tmap *cmap)
|
---|
155 | {
|
---|
156 | text_tmap::iterator here = map.begin();
|
---|
157 | text_tmap::iterator end = map.end();
|
---|
158 | unsigned int i = 0;
|
---|
159 |
|
---|
160 | while (here != end)
|
---|
161 | {
|
---|
162 | (*cmap).names.length(i+1);
|
---|
163 | (*cmap).values.length(i+1);
|
---|
164 | cmap->names[i] = *corbatext_corbatext((*here).first);
|
---|
165 | cmap->values[i] = *corbatext_corbatext((*here).second);
|
---|
166 | here ++;
|
---|
167 | i ++;
|
---|
168 | }
|
---|
169 | }
|
---|
170 |
|
---|
171 | void corbatext_corbaMapToMap(corbatext_tmap cmap, text_tmap &map)
|
---|
172 | {
|
---|
173 | unsigned int i;
|
---|
174 |
|
---|
175 | for (i = 0; i < cmap.names.length(); i ++)
|
---|
176 | {
|
---|
177 | map.insert(make_pair(*(new corbaconv_text_t(cmap.names[i])),
|
---|
178 | *(new corbaconv_text_t(cmap.values[i])))); // further typecast to text_t
|
---|
179 | }
|
---|
180 | }
|
---|
181 |
|
---|
182 |
|
---|
183 | // map of metanames to array(lang, value). So each metaname[i] maps to array (lang, value).
|
---|
184 | // Note that corbacollectionmeta_map is an array of pairs
|
---|
185 | // each pair consists of (string, map)
|
---|
186 | void corbatext_colmetamapToCorbaColmetamap(collectionmeta_map cm, corbatext_tcollectionmeta_map *ccm)
|
---|
187 | {
|
---|
188 | collectionmeta_map::iterator here = cm.begin();
|
---|
189 | collectionmeta_map::iterator end = cm.end();
|
---|
190 | unsigned int i = 0;
|
---|
191 |
|
---|
192 | while (here != end)
|
---|
193 | {
|
---|
194 | ccm->length(i+1); // increase size of array of (name, tuples) pairs by 1 each time
|
---|
195 |
|
---|
196 | // fill in the metaname field
|
---|
197 | // metaname is of type text_t, get the corbatext value for the text_t key
|
---|
198 | (*ccm)[i].name = *corbatext_corbatext((*here).first); // metaname is of type text_t
|
---|
199 |
|
---|
200 | // fill in the tuples field
|
---|
201 | corbatext_mapToCorbaMap((*here).second, &((*ccm)[i].tuples));
|
---|
202 |
|
---|
203 | here ++;
|
---|
204 | i ++;
|
---|
205 | }
|
---|
206 |
|
---|
207 | }
|
---|
208 |
|
---|
209 | void corbatext_corbaColmetamapToColmetamap(corbatext_tcollectionmeta_map ccm, collectionmeta_map &cm)
|
---|
210 | {
|
---|
211 | unsigned int i;
|
---|
212 |
|
---|
213 | for (i = 0; i < ccm.length(); i ++)
|
---|
214 | {
|
---|
215 | // ccm is an array
|
---|
216 | // where each element is a pair of (name, tuples)
|
---|
217 |
|
---|
218 | // 1. get the (corba_text_t) name and convert it to text_t
|
---|
219 | text_t* meta_name = new corbaconv_text_t(ccm[i].name);
|
---|
220 |
|
---|
221 | corbatext_tmap corbameta_tuples = ccm[i].tuples;
|
---|
222 |
|
---|
223 | text_tmap *tuples_map = new text_tmap();
|
---|
224 | corbatext_corbaMapToMap(ccm[i].tuples, *tuples_map);
|
---|
225 |
|
---|
226 |
|
---|
227 | cm.insert(make_pair(*meta_name,
|
---|
228 | *tuples_map));
|
---|
229 | }
|
---|
230 | }
|
---|
231 |
|
---|