source: trunk/gsdl/src/colservr/maptools.cpp@ 367

Last change on this file since 367 was 194, checked in by rjmcnab, 25 years ago

Moved from src/recpt.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1/**********************************************************************
2 *
3 * maptools.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * PUT COPYRIGHT NOTICE HERE
7 *
8 * $Id: maptools.cpp 194 1999-03-09 20:53:14Z rjmcnab $
9 *
10 *********************************************************************/
11
12/*
13 $Log$
14 Revision 1.1 1999/03/09 20:53:13 rjmcnab
15 Moved from src/recpt.
16
17 Revision 1.1 1999/03/08 19:45:53 rjmcnab
18 Initial revision.
19
20 */
21
22
23#include "maptools.h"
24
25
26
27void stringmap::clear () {
28 fromorder.erase (fromorder.begin(), fromorder.end());
29 mapfrom.erase (mapfrom.begin(), mapfrom.end());
30}
31
32void stringmap::importmap (const text_tarray &maparray) {
33 clear ();
34
35 text_tarray::const_iterator here = maparray.begin();
36 text_tarray::const_iterator end = maparray.end();
37 text_t from;
38 text_t to;
39
40 while (here != end) {
41 splitmapentry (*here, from, to);
42 fromorder.push_back (from);
43 mapfrom[from] = to;
44 here++;
45 }
46}
47
48void stringmap::exportmap (text_tarray &maparray) const {
49 maparray.erase (maparray.begin(), maparray.end());
50
51 text_tarray::const_iterator here = fromorder.begin();
52 text_tarray::const_iterator end = fromorder.end();
53 text_tmap::const_iterator toptr;
54 text_t tempmap;
55
56 while (here != end) {
57 toptr = mapfrom.find (*here);
58 if (toptr != mapfrom.end()) {
59 joinmapentry ((*toptr).first, (*toptr).second, tempmap);
60 maparray.push_back (tempmap);
61 }
62
63 here++;
64 }
65}
66
67void stringmap::getfromarray (text_tarray &fromarray) const {
68 fromarray = fromorder;
69}
70
71void stringmap::gettoarray (text_tarray &toarray) const {
72 toarray.erase(toarray.begin(), toarray.end());
73
74 text_tarray::const_iterator here = fromorder.begin();
75 text_tarray::const_iterator end = fromorder.end();
76 text_tmap::const_iterator toptr;
77
78 while (here != end) {
79 toptr = mapfrom.find (*here);
80 if (toptr != mapfrom.end()) {
81 toarray.push_back((*toptr).second);
82 }
83 here++;
84 }
85}
86
87bool stringmap::fromexists (const text_t &from) const {
88 return (mapfrom.find (from) != mapfrom.end ());
89}
90
91bool stringmap::toexists (const text_t &to) const {
92 text_tarray::const_iterator here = fromorder.begin();
93 text_tarray::const_iterator end = fromorder.end();
94 text_tmap::const_iterator toptr;
95
96 while (here != end) {
97 toptr = mapfrom.find (*here);
98 if (toptr != mapfrom.end() && (*toptr).second == to) return true;
99 here++;
100 }
101
102 // it was not found
103 return false;
104}
105
106bool stringmap::from2to (const text_t &from, text_t &to) const {
107 text_tmap::const_iterator toptr = mapfrom.find (from);
108 if (toptr == mapfrom.end()) {
109 to.clear();
110 return false;
111 }
112
113 to = (*toptr).second;
114 return true;
115}
116
117bool stringmap::to2from (const text_t &to, text_t &from) const {
118 text_tarray::const_iterator here = fromorder.begin();
119 text_tarray::const_iterator end = fromorder.end();
120 text_tmap::const_iterator toptr;
121
122 while (here != end) {
123 toptr = mapfrom.find (*here);
124 if (toptr != mapfrom.end() && (*toptr).second == to) {
125 from = (*toptr).first;
126 return true;
127 }
128 here++;
129 }
130
131 // it was not found
132 from.clear();
133 return false;
134}
135
136
137
138void splitmapentry (const text_t &map, text_t &from, text_t &to) {
139 from.clear ();
140 to.clear();
141
142 text_t::const_iterator here = map.begin();
143 text_t::const_iterator end = map.end();
144
145 // get the "from" part of the map
146 while (here != end) {
147 if (*here == '-') {
148 here++;
149 if (here != end && *here == '>') {
150 here++;
151 break; // found "->"
152 }
153
154 // didn't find "->"
155 from.push_back('-');
156
157 } else {
158 from.push_back(*here);
159 here++;
160 }
161 }
162
163 // get the "to" part of the map
164 while (here != end) {
165 to.push_back(*here);
166 here++;
167 }
168}
169
170void joinmapentry (const text_t &from, const text_t &to, text_t &map) {
171 map = from;
172 map += "->";
173 map += to;
174}
Note: See TracBrowser for help on using the repository browser.