Show bonus/malus timer text if available
[ryzomcore.git] / nel / src / ligo / zone_bank.cpp
blobc51c2311b2deefd9fd63fb110262914aabad09ad
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2010-2013 Matt RAYKOWSKI (sfb) <matt.raykowski@gmail.com>
6 // Copyright (C) 2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 //
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "stdligo.h"
24 #include "nel/ligo/zone_bank.h"
26 #include "nel/misc/debug.h"
27 #include "nel/misc/file.h"
28 #include "nel/misc/i_xml.h"
29 #include "nel/misc/o_xml.h"
32 using namespace std;
33 using namespace NLMISC;
35 #ifdef DEBUG_NEW
36 #define new DEBUG_NEW
37 #endif
39 namespace NLLIGO
42 // ***************************************************************************
43 // CZoneBankElement
44 // ***************************************************************************
46 string CZoneBankElement::_NoCatTypeFound = STRING_NO_CAT_TYPE;
48 // ---------------------------------------------------------------------------
49 CZoneBankElement::CZoneBankElement()
51 _SizeX = _SizeY = 0;
54 // ---------------------------------------------------------------------------
55 void CZoneBankElement::addCategory (const std::string &CatType, const std::string &CatValue)
57 _CategoriesMap.insert(pair<string,string>(CatType, CatValue));
60 // ---------------------------------------------------------------------------
61 const string& CZoneBankElement::getName ()
63 return getCategory ("zone");
66 // ---------------------------------------------------------------------------
67 const string& CZoneBankElement::getSize ()
69 return getCategory ("size");
72 // ---------------------------------------------------------------------------
73 const string& CZoneBankElement::getCategory (const string &CatType)
75 map<string,string>::iterator it = _CategoriesMap.find (CatType);
76 if (it == _CategoriesMap.end())
77 return _NoCatTypeFound;
78 else
79 return it->second;
82 // ---------------------------------------------------------------------------
83 void CZoneBankElement::convertSize()
85 const string &sizeString = getSize();
86 string sTmp;
87 uint32 i;
89 for (i = 0; i < sizeString.size(); ++i)
91 if (sizeString[i] == 'x')
92 break;
93 else
94 sTmp += sizeString[i];
96 fromString(sTmp, _SizeX);
98 ++i; sTmp.clear();
99 for (; i < sizeString.size(); ++i)
101 sTmp += sizeString[i];
103 fromString(sTmp, _SizeY);
106 // ---------------------------------------------------------------------------
107 void CZoneBankElement::serial (NLMISC::IStream &f)
109 f.xmlPush ("LIGOZONE");
111 sint version = 1;
112 f.serialVersion (version);
113 string check = "LIGOZONE";
114 f.serialCheck (check);
116 f.xmlPush ("CATEGORIES");
117 f.serialCont (_CategoriesMap);
118 f.xmlPop ();
120 f.xmlPush ("MASK");
121 f.serialCont (_Mask);
122 f.xmlPop ();
124 f.xmlPop ();
126 convertSize();
130 // ---------------------------------------------------------------------------
131 void CZoneBankElement::setMask (const std::vector<bool> &mask, uint8 sizeX, uint8 sizeY)
133 _SizeX = sizeX;
134 _SizeY = sizeY;
135 _Mask = mask;
138 // ***************************************************************************
139 // CZoneBank
140 // ***************************************************************************
142 // ---------------------------------------------------------------------------
143 void CZoneBank::debugSaveInit (CZoneBankElement &zbeTmp, const string &fileName)
147 COFile fileOut;
148 fileOut.open (fileName);
149 COXml output;
150 output.init (&fileOut);
151 zbeTmp.serial (output);
153 catch (const Exception& /*e*/)
159 // ---------------------------------------------------------------------------
160 void CZoneBank::debugInit(const std::string &sPath) // \ todo trap remove this
162 CZoneBankElement zbeTmp;
163 zbeTmp.addCategory ("zone", "Zone001");
164 zbeTmp.addCategory ("size", "1x1");
165 zbeTmp.addCategory ("material", "titFleur");
166 zbeTmp._Mask.push_back (true);
167 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(), zbeTmp));
168 debugSaveInit (zbeTmp, sPath + "Zone001.ligozone");
169 zbeTmp._CategoriesMap.clear ();
170 zbeTmp._Mask.clear ();
173 zbeTmp.addCategory ("zone", "Zone002");
174 zbeTmp.addCategory ("size", "1x1");
175 zbeTmp.addCategory ("material", "titFleur");
176 zbeTmp._Mask.push_back (true);
177 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(), zbeTmp));
178 debugSaveInit (zbeTmp, sPath + "Zone002.ligozone");
179 zbeTmp._CategoriesMap.clear ();
180 zbeTmp._Mask.clear ();
182 zbeTmp.addCategory ("zone", "Zone003");
183 zbeTmp.addCategory ("size", "2x2");
184 zbeTmp.addCategory ("material", "titFleur");
185 zbeTmp._Mask.push_back (true);
186 zbeTmp._Mask.push_back (true);
187 zbeTmp._Mask.push_back (false);
188 zbeTmp._Mask.push_back (true);
189 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(), zbeTmp));
190 debugSaveInit (zbeTmp, sPath + "Zone003.ligozone");
191 zbeTmp._CategoriesMap.clear ();
192 zbeTmp._Mask.clear ();
194 zbeTmp.addCategory ("zone", "Zone004");
195 zbeTmp.addCategory ("size", "2x2");
196 zbeTmp.addCategory ("material", "grozFleur");
197 zbeTmp._Mask.push_back (false);
198 zbeTmp._Mask.push_back (true);
199 zbeTmp._Mask.push_back (true);
200 zbeTmp._Mask.push_back (true);
201 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(), zbeTmp));
202 debugSaveInit (zbeTmp, sPath + "Zone004.ligozone");
203 zbeTmp._CategoriesMap.clear ();
204 zbeTmp._Mask.clear ();
206 zbeTmp.addCategory ("zone", "Zone005");
207 zbeTmp.addCategory ("size", "1x1");
208 zbeTmp.addCategory ("material", "grozFleur");
209 zbeTmp._Mask.push_back (true);
210 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(), zbeTmp));
211 debugSaveInit (zbeTmp, sPath + "Zone005.ligozone");
212 zbeTmp._CategoriesMap.clear ();
213 zbeTmp._Mask.clear ();
215 zbeTmp.addCategory ("zone", "Zone006");
216 zbeTmp.addCategory ("size", "4x2");
217 zbeTmp.addCategory ("material", "grozFleur");
218 zbeTmp._Mask.push_back (true);
219 zbeTmp._Mask.push_back (true);
220 zbeTmp._Mask.push_back (false);
221 zbeTmp._Mask.push_back (false);
222 zbeTmp._Mask.push_back (false);
223 zbeTmp._Mask.push_back (true);
224 zbeTmp._Mask.push_back (true);
225 zbeTmp._Mask.push_back (false);
226 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(), zbeTmp));
227 debugSaveInit (zbeTmp, sPath + "Zone006.ligozone");
228 zbeTmp._CategoriesMap.clear ();
229 zbeTmp._Mask.clear ();
230 _ElementsMap.clear ();
232 zbeTmp.addCategory ("zone", "Zone007");
233 zbeTmp.addCategory ("size", "1x1");
234 zbeTmp.addCategory ("material", "grozFleur");
235 zbeTmp._Mask.push_back (true);
236 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(), zbeTmp));
237 debugSaveInit (zbeTmp, sPath + "Zone007.ligozone");
238 zbeTmp._CategoriesMap.clear ();
239 zbeTmp._Mask.clear ();
240 _ElementsMap.clear ();
242 zbeTmp.addCategory ("zone", "Zone008");
243 zbeTmp.addCategory ("size", "2x2");
244 zbeTmp.addCategory ("material", "prairie");
245 zbeTmp._Mask.push_back (true);
246 zbeTmp._Mask.push_back (true);
247 zbeTmp._Mask.push_back (true);
248 zbeTmp._Mask.push_back (true);
249 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(), zbeTmp));
250 debugSaveInit (zbeTmp, sPath + "Zone008.ligozone");
251 zbeTmp._CategoriesMap.clear ();
252 zbeTmp._Mask.clear ();
253 _ElementsMap.clear ();
255 zbeTmp.addCategory ("zone", "Zone009");
256 zbeTmp.addCategory ("size", "2x2");
257 zbeTmp.addCategory ("material", "prairie");
258 zbeTmp._Mask.push_back (true);
259 zbeTmp._Mask.push_back (true);
260 zbeTmp._Mask.push_back (true);
261 zbeTmp._Mask.push_back (true);
262 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(), zbeTmp));
263 debugSaveInit (zbeTmp, sPath + "Zone009.ligozone");
264 zbeTmp._CategoriesMap.clear ();
265 zbeTmp._Mask.clear ();
266 _ElementsMap.clear ();
268 zbeTmp.addCategory ("zone", "Zone010");
269 zbeTmp.addCategory ("size", "1x1");
270 zbeTmp.addCategory ("material", "prairie");
271 zbeTmp._Mask.push_back (true);
272 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(), zbeTmp));
273 debugSaveInit (zbeTmp, sPath + "Zone010.ligozone");
274 zbeTmp._CategoriesMap.clear ();
275 zbeTmp._Mask.clear ();
276 _ElementsMap.clear ();
278 zbeTmp.addCategory ("zone", "WT0");
279 zbeTmp.addCategory ("size", "1x1");
280 zbeTmp.addCategory ("transname", "grozFleur-prairie");
281 zbeTmp.addCategory ("transtype", "Flat");
282 zbeTmp.addCategory ("transnum", "0");
283 zbeTmp._Mask.push_back (true);
284 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(), zbeTmp));
285 debugSaveInit (zbeTmp, sPath + "WT0.ligozone");
286 zbeTmp._CategoriesMap.clear ();
287 zbeTmp._Mask.clear ();
288 _ElementsMap.clear ();
290 zbeTmp.addCategory ("zone", "WT1");
291 zbeTmp.addCategory ("size", "1x1");
292 zbeTmp.addCategory ("transname", "grozFleur-prairie");
293 zbeTmp.addCategory ("transtype", "Flat");
294 zbeTmp.addCategory ("transnum", "1");
295 zbeTmp._Mask.push_back (true);
296 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(), zbeTmp));
297 debugSaveInit (zbeTmp, sPath + "WT1.ligozone");
298 zbeTmp._CategoriesMap.clear ();
299 zbeTmp._Mask.clear ();
300 _ElementsMap.clear ();
302 zbeTmp.addCategory ("zone", "WT2");
303 zbeTmp.addCategory ("size", "1x1");
304 zbeTmp.addCategory ("transname", "grozFleur-prairie");
305 zbeTmp.addCategory ("transtype", "Flat");
306 zbeTmp.addCategory ("transnum", "2");
307 zbeTmp._Mask.push_back (true);
308 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(), zbeTmp));
309 debugSaveInit (zbeTmp, sPath + "WT2.ligozone");
310 zbeTmp._CategoriesMap.clear ();
311 zbeTmp._Mask.clear ();
312 _ElementsMap.clear ();
314 zbeTmp.addCategory ("zone", "WT3");
315 zbeTmp.addCategory ("size", "1x1");
316 zbeTmp.addCategory ("transname", "grozFleur-prairie");
317 zbeTmp.addCategory ("transtype", "CornerA");
318 zbeTmp.addCategory ("transnum", "3");
319 zbeTmp._Mask.push_back (true);
320 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(), zbeTmp));
321 debugSaveInit (zbeTmp, sPath + "WT3.ligozone");
322 zbeTmp._CategoriesMap.clear ();
323 zbeTmp._Mask.clear ();
324 _ElementsMap.clear ();
326 zbeTmp.addCategory ("zone", "WT4");
327 zbeTmp.addCategory ("size", "1x1");
328 zbeTmp.addCategory ("transname", "grozFleur-prairie");
329 zbeTmp.addCategory ("transtype", "CornerA");
330 zbeTmp.addCategory ("transnum", "4");
331 zbeTmp._Mask.push_back (true);
332 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(), zbeTmp));
333 debugSaveInit (zbeTmp, sPath + "WT4.ligozone");
334 zbeTmp._CategoriesMap.clear ();
335 zbeTmp._Mask.clear ();
336 _ElementsMap.clear ();
338 zbeTmp.addCategory ("zone", "WT5");
339 zbeTmp.addCategory ("size", "1x1");
340 zbeTmp.addCategory ("transname", "grozFleur-prairie");
341 zbeTmp.addCategory ("transtype", "CornerA");
342 zbeTmp.addCategory ("transnum", "5");
343 zbeTmp._Mask.push_back (true);
344 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(), zbeTmp));
345 debugSaveInit (zbeTmp, sPath + "WT5.ligozone");
346 zbeTmp._CategoriesMap.clear ();
347 zbeTmp._Mask.clear ();
348 _ElementsMap.clear ();
350 zbeTmp.addCategory ("zone", "WT6");
351 zbeTmp.addCategory ("size", "1x1");
352 zbeTmp.addCategory ("transname", "grozFleur-prairie");
353 zbeTmp.addCategory ("transtype", "CornerB");
354 zbeTmp.addCategory ("transnum", "6");
355 zbeTmp._Mask.push_back (true);
356 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(), zbeTmp));
357 debugSaveInit (zbeTmp, sPath + "WT6.ligozone");
358 zbeTmp._CategoriesMap.clear ();
359 zbeTmp._Mask.clear ();
360 _ElementsMap.clear ();
362 zbeTmp.addCategory ("zone", "WT7");
363 zbeTmp.addCategory ("size", "1x1");
364 zbeTmp.addCategory ("transname", "grozFleur-prairie");
365 zbeTmp.addCategory ("transtype", "CornerB");
366 zbeTmp.addCategory ("transnum", "7");
367 zbeTmp._Mask.push_back (true);
368 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(), zbeTmp));
369 debugSaveInit (zbeTmp, sPath + "WT7.ligozone");
370 zbeTmp._CategoriesMap.clear ();
371 zbeTmp._Mask.clear ();
372 _ElementsMap.clear ();
374 zbeTmp.addCategory ("zone", "WT8");
375 zbeTmp.addCategory ("size", "1x1");
376 zbeTmp.addCategory ("transname", "grozFleur-prairie");
377 zbeTmp.addCategory ("transtype", "CornerB");
378 zbeTmp.addCategory ("transnum", "8");
379 zbeTmp._Mask.push_back (true);
380 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(), zbeTmp));
381 debugSaveInit (zbeTmp, sPath + "WT8.ligozone");
382 zbeTmp._CategoriesMap.clear ();
383 zbeTmp._Mask.clear ();
384 _ElementsMap.clear ();
386 zbeTmp.addCategory ("zone", "ZT0");
387 zbeTmp.addCategory ("size", "1x1");
388 zbeTmp.addCategory ("transname", "titFleur-grozFleur");
389 zbeTmp.addCategory ("transtype", "Flat");
390 zbeTmp.addCategory ("transnum", "0");
391 zbeTmp._Mask.push_back (true);
392 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(), zbeTmp));
393 debugSaveInit (zbeTmp, sPath + "ZT0.ligozone");
394 zbeTmp._CategoriesMap.clear ();
395 zbeTmp._Mask.clear ();
396 _ElementsMap.clear ();
398 zbeTmp.addCategory ("zone", "ZT1");
399 zbeTmp.addCategory ("size", "1x1");
400 zbeTmp.addCategory ("transname", "titFleur-grozFleur");
401 zbeTmp.addCategory ("transtype", "Flat");
402 zbeTmp.addCategory ("transnum", "1");
403 zbeTmp._Mask.push_back (true);
404 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(), zbeTmp));
405 debugSaveInit (zbeTmp, sPath + "ZT1.ligozone");
406 zbeTmp._CategoriesMap.clear ();
407 zbeTmp._Mask.clear ();
408 _ElementsMap.clear ();
410 zbeTmp.addCategory ("zone", "ZT2");
411 zbeTmp.addCategory ("size", "1x1");
412 zbeTmp.addCategory ("transname", "titFleur-grozFleur");
413 zbeTmp.addCategory ("transtype", "Flat");
414 zbeTmp.addCategory ("transnum", "2");
415 zbeTmp._Mask.push_back (true);
416 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(), zbeTmp));
417 debugSaveInit (zbeTmp, sPath + "ZT2.ligozone");
418 zbeTmp._CategoriesMap.clear ();
419 zbeTmp._Mask.clear ();
420 _ElementsMap.clear ();
422 zbeTmp.addCategory ("zone", "ZT3");
423 zbeTmp.addCategory ("size", "1x1");
424 zbeTmp.addCategory ("transname", "titFleur-grozFleur");
425 zbeTmp.addCategory ("transtype", "CornerA");
426 zbeTmp.addCategory ("transnum", "3");
427 zbeTmp._Mask.push_back (true);
428 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(), zbeTmp));
429 debugSaveInit (zbeTmp, sPath + "ZT3.ligozone");
430 zbeTmp._CategoriesMap.clear ();
431 zbeTmp._Mask.clear ();
432 _ElementsMap.clear ();
434 zbeTmp.addCategory ("zone", "ZT4");
435 zbeTmp.addCategory ("size", "1x1");
436 zbeTmp.addCategory ("transname", "titFleur-grozFleur");
437 zbeTmp.addCategory ("transtype", "CornerA");
438 zbeTmp.addCategory ("transnum", "4");
439 zbeTmp._Mask.push_back (true);
440 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(), zbeTmp));
441 debugSaveInit (zbeTmp, sPath + "ZT4.ligozone");
442 zbeTmp._CategoriesMap.clear ();
443 zbeTmp._Mask.clear ();
444 _ElementsMap.clear ();
446 zbeTmp.addCategory ("zone", "ZT5");
447 zbeTmp.addCategory ("size", "1x1");
448 zbeTmp.addCategory ("transname", "titFleur-grozFleur");
449 zbeTmp.addCategory ("transtype", "CornerA");
450 zbeTmp.addCategory ("transnum", "5");
451 zbeTmp._Mask.push_back (true);
452 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(), zbeTmp));
453 debugSaveInit (zbeTmp, sPath + "ZT5.ligozone");
454 zbeTmp._CategoriesMap.clear ();
455 zbeTmp._Mask.clear ();
456 _ElementsMap.clear ();
458 zbeTmp.addCategory ("zone", "ZT6");
459 zbeTmp.addCategory ("size", "1x1");
460 zbeTmp.addCategory ("transname", "titFleur-grozFleur");
461 zbeTmp.addCategory ("transtype", "CornerB");
462 zbeTmp.addCategory ("transnum", "6");
463 zbeTmp._Mask.push_back (true);
464 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(), zbeTmp));
465 debugSaveInit (zbeTmp, sPath + "ZT6.ligozone");
466 zbeTmp._CategoriesMap.clear ();
467 zbeTmp._Mask.clear ();
468 _ElementsMap.clear ();
470 zbeTmp.addCategory ("zone", "ZT7");
471 zbeTmp.addCategory ("size", "1x1");
472 zbeTmp.addCategory ("transname", "titFleur-grozFleur");
473 zbeTmp.addCategory ("transtype", "CornerB");
474 zbeTmp.addCategory ("transnum", "7");
475 zbeTmp._Mask.push_back (true);
476 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(), zbeTmp));
477 debugSaveInit (zbeTmp, sPath + "ZT7.ligozone");
478 zbeTmp._CategoriesMap.clear ();
479 zbeTmp._Mask.clear ();
480 _ElementsMap.clear ();
482 zbeTmp.addCategory ("zone", "ZT8");
483 zbeTmp.addCategory ("size", "1x1");
484 zbeTmp.addCategory ("transname", "titFleur-grozFleur");
485 zbeTmp.addCategory ("transtype", "CornerB");
486 zbeTmp.addCategory ("transnum", "8");
487 zbeTmp._Mask.push_back (true);
488 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(), zbeTmp));
489 debugSaveInit (zbeTmp, sPath + "ZT8.ligozone");
490 zbeTmp._CategoriesMap.clear ();
491 zbeTmp._Mask.clear ();
492 _ElementsMap.clear ();
496 // ---------------------------------------------------------------------------
497 void CZoneBank::reset ()
499 _ElementsMap.clear ();
500 _Selection.clear ();
503 // ---------------------------------------------------------------------------
504 bool CZoneBank::initFromPath(const std::string &sPathName, std::string &error)
506 std::vector<std::string> files;
507 NLMISC::CPath::getPathContent(sPathName, false, false, true, files);
509 for (uint i = 0, len = files.size(); i < len; ++i)
511 std::string ext = NLMISC::CFile::getExtension(files[i]);
513 if (ext == "ligozone")
515 if (!addElement(files[i], error))
516 return false;
520 return true;
523 // ---------------------------------------------------------------------------
524 bool CZoneBank::addElement (const std::string &elementName, std::string &error)
528 CZoneBankElement zbeTmp;
529 CIFile fileIn;
530 if (fileIn.open (elementName))
532 CIXml input;
533 input.init (fileIn);
534 zbeTmp.serial (input);
535 _ElementsMap.insert (pair<string,CZoneBankElement>(zbeTmp.getName(),zbeTmp));
536 return true;
538 else
540 error = "Can't open file " + elementName;
543 catch (const Exception& e)
545 error = "Error while loading ligozone "+elementName+" : "+e.what();
547 return false;
550 // ---------------------------------------------------------------------------
551 void CZoneBank::getCategoriesType (std::vector<std::string> &CategoriesType)
553 map<string,CZoneBankElement>::iterator itElt = _ElementsMap.begin();
555 while (itElt != _ElementsMap.end())
557 CZoneBankElement &rZBE = itElt->second;
559 map<string,string>::iterator it = rZBE._CategoriesMap.begin();
561 while (it != rZBE._CategoriesMap.end())
563 bool bFound = false;
564 for (uint32 k = 0; k < CategoriesType.size(); ++k)
565 if (it->first == CategoriesType[k])
567 bFound = true;
568 break;
570 if (!bFound)
571 CategoriesType.push_back (it->first);
573 ++it;
575 ++itElt;
579 // ---------------------------------------------------------------------------
580 void CZoneBank::getCategoryValues (const std::string &CategoryType, std::vector<std::string> &CategoryValues)
582 map<string,CZoneBankElement>::iterator itElt = _ElementsMap.begin();
584 while (itElt != _ElementsMap.end())
586 CZoneBankElement &rZBE = itElt->second;
588 map<string,string>::iterator it = rZBE._CategoriesMap.find (CategoryType);
590 if (it != rZBE._CategoriesMap.end())
592 bool bFound = false;
593 for (uint32 k = 0; k < CategoryValues.size(); ++k )
594 if (it->second == CategoryValues[k])
596 bFound = true;
597 break;
599 if (!bFound)
600 CategoryValues.push_back (it->second);
602 ++itElt;
606 // ---------------------------------------------------------------------------
607 CZoneBankElement *CZoneBank::getElementByZoneName (const std::string &ZoneName)
609 map<string,CZoneBankElement>::iterator it = _ElementsMap.find (ZoneName);
610 if (it != _ElementsMap.end())
612 return &(it->second);
614 return NULL;
617 // ---------------------------------------------------------------------------
618 void CZoneBank::resetSelection ()
620 _Selection.clear ();
623 // ---------------------------------------------------------------------------
624 void CZoneBank::addOrSwitch (const std::string &CategoryType, const std::string &CategoryValue)
626 map<string,CZoneBankElement>::iterator itElt = _ElementsMap.begin();
628 while (itElt != _ElementsMap.end())
630 CZoneBankElement &rZBE = itElt->second;
632 map<string,string>::iterator it = rZBE._CategoriesMap.find (CategoryType);
634 if (it != rZBE._CategoriesMap.end())
636 if (it->second == CategoryValue)
638 // Check if the element is not already present in the selection
639 bool bFound = false;
640 for (uint32 k = 0; k < _Selection.size(); ++k )
641 if (&rZBE == _Selection[k])
643 bFound = true;
644 break;
646 if (!bFound)
647 _Selection.push_back (&rZBE);
650 ++itElt;
654 // ---------------------------------------------------------------------------
655 void CZoneBank::addAndSwitch (const std::string &CategoryType, const std::string &CategoryValue)
657 uint32 i, j;
658 // And the selection with some constraints
659 // All elements of the selection must have a catType and catValue equal to those given in parameters
660 for (i = 0; i < _Selection.size(); ++i)
662 CZoneBankElement *pZBE = _Selection[i];
663 bool bFound = false;
665 map<string,string>::iterator it = pZBE->_CategoriesMap.find (CategoryType);
666 if (it != pZBE->_CategoriesMap.end())
668 if (it->second == CategoryValue)
669 bFound = true;
671 if (!bFound)
673 _Selection[i] = NULL; // Mark this item to be removed
676 // Remove all unused items
677 for (i = 0, j = 0; i < _Selection.size(); ++i)
679 if (_Selection[i] != NULL)
681 _Selection[j] = _Selection[i];
682 ++j;
685 _Selection.resize (j);
688 // ---------------------------------------------------------------------------
689 void CZoneBank::getSelection (std::vector<CZoneBankElement*> &SelectedElements)
691 SelectedElements = _Selection;
694 // ***************************************************************************
696 } // namespace NLLIGO