KSquare Utilities
XmlStream.cpp
Go to the documentation of this file.
1 /* XmlStream.cpp -- Class to XML Objects; still in development.
2  * Copyright (C) 1994-2011 Kurt Kramer
3  * For conditions of distribution and use, see copyright notice in KKB.h
4  */
5 #include "FirstIncludes.h"
6 #include <stdio.h>
7 #include <fstream>
8 #include <string.h>
9 #include <string>
10 #include <iostream>
11 #include <ostream>
12 #include <vector>
13 #include "MemoryDebug.h"
14 using namespace std;
15 
16 
17 #include "BitString.h"
18 #include "GlobalGoalKeeper.h"
19 #include "KKBaseTypes.h"
20 #include "KKException.h"
21 #include "KKStrParser.h"
22 #include "XmlTokenizer.h"
23 #include "XmlStream.h"
24 using namespace KKB;
25 
26 
27 
28 
30  endOfElementTagNames (),
31  endOfElemenReached (false),
32  fileName (),
33  nameOfLastEndTag (),
34  tokenStream (_tokenStream),
35  weOwnTokenStream (false)
36 {
37 }
38 
39 
40 
41 XmlStream::XmlStream (const KKStr& _fileName, RunLog& _log):
42  endOfElementTagNames (),
43  endOfElemenReached (false),
44  fileName (_fileName),
45  nameOfLastEndTag (),
46  tokenStream (NULL),
47  weOwnTokenStream (false)
48 {
49  bool fileOpened = false;
50  tokenStream = new XmlTokenizer (fileName, fileOpened);
51  weOwnTokenStream = true;
52 }
53 
54 
55 
57 {
58  delete tokenStream;
59  tokenStream = NULL;
60 }
61 
62 
63 
64 /**
65  *@brief Registers a Factory at the current hierarchy that is being processed.
66  */
68 {
69  if (factoryManagers.size () > 0)
70  factoryManagers.back ()->RegisterFactory (factory);
71  else
72  XmlFactory::RegisterFactory (factory);
73 
74 } /* RegisterFactory */
75 
76 
77 
78 void XmlStream::PushXmlElementLevel (const KKStr& sectionName)
79 {
80  endOfElementTagNames.push_back (sectionName);
81  factoryManagers.push_back (new XmlFactoryManager (sectionName));
82 } /* PushNewXmlElementLevel */
83 
84 
85 
86 void XmlStream::PopXmlElementLevel ()
87 {
88  if ((endOfElementTagNames.size () < 1) || (factoryManagers.size () < 1))
89  return;
90 
91  endOfElementTagNames.pop_back ();
92  XmlFactoryManagerPtr fm = factoryManagers.back ();
93  factoryManagers.pop_back ();
94  delete fm;
95  fm = NULL;
96 }
97 
98 
99 XmlFactoryPtr XmlStream::TrackDownFactory (const KKStr& sectionName)
100 {
101  XmlFactory* result = NULL;
102  kkuint32 level = factoryManagers.size ();
103  while ((level > 0) && (result == NULL))
104  {
105  --level;
106  result = factoryManagers[level]->FactoryLookUp (sectionName);
107  }
108 
109  if (result == NULL)
110  result = XmlFactory::FactoryLookUp (sectionName);
111  return result;
112 }
113 
114 
115 
117  RunLog& log
118  )
119 {
120  if (endOfElemenReached || cancelFlag)
121  return NULL;
122 
123  XmlTokenPtr token = NULL;
124 
125  KKStrPtr t = tokenStream->GetNextToken ();
126  if (t == NULL)
127  return NULL;
128 
129  if (t->FirstChar () == '<')
130  {
131  XmlTagPtr tag = new XmlTag (t);
132  delete t;
133  t = NULL;
135  {
136  XmlFactoryPtr factory = TrackDownFactory (tag->Name ());
137  if (!factory)
139  else
140  int zed =100;
141  log.Level (50) << "XmlStream::GetNextToken Factory Selected: " << factory->ClassName () << endl;
142 
143  PushXmlElementLevel (tag->Name ());
144  token = factory->ManufatureXmlElement (tag, *this, cancelFlag, log);
145  KKStr endTagName = endOfElementTagNames.back ();
146  PopXmlElementLevel ();
147  endOfElemenReached = false;
148  }
149 
150  else if (tag->TagType () == XmlTag::TagTypes::tagEmpty)
151  {
153  if (!factory)
155  PushXmlElementLevel (tag->Name ());
156  endOfElemenReached = true;
157  token = factory->ManufatureXmlElement (tag, *this, cancelFlag, log);
158  if ((!endOfElemenReached) && (tag->TagType () == XmlTag::TagTypes::tagStart))
159  {
160  // The element that we just read did not finish consuming all its components.
161  log.Level (-1) << "XmlStream::GetNextToken ***WARNING*** The element just read[" << tag->Name () << "] Did not consume all its elements." << endl;
162  XmlTokenPtr t = GetNextToken (cancelFlag, log);
163  while (t)
164  {
165  delete t;
166  t = GetNextToken (cancelFlag, log);
167  }
168  }
169  endOfElemenReached = false;
170  PopXmlElementLevel ();
171  }
172 
173  else if (tag->TagType () == XmlTag::TagTypes::tagEnd)
174  {
175  if (endOfElementTagNames.size () < 1)
176  {
177  // end tag with no matching start tag.
178  log.Level (-1) << endl
179  << "XmlStream::GetNextToken ***ERROR*** Encountered end-tag </" << tag->Name () << "> with no matching start-tag." << endl
180  << endl;
181  }
182  else
183  {
184  endOfElemenReached = true;
185  nameOfLastEndTag = tag->Name ();
186  if (!endOfElementTagNames.back ().EqualIgnoreCase (nameOfLastEndTag))
187  {
188  log.Level (-1) << endl
189  << "XmlStream::GetNextToken ***ERROR*** Encountered end-tag </" << nameOfLastEndTag << "> does not match StartTag <" << endOfElementTagNames.back () << ">." << endl
190  << endl;
191  // </End-Tag> does not match <Start-Tag> we will put back on token stream assuming that we are missing a </End-Tag>
192  // We will end the current element here.
193  tokenStream->PushTokenOnFront (new KKStr ("<" + tag->Name () + " />"));
194  }
195  }
196  delete tag;
197  tag = NULL;
198  }
199  }
200  else
201  {
202  token = new XmlContent (t);
203  }
204  return token;
205 } /* GetNextToken */
206 
207 
208 
209 
211 {
212  if (!tokenStream)
213  return NULL;
214 
215  KKStrConstPtr peekNext = tokenStream->Peek (0);
216  if (!peekNext)
217  return NULL;
218 
219  if (peekNext->FirstChar () == '<')
220  return NULL;
221 
222  else
223  {
224  KKStrPtr ts = tokenStream->GetNextToken ();
225  if (ts)
226  return new XmlContent (ts);
227  else
228  return NULL;
229  }
230 }
231 
232 
233 
234 
237 {
238 }
239 
240 
242 {
243  XmlAttributeList::const_iterator idx;
244  for (idx = attributes.begin (); idx != attributes.end (); ++idx)
245  PushOnBack (*idx);
246 }
247 
248 
249 
251 {
252  KKQueue<XmlAttribute>::PushOnBack (a);
253  nameIndex.insert (NameIndexPair (a->Name (), a));
254 }
255 
256 
258 {
259  KKQueue<XmlAttribute>::PushOnFront (a);
260  nameIndex.insert (NameIndexPair (a->Name (), a));
261 }
262 
263 
265 {
266  XmlAttributePtr a = KKQueue<XmlAttribute>::PopFromBack ();
267  if (a)
268  DeleteFromNameIndex (a);
269  return a;
270 }
271 
272 
274 {
275  XmlAttributePtr a = KKQueue<XmlAttribute>::PopFromFront ();
276  if (a)
277  DeleteFromNameIndex (a);
278  return a;
279 }
280 
281 
282 
283 void XmlAttributeList::DeleteFromNameIndex (XmlAttributePtr a)
284 {
285  {
286  NameIndex::iterator idx;
287  idx = nameIndex.find (a->Name ());
288  while ((idx != nameIndex.end ()) &&
289  (idx->first == a->Name ()) &&
290  (idx->second != a)
291  )
292  ++idx;
293 
294  if ((idx != nameIndex.end ()) && (idx->second == a))
295  nameIndex.erase (idx);
296  }
297 }
298 
299 
300 
301 KKStrConstPtr XmlAttributeList::AttributeValueByName (const KKStr& name) const
302 {
304  if (a)
305  return &(a->Value ());
306  else
307  return NULL;
308 }
309 
310 
311 KKStrConstPtr XmlAttributeList::AttributeValueByIndex (kkuint32 index) const
312 {
313  if (index >= size ())
314  return NULL;
315  else
316  return &(at (index)->Value ());
317 }
318 
319 
320 KKStrConstPtr XmlAttributeList::AttributeNameByIndex (kkuint32 index) const
321 {
322  if (index >= size ())
323  return NULL;
324  else
325  return &(at (index)->Name ());
326 }
327 
328 
329 
330 const KKStr& XmlAttributeList::AttributeValueKKStr (const KKStr& name) const
331 {
332  KKStrConstPtr s = AttributeValueByName (name);
333  if (s)
334  return *s;
335  else
336  return KKStr::EmptyStr ();
337 }
338 
339 
340 
342 {
343  KKStrConstPtr s = AttributeValueByName (name);
344  if (!s)
345  return 0;
346  else
347  return s->ToInt32 ();
348 }
349 
350 
351 
353 {
354  KKStrConstPtr s = AttributeValueByName (name);
355  if (!s)
356  return DateTime ();
357 
358  DateTime dt (*s);
359  return dt;
360 }
361 
362 
363 
364 
365 
367  const KKStr& value
368  )
369 {
370  PushOnBack (new XmlAttribute (name, value));
371 }
372 
373 
374 
376 {
377  NameIndex::const_iterator idx;
378  idx = nameIndex.find (name);
379  if (idx == nameIndex.end ())
380  return NULL;
381 
382  if (idx->first != name)
383  return NULL;
384 
385  return idx->second;
386 }
387 
388 
389 
390 void ReadWholeTag (istream& i,
391  KKStr& tagStr
392  )
393 {
394  tagStr = "";
395  while (!i.eof ())
396  {
397  char nextCh = i.get ();
398  if (nextCh != 0)
399  tagStr.Append (nextCh);
400  if (nextCh == '>')
401  break;
402  }
403 
404  return;
405 } /* ReadWholeTag */
406 
407 
408 
409 
410 
411 
412 void ExtractAttribute (KKStr& tagStr,
413  KKStr& attributeName,
414  KKStr& attributeValue
415  )
416 {
417  kkint32 startIdx = 0;
418  kkint32 len = tagStr.Len ();
419  attributeName = "";
420  attributeValue = "";
421 
422  // Skip over leading spaces
423  while (startIdx < len)
424  {
425  if (strchr ("\n\t\r ", tagStr[startIdx]) == NULL)
426  break;
427  startIdx++;
428  }
429 
430  if (startIdx >= len)
431  {
432  tagStr = "";
433  return;
434  }
435 
436  kkint32 idx = startIdx;
437 
438  // Skip until we find the '=' character.
439  while (idx < len)
440  {
441  if (tagStr[idx] == '=')
442  break;
443  ++idx;
444  }
445 
446  if (idx >= len)
447  {
448  tagStr = "";
449  return;
450  }
451 
452  attributeName = tagStr.SubStrPart (startIdx, idx - 1);
453 
454  ++idx; // Skip past '=' character.
455 
456  // Skip over leading spaces
457  while (idx < len)
458  {
459  if (strchr ("\n\t\r ", tagStr[idx]) == NULL)
460  break;
461  ++idx;
462  }
463 
464  if (idx >= len)
465  {
466  tagStr = "";
467  return;
468  }
469 
470  int valueStartIdx = idx;
471 
472  while (idx < len)
473  {
474  if (strchr ("\n\t\r ", tagStr[idx]) != NULL)
475  break;
476  ++idx;
477  }
478 
479  attributeValue = tagStr.SubStrPart (valueStartIdx, idx - 1);
480 
481  tagStr = tagStr.SubStrPart (idx + 1);
482 
483  return;
484 } /* ExtractAttribute */
485 
486 
487 
488 XmlTag::XmlTag (istream& i):
489  attributes (true),
490  name (),
491  tagType (TagTypes::tagNULL)
492 {
493  tagType = TagTypes::tagNULL;
494 
495  if (i.peek () == '<')
496  i.get ();
497 
498  KKStr tagStr (100);
499  ReadWholeTag (i, tagStr);
500 
501  if (tagStr.FirstChar () == '/')
502  {
503  tagStr.ChopFirstChar ();
504  tagType = TagTypes::tagEnd;
505  }
506 
507  if (tagStr.EndsWith ("/>"))
508  {
509  tagType = TagTypes::tagEmpty;
510  tagStr.ChopLastChar ();
511  tagStr.ChopLastChar ();
512  }
513 
514  else if (tagStr.LastChar () != '>')
515  {
516  tagType = TagTypes::tagStart;
517  }
518 
519  else
520  {
521  if (tagType == TagTypes::tagNULL)
522  tagType = TagTypes::tagStart;
523  tagStr.ChopLastChar ();
524  }
525 
526  name.TrimLeft ();
527  name.TrimRight ();
528 
529  name = tagStr.ExtractToken2 (" \n\r\t");
530  KKStr attributeName (20);
531  KKStr attributeValue (20);
532 
533  while (!tagStr.Empty ())
534  {
535  ExtractAttribute (tagStr, attributeName, attributeValue);
536  if (!attributeName.Empty ())
537  attributes.AddAttribute (attributeName, attributeValue);
538  }
539 }
540 
541 
542 
543 XmlTag::XmlTag (const KKStrConstPtr tagStr):
544  attributes (true),
545  name (),
546  tagType (TagTypes::tagNULL)
547 {
548  KKStrParser parser(*tagStr);
549  parser.TrimWhiteSpace (" ");
550 
551  if (parser.PeekNextChar () == '<')
552  parser.GetNextChar ();
553 
554  if (parser.PeekLastChar () == '>')
555  parser.GetLastChar ();
556 
557  if (parser.PeekNextChar () == '/')
558  {
559  parser.GetNextChar ();
560  tagType = XmlTag::TagTypes::tagEnd;
561  }
562  else if (parser.PeekLastChar () == '/')
563  {
564  parser.GetLastChar ();
565  tagType = XmlTag::TagTypes::tagEmpty;
566  }
567  else
568  {
569  tagType = XmlTag::TagTypes::tagStart;
570  }
571 
572  name = parser.GetNextToken ();
573  parser.SkipWhiteSpace ();
574 
575  while (parser.MoreTokens ())
576  {
577  KKStr attributeName = parser.GetNextToken ("=");
578  KKStr attributeValue = parser.GetNextToken (" \t\n\r");
579  attributes.AddAttribute (attributeName, attributeValue);
580  }
581 } /* XmlTag::XmlTag (const KKStrConstPtr tagStr) */
582 
583 
584 
585 
586 XmlTag::XmlTag (const KKStr& _name,
587  TagTypes _tagType
588  ):
589  attributes (true),
590  name (_name),
591  tagType (_tagType)
592 {
593 }
594 
595 
597 {
598 }
599 
600 
601 
602 void XmlTag::AddAtribute (const KKStr& attributeName,
603  const KKStr& attributeValue
604  )
605 {
606  attributes.AddAttribute (attributeName, attributeValue);
607 }
608 
609 
610 
611 void XmlTag::AddAtribute (const KKStr& attributeName,
612  bool attributeValue
613  )
614 {
615  attributes.AddAttribute (attributeName, (attributeValue ? "Yes" : "No"));
616 }
617 
618 
619 
620 void XmlTag::AddAtribute (const KKStr& attributeName,
621  kkint32 attributeValue
622  )
623 {
624  attributes.AddAttribute (attributeName, StrFromInt32 (attributeValue));
625 }
626 
627 
628 
629 void XmlTag::AddAtribute (const KKStr& attributeName,
630  kkint64 attributeValue
631  )
632 {
633  attributes.AddAttribute (attributeName, StrFromInt64 (attributeValue));
634 }
635 
636 
637 
638 void XmlTag::AddAtribute (const KKStr& attributeName,
639  double attributeValue
640  )
641 {
642  KKStr s (20);
643  s << attributeValue;
644  attributes.AddAttribute (attributeName, s);
645 }
646 
647 
648 
649 void XmlTag::AddAtribute (const KKStr& attributeName,
650  const DateTime& attributeValue
651  )
652 {
653  attributes.AddAttribute (attributeName, attributeValue.YYYY_MM_DD_HH_MM_SS ());
654 }
655 
656 
657 
658 KKStrConstPtr XmlTag::AttributeValueByName (const KKStr& name) const
659 {
660  return attributes.AttributeValueByName (name);
661 }
662 
663 
664 KKStrConstPtr XmlTag::AttributeValueByIndex (kkuint32 index) const
665 {
666  return attributes.AttributeValueByIndex (index);
667 }
668 
669 
670 KKStrConstPtr XmlTag::AttributeNameByIndex (kkuint32 index) const
671 {
672  return attributes.AttributeNameByIndex (index);
673 }
674 
675 
676 kkint32 XmlTag::AttributeValueInt32 (const KKStr& attributeName) const
677 {
678  return this->attributes.AttributeValueInt32 (attributeName);
679 }
680 
681 
682 DateTime XmlTag::AttributeValueDateTime (const KKStr& attributeName) const
683 {
684  return this->attributes.AttributeValueDateTime (attributeName);
685 }
686 
687 
688 const KKStr& XmlTag::AttributeValueKKStr (const KKStr& attributeName) const
689 {
690  return attributes.AttributeValueKKStr (attributeName);
691 }
692 
693 
695 {
696  KKStr s (name.Len () + attributes.size () * 30);
697  s << "<";
698 
699  if (tagType == TagTypes::tagEnd)
700  s << "/";
701 
702  s << name;
703 
704  XmlAttributeList::const_iterator idx;
705  for (idx = attributes.begin(); idx != attributes.end (); ++idx)
706  {
707  XmlAttributePtr a = *idx;
708  s << " " << a->Name () << "=" << a->Value ().QuotedStr ();
709  }
710 
711  if (tagType == TagTypes::tagEmpty)
712  s << "/";
713 
714  s << ">";
715 
716  return s;
717 }
718 
719 
721 
722 
723 void XmlTag::WriteXML (std::ostream& o)
724 {
725  if (TagType () == TagTypes::tagEnd)
726  --xmlLevel;
727 
728  for (kkint32 x = 0; x < xmlLevel; ++x)
729  o << " ";
730  o << ToString ();
731 
732  if (this->TagType () == TagTypes::tagStart)
733  ++xmlLevel;
734 } /* WriteXML */
735 
736 
737 
738 
739 
741 {
742 }
743 
744 
746 {
747 }
748 
749 
750 XmlElement::XmlElement (const KKStr& sectionName,
751  XmlTag::TagTypes tagType
752  ):
753  nameTag (new XmlTag (sectionName, tagType))
754 {}
755 
756 
757 
759  XmlStream& s,
760  RunLog& log
761  ):
762  nameTag (_nameTag)
763 {}
764 
765 
766 
768 {
769  delete nameTag;
770  nameTag = NULL;
771 }
772 
773 
774 
776 {
777  if (!nameTag)
778  return KKStr::EmptyStr ();
779  else
780  return nameTag->ToString ();
781 }
782 
783 
784 
785 const KKStr& XmlElement::SectionName () const
786 {
787  if (nameTag)
788  return nameTag->Name ();
789  else
790  return KKStr::EmptyStr ();
791 }
792 
793 
794 const KKStr& XmlElement::VarName () const
795 {
796  if (!nameTag)
797  return KKStr::EmptyStr ();
798 
799  KKStrConstPtr nameStr = nameTag->AttributeValueByName ("VarName");
800  if (nameStr)
801  return *nameStr;
802  else
803  return KKStr::EmptyStr ();
804 }
805 
806 
807 
808 
809 KKStrConstPtr XmlElement::AttributeValue (const KKStr& attributeName)
810 {
811  if (nameTag)
812  return nameTag->AttributeValueByName (attributeName);
813  else
814  return NULL;
815 }
816 
817 
818 KKStrConstPtr XmlElement::AttributeValue (const char* attributeName)
819 {
820  if (nameTag)
821  return nameTag->AttributeValueByName (attributeName);
822  else
823  return NULL;
824 }
825 
826 
827 
828 
829 XmlContent::XmlContent (KKStrPtr _content):
830  XmlToken (),
831  content (_content)
832 {
833 }
834 
835 
836 
838 {
839  delete content;
840  content = NULL;
841 }
842 
843 
844 
846 {
847  KKStrPtr c = content;
848  content = NULL;
849  return c;
850 }
851 
852 
853 void XmlContent::WriteXml (const KKStr& s,
854  std::ostream& o
855  )
856 {
857  const char* str = s.Str ();
858  kkuint32 len = s.Len ();
859 
860  for (kkuint32 x = 0; x < len; ++x)
861  {
862  char ch = str[x];
863  switch (ch)
864  {
865  case '&': o << "&amp;"; break;
866  case '<': o << "&lt;"; break;
867  case '>': o << "&gt;"; break;
868  default: o << ch; break;
869  }
870  }
871 } /* WriteXML */
872 
873 
874 
876 
877 
878 
880 {
882  if (globalXmlFactoryManager == NULL)
883  {
884  globalXmlFactoryManager = new XmlFactoryManager ("globalXmlFactoryManager");
885  atexit (FinalCleanUp);
886  }
887 
889 
891 
892  return factory;
893 } /* FactoryLookUp */
894 
895 
896 
898 {
899  if (!factory)
900  {
901  KKStr errMsg = "XmlStream::RegisterFactory ***ERROR*** (factory == NULL).";
902  cerr << endl << errMsg << endl << endl;
903  throw KKException (errMsg);
904  }
905 
907 
909  {
910  globalXmlFactoryManager = new XmlFactoryManager ("globalXmlFactoryManager");
911  atexit (FinalCleanUp);
912  }
913 
915 
917 }
918 
919 
920 
922 {
926 }
927 
928 
929 
930 
931 XmlFactory::XmlFactory (const KKStr& _clasName):
932  className (_clasName)
933 {
934 }
935 
936 
937 
938 
940  factories (),
941  name (_name)
942 {
943 }
944 
945 
947 {
948  map<KKStr, XmlFactory*>::iterator idx;
949  for (idx = factories.begin (); idx != factories.end (); ++idx)
950  {
951  XmlFactory* f = idx->second;
952  delete f;
953  }
954  factories.clear ();
955 }
956 
957 
958 
960 {
962  XmlFactory* existingFactory = FactoryLookUp (factory->ClassName ());
963  if (existingFactory)
964  {
966  KKStr errMsg (200);
967  errMsg << "XmlFactoryManager::RegisterFactory FactoryManager[" << name << "] Factory[" << factory->ClassName () << "] already exists." ;
968  cerr << endl << errMsg << endl << endl;
969  throw KKException (errMsg);
970  }
971  else
972  {
973  factories.insert (pair<KKStr, XmlFactory*> (factory->ClassName (), factory));
974  }
976 }
977 
978 
980 {
982  XmlFactory* result = NULL;
983 
984  map<KKStr, XmlFactory*>::const_iterator idx;
985  idx = factories.find (className);
986  if (idx == factories.end ())
987  result = NULL;
988  else
989  result = idx->second;
990 
992  return result;
993 } /* FactoryLookUp */
994 
995 
996 
997 
999  XmlStream& s,
1000  VolConstBool& cancelFlag,
1001  RunLog& log
1002  ):
1003  XmlElement (tag, s, log),
1004  value (false)
1005 {
1006  KKStrConstPtr valueStr = tag->AttributeValueByName ("Value");
1007  if (valueStr)
1008  value = valueStr->ToBool ();
1009  XmlTokenPtr t = s.GetNextToken (cancelFlag, log);
1010  while (t != NULL)
1011  {
1013  {
1014  XmlContentPtr c = dynamic_cast<XmlContentPtr> (t);
1015  value = c->Content ()->ToBool ();
1016  }
1017  delete t;
1018  t = s.GetNextToken (cancelFlag, log);
1019  }
1020 }
1021 
1022 
1024 {
1025 }
1026 
1027 
1028 bool XmlElementBool::Value () const
1029 {
1030  return value;
1031 }
1032 
1033 
1034 
1035 void XmlElementBool::WriteXML (const bool b,
1036  const KKStr& varName,
1037  std::ostream& o
1038  )
1039 {
1040  XmlTag startTag ("Bool", XmlTag::TagTypes::tagEmpty);
1041  if (!varName.Empty ())
1042  startTag.AddAtribute ("VarName", varName);
1043  startTag.AddAtribute ("Value", b);
1044  startTag.WriteXML (o);
1045  o << endl;
1046 }
1047 
1049 
1050 
1052  XmlStream& s,
1053  VolConstBool& cancelFlag,
1054  RunLog& log
1055  ):
1056  XmlElement (tag, s, log),
1057  value (new deque<XmlTokenPtr> ())
1058 {
1059  XmlTokenPtr t = s.GetNextToken (cancelFlag, log);
1060  while (t != NULL)
1061  {
1062  value->push_back (t);
1063  t = s.GetNextToken (cancelFlag, log);
1064  }
1065 }
1066 
1067 
1069 {
1070  if (value)
1071  {
1072  for (auto idx: *value)
1073  delete idx;
1074  delete value;
1075  value = NULL;
1076  }
1077 }
1078 
1079 
1081 {
1082  deque<XmlTokenPtr>* v = value;
1083  value = NULL;
1084  return v;
1085 }
1086 
1087 
1089 
1091 {
1092  return XmlFactoryUnKnown::FactoryInstance ();
1093 }
1094 
1095 
1097  XmlStream& s,
1098  VolConstBool& cancelFlag,
1099  RunLog& log
1100  ):
1101  XmlElement (tag, s, log),
1102  value ()
1103 {
1104  value = tag->AttributeValueDateTime ("Value");
1105 }
1106 
1107 
1109 {
1110 }
1111 
1112 
1114  const KKStr& varName,
1115  std::ostream& o
1116  )
1117 {
1118  XmlTag startTag ("DateTime", XmlTag::TagTypes::tagEmpty);
1119  if (!varName.Empty ())
1120  startTag.AddAtribute ("VarName", varName);
1121  startTag.AddAtribute ("Value", d.YYYY_MM_DD_HH_MM_SS ());
1122  startTag.WriteXML (o);
1123  o << endl;
1124 }
1125 
1126 
1128 
1129 
1130 
1131 
1132 
1133 
1135  XmlElement ("KeyValuePairs", XmlTag::TagTypes::tagStart),
1136  value (new vector<pair<KKStr,KKStr> > ())
1137 {
1138 }
1139 
1140 
1142  XmlStream& s,
1143  VolConstBool& cancelFlag,
1144  RunLog& log
1145  ):
1146  XmlElement (tag, s, log),
1147  value (NULL)
1148 {
1149  value = new vector<pair<KKStr,KKStr> > ();
1150 
1151  XmlTokenPtr t = s.GetNextToken (cancelFlag, log);
1152  while (t != NULL)
1153  {
1155  {
1156  XmlContentPtr c = dynamic_cast<XmlContentPtr> (t);
1157  if (c)
1158  {
1159  KKStrParser p (*(c->Content ()));
1160  p.TrimWhiteSpace (" ");
1161 
1162  while (p.MoreTokens ())
1163  {
1164  KKStr key = p.GetNextToken ("\t\n");
1165  if (p.LastDelimiter () == '\n')
1166  value->push_back (pair<KKStr,KKStr> (key, ""));
1167  else
1168  value->push_back (pair<KKStr,KKStr> (key, p.GetRestOfLine ()));
1169  }
1170  }
1171  }
1172  delete t;
1173  t = s.GetNextToken (cancelFlag, log);
1174  }
1175 }
1176 
1177 
1179 {
1180  delete value;
1181  value = NULL;
1182 }
1183 
1184 
1186 {
1187  vector<pair<KKStr,KKStr> >* v = value;
1188  value = NULL;
1189  return v;
1190 }
1191 
1192 
1194  const KKStr& v
1195  )
1196 {
1197  value->push_back (pair<KKStr,KKStr> (key, v));
1198 }
1199 
1200 
1201 
1202 
1204  kkint32 v
1205  )
1206 {
1208 }
1209 
1210 
1211 
1213  float v
1214  )
1215 {
1217 }
1218 
1219 
1220 
1221 
1223  double v
1224  )
1225 {
1227 }
1228 
1229 
1230 
1231 
1233  bool v
1234  )
1235 {
1236  KKStr vStr = "False";
1237  if (v) vStr = "True";
1238  Add (key, vStr);
1239 }
1240 
1241 
1242 
1244  const KKB::DateTime& v
1245  )
1246 {
1248 }
1249 
1250 
1251 
1253  ostream& o
1254  )
1255 {
1256  XmlTag startTag ("KeyValuePairs", XmlTag::TagTypes::tagStart);
1257  if (!varName.Empty ())
1258  startTag.AddAtribute ("VarName", varName);
1259  startTag.WriteXML (o);
1260  o << endl;
1261 
1262  vector<pair<KKStr,KKStr> >::const_iterator idx;
1263  for (idx = value->begin (); idx != value->end (); ++idx)
1264  {
1265  XmlContent::WriteXml (idx->first, o);
1266  o << "\t";
1267  XmlContent::WriteXml (idx->second, o);
1268  o << endl;
1269  }
1270 
1271  XmlTag endTag ("KeyValuePairs", XmlTag::TagTypes::tagEnd);
1272  endTag.WriteXML (o);
1273  o << endl;
1274 }
1275 
1276 
1277 XmlFactoryMacro(KeyValuePairs)
1278 
1279 
1280 
1281 
1282 
1284  XmlStream& s,
1285  VolConstBool& cancelFlag,
1286  RunLog& log
1287  ):
1288  XmlElement (tag, s, log),
1289  height (0),
1290  widths (NULL),
1291  value (NULL)
1292 {
1293  height = tag->AttributeValueInt32 ("Height");
1294  if (height < 1)
1295  {
1296  log.Level (-1) << endl
1297  << "XmlElementArrayFloat2DVarying ***ERROR*** Height[" << height << "] must be greater than 0." << endl
1298  << endl;
1299  height = 0;
1300  return;
1301  }
1302  value = new float*[height];
1303  widths = new kkuint32[height];
1304 
1305  XmlTokenPtr tok = s.GetNextToken (cancelFlag, log);
1306  kkuint32 rowCount = 0;
1307  while (tok)
1308  {
1309  if (typeid(*tok) == typeid(XmlElementArrayFloat))
1310  {
1311  if (rowCount >= height)
1312  {
1313  log.Level (-1) << endl
1314  << "XmlElementArrayFloat2DVarying ***ERROR*** Number of defined rows exceeds defined Height[" << height << "]" << endl
1315  << endl;
1316  widths[rowCount] = 0;
1317  value[rowCount] = NULL;
1318  }
1319  else
1320  {
1321  XmlElementArrayFloatPtr f = dynamic_cast<XmlElementArrayFloatPtr>(tok);
1322  widths[rowCount] = f->Count ();
1323  value[rowCount] = f->TakeOwnership ();
1324  }
1325  ++rowCount;
1326  }
1327  delete tok;
1328  tok = s.GetNextToken (cancelFlag, log);
1329  }
1330  while (rowCount < height)
1331  {
1332  value[rowCount] = NULL;
1333  ++rowCount;
1334  }
1335 }
1336 
1337 
1338 
1340 {
1341  if (value)
1342  {
1343  for (kkuint32 x = 0; x < height; ++x)
1344  {
1345  delete value[x];
1346  value[x] = NULL;
1347  }
1348  }
1349  delete value; value = NULL;
1350  delete widths; widths = NULL;
1351 }
1352 
1353 
1354 
1355 
1357 {
1358  float** v = value;
1359  value = NULL;
1360  return v;
1361 }
1362 
1363 
1365 {
1366  kkuint32* w = widths;
1367  widths = NULL;
1368  return w;
1369 }
1370 
1371 
1372 
1374  (kkuint32 height,
1375  const kkint32* widths, /**< Each entry in array defines the length of the corresponding row in 'mat'. */
1376  float** const mat,
1377  const KKStr& varName,
1378  ostream& o
1379  )
1380 {
1381  XmlTag startTag ("ArrayFloat2DVarying", XmlTag::TagTypes::tagStart);
1382  if (!varName.Empty ())
1383  startTag.AddAtribute ("VarName", varName);
1384  startTag.AddAtribute ("Height", (kkint32)height);
1385  startTag.WriteXML (o);
1386  o << endl;
1387 
1388  for (kkuint32 r = 0; r < height; ++r)
1389  {
1390  KKStr rowName = "Row_" + StrFormatInt (r, "000");
1391  XmlElementArrayFloat::WriteXML (widths[r], mat[r], rowName, o);
1392  }
1393 
1394  XmlTag endTag ("ArrayFloat2DVarying", XmlTag::TagTypes::tagEnd);
1395  endTag.WriteXML (o);
1396  o << endl;
1397 }
1398 
1399 
1400 XmlFactoryMacro(ArrayFloat2DVarying)
1401 
1402 
1403 
1404 
1405 
1406 
1407 
1408 
1409 
1410 
1411 
1412 
1414 
1416 {
1417  return XmlFactoryKKStr::FactoryInstance ();
1418 }
1419 
1420 
1421 
1422 
1423 XmlFactoryMacro(VectorKKStr)
1425 XmlFactoryMacro(KKStrListIndexed)
1426 
1427 
1428 
1429 
1430 
1431 
1432 
1433 
1434 
1435 /**
1436  * Works with matching Marco (XmlElementBuiltInTypeHeader) defined in XmlStream.h
1437  */
1438 #define XmlElementBuiltInTypeBody(T,TypeName,ParseMethod)
1439  XmlElement##TypeName::XmlElement##TypeName (XmlTagPtr tag,
1440  XmlStream& s,
1441  VolConstBool& cancelFlag,
1442  RunLog& log
1443  ):
1444  XmlElement (tag, s, log),
1445  value ((T)0) \
1446 {
1447  KKStrConstPtr valueStr = tag->AttributeValueByName ("Value");
1448  if (valueStr)
1449  value = (T)valueStr->##ParseMethod ();
1450  XmlTokenPtr tok = s.GetNextToken (cancelFlag, log);
1451  while (tok != NULL)
1452  {
1453  if (tok->TokenType () == XmlToken::TokenTypes::tokContent)
1454  {
1455  XmlContentPtr c = dynamic_cast<XmlContentPtr> (tok);
1456  value = (T)c->Content ()->##ParseMethod ();
1457  }
1458  delete tok;
1459  tok = s.GetNextToken (cancelFlag, log);
1460  } \
1461 }
1462 
1463  XmlElement
1464  ##TypeName::~ XmlElement##TypeName () \
1465 { \
1466 }
1467 
1468  void
1469  XmlElement##TypeName::WriteXML (T d,
1470  const KKStr& varName,
1471  std::ostream& o
1472  ) \
1473 {
1474  XmlTag startTag (#TypeName, XmlTag::TagTypes::tagEmpty);
1475  if (!varName.Empty ())
1476  startTag.AddAtribute ("VarName", varName);
1477  startTag.AddAtribute ("Value", d);
1478  startTag.WriteXML (o);
1479  o << endl; \
1480 }
1481 
1482  bool
1483  XmlElement##TypeName::ToBool () const {return value != 0;} KKStr
1484  XmlElement##TypeName::ToKKStr () const {return (KKStr)value;} double
1485  XmlElement##TypeName::ToDouble () const {return (double)value;} float
1486  XmlElement##TypeName::ToFloat () const {return (float)value;} kkint32
1487  XmlElement##TypeName::ToInt32 () const {return (kkint32)value;}
1488  XmlFactoryMacro
1489  (TypeName)
1490 
1491 
1492 
1493 
1494 
1495 
1496 #define XmlElementArrayBody(T,TypeName,ParserNextTokenMethod) XmlElement
1497  ##TypeName::XmlElement##TypeName (XmlTagPtr tag,
1498  XmlStream& s,
1499  VolConstBool& cancelFlag,
1500  RunLog& log
1501  ):
1502  XmlElement (tag, s, log),
1503  count (0),
1504  value (NULL) \
1505 {
1506  count = tag->AttributeValueInt32 ("Count");
1507  if (count < 0)
1508  {
1509  log.Level (-1) << endl
1510  << "XmlElement##TypeName ***ERROR*** Attribute Count[" << count
1511  << "] must be a positive value; will set array to NULL." << endl
1512  << endl;
1513  count = 0;
1514  }
1515 
1516  if (count <= 0)
1517  {
1518  value = NULL;
1519  count = 0;
1520  }
1521  else
1522  {
1523  value = new T[count];
1524  }
1525 
1526  kkuint32 fieldsExtracted = 0;
1527  XmlTokenPtr tok = s.GetNextToken (cancelFlag, log);
1528  while (tok)
1529  {
1530  if (tok->TokenType () == XmlToken::TokenTypes::tokContent)
1531  {
1532  XmlContentPtr c = dynamic_cast<XmlContentPtr> (tok);
1533 
1534  KKStrParser p (*(c->Content ()));
1535 
1536  while (p.MoreTokens ())
1537  {
1538  double zed = p.##ParserNextTokenMethod ("\t,");
1539  if (fieldsExtracted < count)
1540  value[fieldsExtracted] = (T)zed;
1541  ++fieldsExtracted;
1542  }
1543  }
1544  delete tok;
1545  tok = s.GetNextToken (cancelFlag, log);
1546  }
1547 
1548  if (fieldsExtracted != count)
1549  {
1550  log.Level (-1) << endl
1551  << "XmlElement##TypeName<> ***ERROR*** FieldsExtracted["
1552  << fieldsExtracted << "] differs from specified Count["
1553  << count << "]" << endl
1554  << endl;
1555  } \
1556 }
1557 
1558  XmlElement
1559  ##TypeName::~XmlElement##TypeName () \
1560 {
1561  delete value;
1562  value = NULL; \
1563 }
1564 
1565  T
1566  * XmlElement##TypeName::TakeOwnership () \
1567 {
1568  T* v = value;
1569  value = NULL;
1570  return v; \
1571 }
1572 
1573  void
1574  XmlElement##TypeName::WriteXML (kkuint32 count,
1575  const T* d,
1576  const KKStr& varName,
1577  std::ostream& o
1578  ) \
1579 {
1580  XmlTag startTag (#TypeName, XmlTag::TagTypes::tagStart);
1581  if (!varName.Empty ())
1582  startTag.AddAtribute ("VarName", varName);
1583  startTag.AddAtribute ("Count", (kkint32)count);
1584  startTag.WriteXML (o);
1585 
1586  for (kkuint32 x = 0; x < count; ++x)
1587  {
1588  if (x > 0)
1589  o << "\t";
1590  o << d[x];
1591  }
1592  XmlTag endTag (#TypeName, XmlTag::TagTypes::tagEnd);
1593  endTag.WriteXML (o);
1594  o << endl; \
1595 }
1596  XmlFactoryMacro
1597  (TypeName)
1598 
1599 
1600 
1601 
1602 
1603 
1604 
1605 
1606 
1607 /**
1608  *@details Works with corresponding macro (XmlElementArray2DHeader) defined in header file "XmlStream.h"
1609  *@param T The Built-In type, examples: float, kkint32, double, ...
1610  *@param TypeName The name we give the type ex: "Int32", "Float", ....
1611  *@param XmlElementToUse the XmlElement derived class that will be used to process each row in the matrix.
1612  */
1613 #define XmlElementArray2DBody(T,TypeName,XmlElementToUse) XmlElement
1614  ##TypeName::XmlElement##TypeName (XmlTagPtr tag,
1615  XmlStream& s,
1616  VolConstBool& cancelFlag,
1617  RunLog& log
1618  ):
1619  XmlElement (tag, s, log),
1620  height (0),
1621  value (NULL),
1622  width (0) \
1623 {
1624  height = tag->AttributeValueInt32 ("Height");
1625  if (height <= 0)
1626  {
1627  log.Level (-1) << endl
1628  << "XmlElement" << #TypeName << " ***ERROR*** Attribute Height["
1629  << height << "] must be a positive value; will set array to NULL."
1630  << endl << endl;
1631  height = 0;
1632  }
1633 
1634  width = tag->AttributeValueInt32 ("Width");
1635  if (width <= 0)
1636  {
1637  log.Level (-1) << endl
1638  << "XmlElement" << #TypeName << " ***ERROR*** Attribute Width["
1639  << width << "] must be a positive value; will set array to NULL."
1640  << endl << endl;
1641  width = 0;
1642  }
1643 
1644  if ((height <= 0) || (width <= 0))
1645  {
1646  value = NULL;
1647  height = 0;
1648  width = 0;
1649  }
1650  else
1651  {
1652  value = new T*[width];
1653  }
1654 
1655  kkuint32 rowCount = 0;
1656  XmlTokenPtr tok = s.GetNextToken (cancelFlag, log);
1657  while (tok)
1658  {
1659  if (typeid(*tok) != typeid(XmlElementToUse))
1660  {
1661  log.Level (-1) << endl
1662  << "XmlElement" << #TypeName << " ***ERROR*** Element: "
1663  << tok->SectionName () << " unexpected."
1664  << endl << endl;
1665  }
1666  else
1667  {
1668  XmlElementToUse* row = dynamic_cast<XmlElementToUse*> (tok);
1669  if (row->Count () != width)
1670  {
1671  log.Level (-1) << endl
1672  << "XmlElement" << #TypeName << " ***ERROR*** Row Count[ "
1673  << row->Count () << " not equal to Width[" << width << "]."
1674  << endl << endl;
1675  }
1676  else
1677  {
1678  if (rowCount < height)
1679  value[rowCount] = row->TakeOwnership ();
1680  ++rowCount;
1681  }
1682  }
1683  delete tok;
1684  tok = s.GetNextToken (cancelFlag, log);
1685  }
1686 
1687  if (rowCount != height)
1688  {
1689  log.Level (-1) << endl
1690  << "XmlElement" << #TypeName << " ***ERROR*** RowCount[ "
1691  << rowCount << "] differs from specified height[" << height << "]."
1692  << endl << endl;
1693  }
1694  while (rowCount < height)
1695  {
1696  value[rowCount] = new T[width];
1697  for (kkuint32 x = 0; x < width; ++x)
1698  value[rowCount][x] = (T)0;
1699  ++rowCount;
1700  } \
1701 }
1702 
1703  XmlElement
1704  ##TypeName::~XmlElement##TypeName () \
1705 {
1706  if (value)
1707  {
1708  for (kkuint32 x = 0; x < height; ++x)
1709  delete value[x];
1710  }
1711  delete value;
1712  value = NULL; \
1713 }
1714 
1715  T
1716  ** XmlElement##TypeName::TakeOwnership () \
1717 {
1718  T** v = value;
1719  value = NULL;
1720  return v; \
1721 }
1722 
1723  void
1724  XmlElement##TypeName::WriteXML (kkuint32 height,
1725  kkuint32 width,
1726  T** const mat,
1727  const KKStr& varName,
1728  std::ostream& o
1729  ) \
1730 {
1731  XmlTag startTag (#TypeName, XmlTag::TagTypes::tagStart);
1732  if (!varName.Empty ())
1733  startTag.AddAtribute ("VarName", varName);
1734  startTag.AddAtribute ("Height", (kkint32)height);
1735  startTag.AddAtribute ("Width", (kkint32)width);
1736  startTag.WriteXML (o);
1737 
1738  for (kkuint32 r = 0; r < height; ++r)
1739  {
1740  KKStr vn = "Row_" + StrFormatInt (r, "0000");
1741  XmlElementToUse::WriteXML (width, mat[r], vn, o);
1742  }
1743  XmlTag endTag (#TypeName, XmlTag::TagTypes::tagEnd);
1744  endTag.WriteXML (o);
1745  o << endl; \
1746 }
1747  XmlFactoryMacro
1748  (TypeName)
1749 
1750 
1751 
1752 
1753 
1754 
1755 
1756 
1757 
1758 #define XmlElementVectorBody(T,TypeName,ParserNextTokenMethod) XmlElement
1759  ##TypeName::XmlElement##TypeName (XmlTagPtr tag,
1760  XmlStream& s,
1761  VolConstBool& cancelFlag,
1762  RunLog& log
1763  ):
1764  XmlElement (tag, s, log) \
1765 {
1766  kkint32 count = 0;
1767  KKStrConstPtr countStr = tag->AttributeValueByName ("Count");
1768  if (countStr)
1769  count = countStr->ToInt32 ();
1770 
1771  value = new vector<T> ();
1772 
1773  XmlTokenPtr tok = s.GetNextToken (cancelFlag, log);
1774  while (tok)
1775  {
1776  if (tok->TokenType () == XmlToken::TokenTypes::tokContent)
1777  {
1778  XmlContentPtr c = dynamic_cast<XmlContentPtr> (tok);
1779 
1780  KKStrParser p (*(c->Content ()));
1781 
1782  while (p.MoreTokens ())
1783  {
1784  T zed = p.##ParserNextTokenMethod ("\t,");
1785  value->push_back ((T)zed);
1786  }
1787  }
1788  delete tok;
1789  tok = s.GetNextToken (cancelFlag, log);
1790  } \
1791 }
1792 
1793 
1794  XmlElement
1795  ##TypeName::~XmlElement##TypeName () \
1796 {
1797  delete value;
1798  value = NULL; \
1799 }
1800 
1801 
1802  vector
1803  <T>* XmlElement##TypeName::TakeOwnership () \
1804 {
1805  vector<T>* v = value;
1806  value = NULL;
1807  return v; \
1808 }
1809 
1810 
1811  void
1812  XmlElement##TypeName::WriteXML (const vector<T>& v,
1813  const KKStr& varName,
1814  std::ostream& o
1815  ) \
1816 {
1817  XmlTag startTag (#TypeName, XmlTag::TagTypes::tagStart);
1818  if (!varName.Empty ())
1819  startTag.AddAtribute ("VarName", varName);
1820  startTag.WriteXML (o);
1821 
1822  for (kkuint32 x = 0; x < v.size (); ++x)
1823  {
1824  if (x > 0)
1825  o << "\t";
1826  o << v[x];
1827  }
1828  XmlTag endTag (#TypeName, XmlTag::TagTypes::tagEnd);
1829  endTag.WriteXML (o);
1830  o << endl; \
1831 }
1832  XmlFactoryMacro
1833  (TypeName)
1834 
1835 
1836 
1837 
1838 
1839 // Integral Types
1840 XmlElementBuiltInTypeBody(kkint32,Int32,ToInt32) // XmlElementInt32
1841 
1842 XmlElementBuiltInTypeBody(kkint64,Int64,ToInt64) // XmlElementInt64
1843 
1844 XmlElementBuiltInTypeBody(float,Float,ToDouble) // XmlElementFloat
1845 
1846 XmlElementBuiltInTypeBody(double,Double,ToDouble) // XmlElementDouble
1847 
1848 
1849 
1850 
1851 // Arrays
1852 
1853 XmlElementArrayBody(kkuint16, ArrayUint16, GetNextTokenUint) // XmlElementArrayUint16
1854 
1855 XmlElementArrayBody(kkint32, ArrayInt32, GetNextTokenInt) // XmlElementArrayInt32
1856 
1858 
1860 
1861 
1862 XmlElementArray2DBody(float, ArrayFloat2D, XmlElementArrayFloat) // XmlElementArrayFloat2D
1863 
1864 
1865 
1866 // Vectors
1867 
KKStr(kkint32 size)
Creates a KKStr object that pre-allocates space for &#39;size&#39; characters.
Definition: KKStr.cpp:655
XmlTag(const KKStr &_name, TagTypes _tagType)
Definition: XmlStream.cpp:586
#define XmlElementBuiltInTypeBody(T, TypeName, ParseMethod)
Definition: XmlStream.cpp:1438
void ExtractAttribute(KKStr &tagStr, KKStr &attributeName, KKStr &attributeValue)
Definition: XmlStream.cpp:412
KKStr StrFromFloat(float f)
Definition: KKStr.cpp:5219
XmlTag * XmlTagPtr
Definition: Atom.h:31
XmlTag(std::istream &i)
virtual ~XmlToken()
Definition: XmlStream.cpp:745
void AddAtribute(const KKStr &attributeName, const DateTime &attributeValue)
Definition: XmlStream.cpp:649
void AddAtribute(const KKStr &attributeName, bool attributeValue)
Definition: XmlStream.cpp:611
XmlFactory * FactoryLookUp(const KKStr &className) const
Definition: XmlStream.cpp:979
KKStrConstPtr AttributeValue(const char *attributeName)
Definition: XmlStream.cpp:818
__int32 kkint32
Definition: KKBaseTypes.h:88
TagTypes TagType() const
Definition: XmlStream.h:194
Manages the break down a stream into a set of logical tokens compatible with the XML format...
Definition: XmlTokenizer.h:25
void RegisterFactory(XmlFactory *factory)
Definition: XmlStream.cpp:959
void TrimWhiteSpace(const char *_whiteSpace=" ")
After this call all leading and trailing whitespace will be trimmed from tokens.
Definition: KKStrParser.cpp:95
XmlElementArrayFloat2DVarying(XmlTagPtr tag, XmlStream &s, VolConstBool &cancelFlag, RunLog &log)
Definition: XmlStream.cpp:1283
KKStr & TrimRight(const char *whiteSpaceChars="\n\r\t ")
Definition: KKStr.cpp:1695
bool Value() const
Definition: XmlStream.cpp:1028
void Add(const KKStr &key, float v)
Definition: XmlStream.cpp:1212
XmlElement(XmlTagPtr _nameTag, XmlStream &s, RunLog &log)
Definition: XmlStream.cpp:758
KKStr ExtractToken2(const char *delStr="\n\t\r ")
Extract first Token from the string.
Definition: KKStr.cpp:3026
const KKStr & AttributeValueKKStr(const KKStr &name) const
Definition: XmlStream.cpp:330
virtual ~XmlElementUnKnown()
Definition: XmlStream.cpp:1068
KKStrConstPtr AttributeValueByIndex(kkuint32 index) const
Definition: XmlStream.cpp:664
KKStr GetNextToken(const char *delStr="\n\t\r ")
Extract next Token from string, tokens will be separated by delimiter characters. ...
XmlFactoryManager(const KKStr &_name)
Definition: XmlStream.cpp:939
XmlAttribute * XmlAttributePtr
Definition: XmlStream.h:130
const KKStr & Name() const
Definition: XmlStream.h:122
void ChopLastChar()
Definition: KKStr.cpp:1668
const KKStr & AttributeValueKKStr(const KKStr &name) const
Definition: XmlStream.cpp:688
KKStrConstPtr AttributeValueByName(const KKStr &name) const
Definition: XmlStream.cpp:301
unsigned __int16 kkuint16
16 bit unsigned integer.
Definition: KKBaseTypes.h:86
KKStr & operator=(const char *src)
Definition: KKStr.cpp:1442
DateTime AttributeValueDateTime(const KKStr &attributeName) const
Definition: XmlStream.cpp:682
void AddAtribute(const KKStr &attributeName, kkint64 attributeValue)
Definition: XmlStream.cpp:629
DateTime(const KKStr &s)
Definition: DateTime.cpp:1043
XmlContent * XmlContentPtr
Definition: XmlStream.h:24
char FirstChar() const
Definition: KKStr.cpp:1970
XmlTokenizer(const KKStr &_fileName, bool &_fileOpened)
XmlElementUnKnown(XmlTagPtr tag, XmlStream &s, VolConstBool &cancelFlag, RunLog &log)
Definition: XmlStream.cpp:1051
kkint32 AttributeValueInt32(const KKStr &name) const
Definition: XmlStream.cpp:341
const KKStr & Value() const
Definition: XmlStream.h:123
void ReadWholeTag(istream &i, KKStr &tagStr)
Definition: XmlStream.cpp:390
void Add(const KKStr &key, kkint32 v)
Definition: XmlStream.cpp:1203
static void RegisterFactory(XmlFactory *factory)
Definition: XmlStream.cpp:897
std::deque< XmlTokenPtr > * TakeOwnership()
Definition: XmlStream.cpp:1080
kkint64 ToInt64() const
Definition: KKStr.cpp:3598
static void WriteXML(const bool b, const KKStr &varName, std::ostream &o)
Definition: XmlStream.cpp:1035
KKStr ToString() const
Definition: XmlStream.cpp:694
const KKStr & Name() const
Definition: XmlStream.h:193
void AddAttribute(const KKStr &name, const KKStr &value)
Definition: XmlStream.cpp:366
XmlToken * XmlTokenPtr
Definition: XmlStream.h:18
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
#define XmlElementArrayBody(T, TypeName, ParserNextTokenMethod)
Definition: XmlStream.cpp:1496
float GetNextTokenFloat(const char *delStr="\n\t\r ")
XmlFactory(const KKStr &_clasName)
Definition: XmlStream.cpp:931
__int64 kkint64
Definition: KKBaseTypes.h:90
XmlElementBool(XmlTagPtr tag, XmlStream &s, VolConstBool &cancelFlag, RunLog &log)
Definition: XmlStream.cpp:998
void Add(const KKStr &key, bool v)
Definition: XmlStream.cpp:1232
bool MoreTokens() const
Definition: KKStrParser.h:74
XmlElementKeyValuePairs(XmlTagPtr tag, XmlStream &s, VolConstBool &cancelFlag, RunLog &log)
Definition: XmlStream.cpp:1141
KKStr & operator=(KKStr &&src)
Definition: KKStr.cpp:1369
kkint32 xmlLevel
Definition: XmlStream.cpp:720
KKStrConstPtr AttributeNameByIndex(kkuint32 index) const
Definition: XmlStream.cpp:320
char LastChar() const
Definition: KKStr.cpp:2007
kkuint32 Len() const
Returns the number of characters in the string.
Definition: KKStr.h:366
KKStrConstPtr AttributeValueByName(const KKStr &name) const
Definition: XmlStream.cpp:658
char PeekNextChar() const
void AddAtribute(const KKStr &attributeName, kkint32 attributeValue)
Definition: XmlStream.cpp:620
KKTHread * KKTHreadPtr
void Add(const KKStr &key, double v)
Definition: XmlStream.cpp:1222
KKStrParser(const KKStr &_str)
Definition: KKStrParser.cpp:42
KKStr operator+(const char *left, const KKStr &right)
Definition: KKStr.cpp:3976
void Add(const KKStr &key, const KKStr &v)
Definition: XmlStream.cpp:1193
kkint32 AttributeValueInt32(const KKStr &attributeName) const
Definition: XmlStream.cpp:676
void SkipWhiteSpace(const char *whiteSpace=" ")
Advances the next-character pointer to the next NOT white space character.
KKStrPtr TakeOwnership()
Definition: XmlStream.cpp:845
char PeekLastChar() const
KKStr(const KKStr &str)
Copy Constructor.
Definition: KKStr.cpp:561
void AddAtribute(const KKStr &attributeName, const KKStr &attributeValue)
Definition: XmlStream.cpp:602
virtual XmlAttributePtr PopFromBack()
Definition: XmlStream.cpp:264
void TrimLeft(const char *whiteSpaceChars="\n\r\t ")
Definition: KKStr.cpp:1745
bool Empty() const
Definition: KKStr.h:241
Manages the reading and writing of objects in a simple XML format. For a class to be supported by Xml...
Definition: XmlStream.h:46
KKStr SubStrPart(kkint32 firstChar, kkint32 lastChar) const
returns a SubString consisting of all characters starting at index &#39;firstChar&#39; and ending at &#39;lastInd...
Definition: KKStr.cpp:2802
static void WriteXML(kkuint32 height, const kkint32 *widths, float **const mat, const KKStr &varName, std::ostream &o)
Definition: XmlStream.cpp:1374
XmlElement derived class that will be used when there is no Factory defined for the element...
Definition: XmlStream.h:471
static XmlFactory * FactoryLookUp(const KKStr &className)
Definition: XmlStream.cpp:879
kkint32 ToInt32() const
Definition: KKStr.cpp:3587
KKStr StrFromDouble(double d)
Definition: KKStr.cpp:5229
XmlTokenizer * XmlTokenizerPtr
Definition: XmlTokenizer.h:117
bool EndsWith(const char *value)
Definition: KKStr.cpp:1197
kkuint32 GetNextTokenUint(const char *delStr="\n\t\r ")
virtual ~XmlElementBool()
Definition: XmlStream.cpp:1023
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of &#39;std::string&#39; strings.
Definition: KKStr.cpp:1082
virtual const KKStr & ClassName() const
Definition: XmlStream.h:387
KKStrConstPtr AttributeValue(const KKStr &attributeName)
Definition: XmlStream.cpp:809
virtual ~XmlStream()
Definition: XmlStream.cpp:56
static const KKStr & EmptyStr()
Static method that returns an Empty String.
Definition: KKStr.cpp:3453
XmlFactory * XmlFactoryPtr
Definition: XmlStream.h:27
KKStrConstPtr Peek(kkuint32 idx)
Allows you to look at future tokens in the stream; index of 0 would be the next token to be extracted...
virtual ~XmlContent()
Definition: XmlStream.cpp:837
double GetNextTokenDouble(const char *delStr="\n\t\r ")
virtual const KKStr & VarName() const
Definition: XmlStream.cpp:794
XmlElementDateTime(XmlTagPtr tag, XmlStream &s, VolConstBool &cancelFlag, RunLog &log)
Definition: XmlStream.cpp:1096
KKStrConstPtr AttributeValueByIndex(kkuint32 index) const
Definition: XmlStream.cpp:311
kkint32 GetNextTokenInt(const char *delStr="\n\t\r ")
KKStr StrFormatInt(kkint32 val, const char *mask)
Definition: KKStr.cpp:5004
KKStr YYYY_MM_DD_HH_MM_SS() const
Definition: DateTime.cpp:1216
XmlAttributeList(bool _owner)
Definition: XmlStream.cpp:235
double ToDouble() const
Definition: KKStr.cpp:3541
std::ostream &__cdecl operator<<(std::ostream &os, const KKStr &str)
XmlAttributePtr LookUpByName(const KKStr &name) const
Definition: XmlStream.cpp:375
XmlStream(const KKStr &_fileName, RunLog &_log)
Definition: XmlStream.cpp:41
virtual XmlElementPtr ManufatureXmlElement(XmlTagPtr tag, XmlStream &s, VolConstBool &cancelFlag, RunLog &log)=0
void RegisterFactory(XmlFactoryPtr factory)
Registers a Factory at the current hierarchy that is being processed.
Definition: XmlStream.cpp:67
std::vector< std::pair< KKStr, KKStr > > * TakeOwnership()
Definition: XmlStream.cpp:1185
virtual const KKStr & SectionName() const
Definition: XmlStream.cpp:785
KKStr NameTagStr() const
Definition: XmlStream.cpp:775
const char * Str() const
Returns a pointer to a ascii string.
Definition: KKStr.h:422
XmlFactoryManager * XmlFactoryManagerPtr
Definition: XmlStream.h:30
virtual void PushOnBack(XmlAttributePtr a)
Definition: XmlStream.cpp:250
XmlElement(const KKStr &sectionName, XmlTag::TagTypes tagType)
Definition: XmlStream.cpp:750
void ChopFirstChar()
Definition: KKStr.cpp:1649
static XmlFactoryManagerPtr globalXmlFactoryManager
Definition: XmlStream.h:402
static void WriteXml(const KKStr &s, std::ostream &o)
Definition: XmlStream.cpp:853
virtual ~XmlElement()
Definition: XmlStream.cpp:767
XmlContent(KKStrPtr _content)
Definition: XmlStream.cpp:829
char operator[](kkint32 i) const
Definition: KKStr.cpp:3413
void WriteXML(std::ostream &o)
Definition: XmlStream.cpp:723
KKStrPtr const Content() const
Definition: XmlStream.h:338
Used for logging messages.
Definition: RunLog.h:49
XmlToken * XmlTokenPtr
Definition: XmlStream.h:255
static void FinalCleanUp()
Definition: XmlStream.cpp:921
XmlTag(const KKStrConstPtr tagStr)
Definition: XmlStream.cpp:543
#define XmlElementVectorBody(T, TypeName, ParserNextTokenMethod)
Definition: XmlStream.cpp:1758
static void WriteXML(const DateTime &d, const KKStr &varName, std::ostream &o)
Definition: XmlStream.cpp:1113
virtual TokenTypes TokenType()=0
Class that manages the extraction of tokens from a String without being destructive to the original s...
Definition: KKStrParser.h:18
KKStrPtr GetNextToken()
Will retrieve the next token in the stream which will be either a tag token or up to one line of the ...
virtual XmlTokenPtr GetNextToken(VolConstBool &cancelFlag, RunLog &log)
Definition: XmlStream.cpp:116
KKException(const KKStr &_exceptionStr)
Definition: KKException.cpp:45
bool ToBool() const
Returns the bool equivalent of the string, ex &#39;Yes&#39; = true, &#39;No&#39; = false, &#39;True&#39; = true...
Definition: KKStr.cpp:3523
#define XmlElementArray2DBody(T, TypeName, XmlElementToUse)
Definition: XmlStream.cpp:1613
virtual XmlAttributePtr PopFromFromt()
Definition: XmlStream.cpp:273
XmlElementKeyValuePairs()
Used to construct an instance that will be written out to a XML file.
Definition: XmlStream.cpp:1134
Maintains one instance of a GoalKeeper object that can be used anywhere in the application.
KKStr SubStrPart(kkint32 firstChar) const
returns a SubString consisting of all characters starting at index &#39;firstChar&#39; until the end of the s...
Definition: KKStr.cpp:2780
virtual void PushOnFront(XmlAttributePtr a)
Definition: XmlStream.cpp:257
#define XmlFactoryMacro(NameOfClass)
Definition: XmlStream.h:688
XmlFactoryPtr XmlElementKKStrFactoryInstance()
Definition: XmlStream.cpp:1415
virtual XmlContentPtr GetNextContent(RunLog &log)
Definition: XmlStream.cpp:210
void Add(const KKStr &key, const KKB::DateTime &v)
Definition: XmlStream.cpp:1243
XmlFactoryPtr XmlElementUnKnownFactoryInstance()
Definition: XmlStream.cpp:1090
XmlStream(XmlTokenizerPtr _tokenStream)
Definition: XmlStream.cpp:29
XmlAttributeList(const XmlAttributeList &attributes)
Definition: XmlStream.cpp:241
KKStrConstPtr AttributeNameByIndex(kkuint32 index) const
Definition: XmlStream.cpp:670
~XmlFactoryManager()
summary>Give the FactoryManager instance ownership of this factory; the name of the factory must be u...
Definition: XmlStream.cpp:946
void AddAtribute(const KKStr &attributeName, double attributeValue)
Definition: XmlStream.cpp:638
KKStr QuotedStr() const
Returns a quoted version of string where special characters Line-Feed, Carriage Return, and Tab, are encoded as escape sequences.
Definition: KKStr.cpp:2890
DateTime & operator=(const DateTime &right)
Definition: DateTime.cpp:1231
void WriteXML(const KKStr &varName, std::ostream &o)
Definition: XmlStream.cpp:1252
DateTime AttributeValueDateTime(const KKStr &name) const
Definition: XmlStream.cpp:352
XmlAttribute(const KKStr &_name, const KKStr &_value)
Definition: XmlStream.h:115
KKStr StrFromInt32(kkint32 i)
Definition: KKStr.cpp:5175
volatile const bool VolConstBool
Definition: KKBaseTypes.h:163
virtual ~XmlTag()
Definition: XmlStream.cpp:596