AnimatLab  2
Test
StdXml.cpp
Go to the documentation of this file.
1 
7 #include "StdAfx.h"
8 
9 namespace StdUtils
10 {
11 
19 {
20 
21 }
22 
30 {
31 
32 }
33 
43 {
44  m_aryTagStack.push(GetChildTagName());
45  return CMarkupSTL::IntoElem();
46 }
47 
57 {
58  bool bVal = CMarkupSTL::OutOfElem();
59  if(bVal) m_aryTagStack.pop();
60  return bVal;
61 }
62 
73 std::string CStdXml::FullTagPath(bool bAddChildName)
74 {
75  int iSize = m_aryTagStack.size(), iIndex;
76  std::string strTagPath, strVal;
77  std::deque<std::string> aryTemp;
78 
79 try
80 {
81  for(iIndex=0; iIndex<iSize; iIndex++)
82  {
83  strVal = m_aryTagStack.top();
84 
85  if(iIndex<(iSize-1))
86  strTagPath = "\\" + strVal + strTagPath;
87  else
88  strTagPath = strVal + strTagPath;
89 
90  aryTemp.push_front(strVal);
91  m_aryTagStack.pop();
92  }
93 
94  if(bAddChildName)
95  {
96  strVal = GetChildTagName();
97  if( !strVal.empty() ) strTagPath += ("\\" + strVal);
98  }
99 
100  for(iIndex=0; iIndex<iSize; iIndex++)
101  {
102  strVal = aryTemp[iIndex];
103  m_aryTagStack.push(strVal);
104  }
105 
106  return strTagPath;
107 }
108 catch(...)
109 {return "";}
110 }
111 
122 std::string CStdXml::ValueErrorString(std::string strValue)
123 {
124  std::string strError;
125  strError = " Element: " + FullTagPath() + " Value: " + strValue;
126  return strError;
127 }
128 
136 {
137  int iSize = m_aryTagStack.size(), iIndex;
138 
139  for(iIndex=0; iIndex<iSize; iIndex++)
140  m_aryTagStack.pop();
141 }
142 
151 std::string CStdXml::Serialize()
152 {return GetDoc();}
153 
162 void CStdXml::Deserialize(std::string &strXml)
163 {
164  if(!SetDoc(strXml.c_str()))
165  THROW_ERROR(Std_Err_lDeserializingXml, Std_Err_strDeserializingXml);
166 }
167 
179 bool CStdXml::FindElement(std::string strElementName, bool bThrowError)
180 {
181  if(CMarkupSTL::FindElem(strElementName.c_str()))
182  {
183  ClearTagStack();
184  m_aryTagStack.push(strElementName);
185 
186  return true;
187  }
188  else if(bThrowError)
189  THROW_PARAM_ERROR(Std_Err_lElementNotFound, Std_Err_strElementNotFound, "Element", (FullTagPath(false) + "\\" + strElementName));
190 
191  return false;
192 }
193 
203 {
204  int iTotal = 0;
205 
206  ResetChildPos();
207  while(FindChildElem())
208  iTotal++;
209  ResetChildPos();
210 
211  return iTotal;
212 }
213 
225 bool CStdXml::FindChildByIndex(int iIndex, bool bThrowError)
226 {
227  int iPos;
228 
229  ResetChildPos();
230 
231  for(iPos=0; iPos<=iIndex; iPos++)
232  {
233  if(!FindChildElem())
234  {
235  if(bThrowError)
236  THROW_PARAM_ERROR(Std_Err_lInvalidIndex, Std_Err_strInvalidIndex, "Index", iIndex);
237  else
238  return false;
239  }
240  }
241 
242  return true;
243 }
244 
256 bool CStdXml::FindChildElement(std::string strElementName, bool bThrowError)
257 {
258  ResetChildPos();
259  if(CMarkupSTL::FindChildElem(strElementName.c_str()))
260  return true;
261  else if(bThrowError)
262  THROW_PARAM_ERROR(Std_Err_lElementNotFound, Std_Err_strElementNotFound, "Element", (FullTagPath(false) + "\\" + strElementName));
263 
264  return false;
265 }
266 
278 bool CStdXml::IntoChildElement(std::string strElementName, bool bThrowError)
279 {
280  if(FindChildElement(strElementName, bThrowError))
281  return IntoElem();
282 
283  return false;
284 }
285 
295 {return GetChildData();}
296 
307 std::string CStdXml::GetChildString(std::string strElementName)
308 {
309  FindChildElement(strElementName);
310  return GetChildData();
311 }
312 
324 std::string CStdXml::GetChildString(std::string strElementName, std::string strDefault)
325 {
326  std::string strVal;
327 
328  if(FindChildElement(strElementName, false))
329  strVal = GetChildData();
330  else
331  strVal = strDefault;
332 
333  return strVal;
334 }
335 
345 {
346  std::string strVal;
347 
348  strVal = GetChildData();
349  strVal = Std_Trim(strVal);
350 
351  if(!Std_IsNumeric(strVal))
352  THROW_TEXT_ERROR(Std_Err_lNotNumericType, Std_Err_strNotNumericType, ValueErrorString(strVal));
353 
354  if(!Std_IsIntegerType(strVal))
355  THROW_TEXT_ERROR(Std_Err_lNotIntegerType, Std_Err_strNotIntegerType, ValueErrorString(strVal));
356 
357  //Need to add code here to verify it is a number.
358  return atol(strVal.c_str());
359 }
360 
371 long CStdXml::GetChildLong(std::string strElementName)
372 {
373  std::string strVal;
374 
375  FindChildElement(strElementName);
376  strVal = GetChildData();
377  strVal = Std_Trim(strVal);
378 
379  if(!Std_IsNumeric(strVal))
380  THROW_TEXT_ERROR(Std_Err_lNotNumericType, Std_Err_strNotNumericType, ValueErrorString(strVal));
381 
382  if(!Std_IsIntegerType(strVal))
383  THROW_TEXT_ERROR(Std_Err_lNotIntegerType, Std_Err_strNotIntegerType, ValueErrorString(strVal));
384 
385  //Need to add code here to verify it is a number.
386  return atol(strVal.c_str());
387 }
388 
400 long CStdXml::GetChildLong(std::string strElementName, long lDefault)
401 {
402  std::string strVal;
403  long lVal=0;
404 
405  if(FindChildElement(strElementName, false))
406  {
407  strVal = GetChildData();
408  strVal = Std_Trim(strVal);
409 
410  if(Std_IsNumeric(strVal) && Std_IsIntegerType(strVal))
411  lVal = atol(strVal.c_str());
412  else
413  lVal = lDefault;
414  }
415  else
416  lVal = lDefault;
417 
418  return lVal;
419 }
420 
430 {
431  std::string strVal;
432 
433  strVal = GetChildData();
434  strVal = Std_Trim(strVal);
435 
436  if(!Std_IsNumeric(strVal))
437  THROW_TEXT_ERROR(Std_Err_lNotNumericType, Std_Err_strNotNumericType, ValueErrorString(strVal));
438 
439  if(!Std_IsIntegerType(strVal))
440  THROW_TEXT_ERROR(Std_Err_lNotIntegerType, Std_Err_strNotIntegerType, ValueErrorString(strVal));
441 
442  //Need to add code here to verify it is a number.
443  return atoi(strVal.c_str());
444 }
445 
456 int CStdXml::GetChildInt(std::string strElementName)
457 {
458  std::string strVal;
459 
460  FindChildElement(strElementName);
461  strVal = GetChildData();
462  strVal = Std_Trim(strVal);
463 
464  if(!Std_IsNumeric(strVal))
465  THROW_TEXT_ERROR(Std_Err_lNotNumericType, Std_Err_strNotNumericType, ValueErrorString(strVal));
466 
467  if(!Std_IsIntegerType(strVal))
468  THROW_TEXT_ERROR(Std_Err_lNotIntegerType, Std_Err_strNotIntegerType, ValueErrorString(strVal));
469 
470  //Need to add code here to verify it is a number.
471  return atoi(strVal.c_str());
472 }
473 
485 int CStdXml::GetChildInt(std::string strElementName, int iDefault)
486 {
487  std::string strVal;
488  int iVal=0;
489 
490  if(FindChildElement(strElementName, false))
491  {
492  strVal = GetChildData();
493  strVal = Std_Trim(strVal);
494 
495  if(Std_IsNumeric(strVal) && Std_IsIntegerType(strVal))
496  iVal = atoi(strVal.c_str());
497  else
498  iVal = iDefault;
499  }
500  else
501  iVal = iDefault;
502 
503  return iVal;
504 }
505 
515 {
516  std::string strVal;
517 
518  strVal = GetChildData();
519  strVal = Std_Trim(strVal);
520 
521  if(!Std_IsNumeric(strVal))
522  THROW_TEXT_ERROR(Std_Err_lNotNumericType, Std_Err_strNotNumericType, ValueErrorString(strVal));
523 
524  //Need to add code here to verify it is a number.
525  return atof(strVal.c_str());
526 }
527 
538 double CStdXml::GetChildDouble(std::string strElementName)
539 {
540  std::string strVal;
541 
542  FindChildElement(strElementName);
543  strVal = GetChildData();
544  strVal = Std_Trim(strVal);
545 
546  if(!Std_IsNumeric(strVal))
547  THROW_TEXT_ERROR(Std_Err_lNotNumericType, Std_Err_strNotNumericType, ValueErrorString(strVal));
548 
549  //Need to add code here to verify it is a number.
550  return atof(strVal.c_str());
551 }
552 
564 double CStdXml::GetChildDouble(std::string strElementName, double dblDefault)
565 {
566  std::string strVal;
567  double dblVal=0;
568 
569  if(FindChildElement(strElementName, false))
570  {
571  strVal = GetChildData();
572  strVal = Std_Trim(strVal);
573 
574  if(Std_IsNumeric(strVal))
575  dblVal = atof(strVal.c_str());
576  else
577  dblVal = dblDefault;
578  }
579  else
580  dblVal = dblDefault;
581 
582  return dblVal;
583 }
584 
594 {
595  std::string strVal;
596 
597  strVal = GetChildData();
598  strVal = Std_Trim(strVal);
599 
600  if(!Std_IsNumeric(strVal))
601  THROW_TEXT_ERROR(Std_Err_lNotNumericType, Std_Err_strNotNumericType, ValueErrorString(strVal));
602 
603  //Need to add code here to verify it is a number.
604  return (float) atof(strVal.c_str());
605 }
606 
617 float CStdXml::GetChildFloat(std::string strElementName)
618 {
619  std::string strVal;
620 
621  FindChildElement(strElementName);
622  strVal = GetChildData();
623  strVal = Std_Trim(strVal);
624 
625  if(!Std_IsNumeric(strVal))
626  THROW_TEXT_ERROR(Std_Err_lNotNumericType, Std_Err_strNotNumericType, ValueErrorString(strVal));
627 
628  //Need to add code here to verify it is a number.
629  return (float) atof(strVal.c_str());
630 }
631 
643 float CStdXml::GetChildFloat(std::string strElementName, float fltDefault)
644 {
645  std::string strVal;
646  float fltVal=0;
647 
648  if(FindChildElement(strElementName, false))
649  {
650  strVal = GetChildData();
651  strVal = Std_Trim(strVal);
652 
653  if(Std_IsNumeric(strVal))
654  fltVal = (float) atof(strVal.c_str());
655  else
656  fltVal = fltDefault;
657  }
658  else
659  fltVal = fltDefault;
660 
661  return fltVal;
662 }
663 
673 {
674  std::string strVal;
675 
676  strVal = GetChildData();
677  strVal = Std_CheckString(strVal);
678 
679  if(strVal == "TRUE" || strVal == "1")
680  return true;
681  else if(strVal == "FALSE" || strVal == "0")
682  return false;
683  else
684  THROW_TEXT_ERROR(Std_Err_lNotBoolType, Std_Err_strNotBoolType, ValueErrorString(strVal));
685 
686  return false;
687 }
688 
699 bool CStdXml::GetChildBool(std::string strElementName)
700 {
701  std::string strVal;
702 
703  FindChildElement(strElementName);
704  strVal = GetChildData();
705  strVal = Std_CheckString(strVal);
706 
707  if(strVal == "TRUE" || strVal == "1")
708  return true;
709  else if(strVal == "FALSE" || strVal == "0")
710  return false;
711  else
712  THROW_TEXT_ERROR(Std_Err_lNotBoolType, Std_Err_strNotBoolType, ValueErrorString(strVal));
713 
714  return false;
715 }
716 
728 bool CStdXml::GetChildBool(std::string strElementName, bool bDefault)
729 {
730  std::string strVal;
731  bool bVal=false;
732 
733  if(FindChildElement(strElementName, false))
734  {
735  strVal = GetChildData();
736  strVal = Std_CheckString(strVal);
737 
738  if(strVal == "TRUE" || strVal == "1")
739  return true;
740  else if(strVal == "FALSE" || strVal == "0")
741  return false;
742  else
743  {
744  if(bDefault)
745  bVal = true;
746  else
747  bVal = false;
748  }
749  }
750  else
751  {
752  if(bDefault)
753  bVal = true;
754  else
755  bVal = false;
756  }
757 
758  return bVal;
759 }
760 
770 void CStdXml::AddElement(std::string strElementName, std::string strData)
771 {
772  if(!AddElem(strElementName.c_str(), strData.c_str()))
773  THROW_PARAM_ERROR(Std_Err_lAddingElement, Std_Err_strAddingElement, "Element", (FullTagPath(false) + "\\" + strElementName));
774 }
775 
785 void CStdXml::AddChildElement(std::string strElementName, std::string strVal)
786 {
787  if(!AddChildElem(strElementName.c_str(), strVal.c_str()))
788  THROW_PARAM_ERROR(Std_Err_lAddingElement, Std_Err_strAddingElement, "Element", (FullTagPath(false) + "\\" + strElementName));
789 }
790 
799 void CStdXml::AddChildElement(std::string strElementName)
800 {
801  std::string strVal;
802  AddChildElement(strElementName, strVal);
803 }
804 
814 void CStdXml::AddChildElement(std::string strElementName, char cVal)
815 {
816  std::ostringstream oStream;
817  int iVal = (int) cVal;
818 
819  oStream << iVal;
820  AddChildElement(strElementName, oStream.str());
821 }
822 
832 void CStdXml::AddChildElement(std::string strElementName, unsigned char cVal)
833 {
834  std::ostringstream oStream;
835  int iVal = (int) cVal;
836 
837  oStream << iVal;
838  AddChildElement(strElementName, oStream.str());
839 }
840 
850 void CStdXml::AddChildElement(std::string strElementName, long lVal)
851 {
852  std::ostringstream oStream;
853 
854  oStream << lVal;
855  AddChildElement(strElementName, oStream.str());
856 }
857 
867 void CStdXml::AddChildElement(std::string strElementName, int iVal)
868 {
869  std::ostringstream oStream;
870 
871  oStream << iVal;
872  AddChildElement(strElementName, oStream.str());
873 }
874 
884 void CStdXml::AddChildElement(std::string strElementName, double dblVal)
885 {
886  std::ostringstream oStream;
887 
888  oStream << dblVal;
889  AddChildElement(strElementName, oStream.str());
890 }
891 
901 void CStdXml::AddChildElement(std::string strElementName, float fltVal)
902 {
903  std::ostringstream oStream;
904 
905  oStream << fltVal;
906  AddChildElement(strElementName, oStream.str());
907 }
908 
918 void CStdXml::AddChildElement(std::string strElementName, bool bVal)
919 {
920  std::string strVal;
921 
922  if(bVal)
923  strVal = "True";
924  else
925  strVal = "False";
926 
927  AddChildElement(strElementName, strVal);
928 }
929 
939 void CStdXml::AddChildCData(std::string strElementName, std::string strCData)
940 {
941  AddChildElement(strElementName);
942  IntoElem();
943  SetData(strCData.c_str(), 1);
944  OutOfElem();
945 }
946 
960 std::string CStdXml::GetAttribString(std::string strAttribName, bool bCanBeBlank, bool bThrowError, std::string strDefault)
961 {
962  std::string strVal = GetAttrib(strAttribName.c_str());
963 
964  if(Std_IsBlank(strVal) && !bCanBeBlank)
965  {
966  if(bThrowError)
967  THROW_TEXT_ERROR(Std_Err_lBlankAttrib, Std_Err_strBlankAttrib, ValueErrorString(strVal));
968 
969  strVal = strDefault;
970  }
971 
972  return strVal;
973 }
974 
987 long CStdXml::GetAttribLong(std::string strAttribName, bool bThrowError, long lDefault)
988 {
989  std::string strVal;
990 
991  strVal = GetAttrib(strAttribName.c_str());
992  strVal = Std_Trim(strVal);
993 
994  if(Std_IsBlank(strVal))
995  {
996  if(bThrowError)
997  THROW_TEXT_ERROR(Std_Err_lBlankAttrib, Std_Err_strBlankAttrib, ValueErrorString(strVal));
998  else
999  return lDefault;
1000  }
1001 
1002  if(!Std_IsNumeric(strVal))
1003  THROW_TEXT_ERROR(Std_Err_lNotNumericType, Std_Err_strNotNumericType, ValueErrorString(strVal));
1004 
1005  if(!Std_IsIntegerType(strVal))
1006  THROW_TEXT_ERROR(Std_Err_lNotIntegerType, Std_Err_strNotIntegerType, ValueErrorString(strVal));
1007 
1008  //Need to add code here to verify it is a number.
1009  return atol(strVal.c_str());
1010 }
1011 
1024 int CStdXml::GetAttribInt(std::string strAttribName, bool bThrowError, int iDefault)
1025 {
1026  std::string strVal;
1027 
1028  strVal = GetAttrib(strAttribName.c_str());
1029  strVal = Std_Trim(strVal);
1030 
1031  if(Std_IsBlank(strVal))
1032  {
1033  if(bThrowError)
1034  THROW_TEXT_ERROR(Std_Err_lBlankAttrib, Std_Err_strBlankAttrib, ValueErrorString(strVal));
1035  else
1036  return iDefault;
1037  }
1038 
1039  if(!Std_IsNumeric(strVal))
1040  THROW_TEXT_ERROR(Std_Err_lNotNumericType, Std_Err_strNotNumericType, ValueErrorString(strVal));
1041 
1042  if(!Std_IsIntegerType(strVal))
1043  THROW_TEXT_ERROR(Std_Err_lNotIntegerType, Std_Err_strNotIntegerType, ValueErrorString(strVal));
1044 
1045  //Need to add code here to verify it is a number.
1046  return atoi(strVal.c_str());
1047 }
1048 
1061 double CStdXml::GetAttribDouble(std::string strAttribName, bool bThrowError, double dblDefault)
1062 {
1063  std::string strVal;
1064 
1065  strVal = GetAttrib(strAttribName.c_str());
1066  strVal = Std_Trim(strVal);
1067 
1068  if(Std_IsBlank(strVal))
1069  {
1070  if(bThrowError)
1071  THROW_TEXT_ERROR(Std_Err_lBlankAttrib, Std_Err_strBlankAttrib, ValueErrorString(strVal));
1072  else
1073  return dblDefault;
1074  }
1075 
1076  if(!Std_IsNumeric(strVal))
1077  THROW_TEXT_ERROR(Std_Err_lNotNumericType, Std_Err_strNotNumericType, ValueErrorString(strVal));
1078 
1079  //Need to add code here to verify it is a number.
1080  return atof(strVal.c_str());
1081 }
1082 
1095 float CStdXml::GetAttribFloat(std::string strAttribName, bool bThrowError, float fltDefault)
1096 {
1097  std::string strVal;
1098 
1099  strVal = GetAttrib(strAttribName.c_str());
1100  strVal = Std_Trim(strVal);
1101 
1102  if(Std_IsBlank(strVal))
1103  {
1104  if(bThrowError)
1105  THROW_TEXT_ERROR(Std_Err_lBlankAttrib, Std_Err_strBlankAttrib, ValueErrorString(strVal));
1106  else
1107  return fltDefault;
1108  }
1109 
1110  if(!Std_IsNumeric(strVal))
1111  THROW_TEXT_ERROR(Std_Err_lNotNumericType, Std_Err_strNotNumericType, ValueErrorString(strVal));
1112 
1113  //Need to add code here to verify it is a number.
1114  return (float) atof(strVal.c_str());
1115 }
1116 
1129 bool CStdXml::GetAttribBool(std::string strAttribName, bool bThrowError, bool bDefault)
1130 {
1131  std::string strVal;
1132 
1133  strVal = GetAttrib(strAttribName.c_str());
1134  strVal = Std_CheckString(strVal);
1135 
1136  if(Std_IsBlank(strVal))
1137  {
1138  if(bThrowError)
1139  THROW_TEXT_ERROR(Std_Err_lBlankAttrib, Std_Err_strBlankAttrib, ValueErrorString(strVal));
1140  else
1141  return bDefault;
1142  }
1143 
1144  if(strVal == "TRUE" || strVal == "1")
1145  return true;
1146  else if(strVal == "FALSE" || strVal == "0")
1147  return false;
1148  else
1149  THROW_TEXT_ERROR(Std_Err_lNotBoolType, Std_Err_strNotBoolType, ValueErrorString(strVal));
1150 
1151  return false;
1152 }
1153 
1163 void CStdXml::SetAttrib(std::string strAttribName, std::string strData)
1164 {
1165  if(!CMarkupSTL::SetAttrib(strAttribName.c_str(), strData.c_str()))
1166  THROW_PARAM_ERROR(Std_Err_lSettingAttrib, Std_Err_strSettingAttrib, "Attrib", (FullTagPath(false) + "\\" + strAttribName));
1167 }
1168 
1178 void CStdXml::SetAttrib(std::string strAttribName, char cVal)
1179 {
1180  std::ostringstream oStream;
1181  int iVal = (int) cVal;
1182 
1183  oStream << iVal;
1184  SetAttrib(strAttribName, oStream.str());
1185 }
1186 
1196 void CStdXml::SetAttrib(std::string strAttribName, unsigned char cVal)
1197 {
1198  std::ostringstream oStream;
1199  int iVal = (int) cVal;
1200 
1201  oStream << iVal;
1202  SetAttrib(strAttribName, oStream.str());
1203 }
1204 
1214 void CStdXml::SetAttrib(std::string strAttribName, long lVal)
1215 {
1216  std::ostringstream oStream;
1217 
1218  oStream << lVal;
1219  SetAttrib(strAttribName, oStream.str());
1220 }
1221 
1231 void CStdXml::SetAttrib(std::string strAttribName, int iVal)
1232 {
1233  std::ostringstream oStream;
1234 
1235  oStream << iVal;
1236  SetAttrib(strAttribName, oStream.str());
1237 }
1238 
1248 void CStdXml::SetAttrib(std::string strAttribName, double dblVal)
1249 {
1250  std::ostringstream oStream;
1251 
1252  oStream << dblVal;
1253  SetAttrib(strAttribName, oStream.str());
1254 }
1255 
1265 void CStdXml::SetAttrib(std::string strAttribName, float fltVal)
1266 {
1267  std::ostringstream oStream;
1268 
1269  oStream << fltVal;
1270  SetAttrib(strAttribName, oStream.str());
1271 }
1272 
1282 void CStdXml::SetAttrib(std::string strAttribName, bool bVal)
1283 {
1284  std::string strVal;
1285 
1286  if(bVal)
1287  strVal = "True";
1288  else
1289  strVal = "False";
1290 
1291  SetAttrib(strAttribName, strVal);
1292 }
1293 
1307 std::string CStdXml::GetChildAttribString(std::string strAttribName, bool bCanBeBlank, bool bThrowError, std::string strDefault)
1308 {
1309  std::string strVal = GetChildAttrib(strAttribName.c_str());
1310 
1311  if(Std_IsBlank(strVal) && !bCanBeBlank)
1312  {
1313  if(bThrowError)
1314  THROW_TEXT_ERROR(Std_Err_lBlankAttrib, Std_Err_strBlankAttrib, ValueErrorString(strVal));
1315 
1316  strVal = strDefault;
1317  }
1318 
1319  return strVal;
1320 }
1321 
1334 long CStdXml::GetChildAttribLong(std::string strAttribName, bool bThrowError, long lDefault)
1335 {
1336  std::string strVal;
1337 
1338  strVal = GetChildAttrib(strAttribName.c_str());
1339  strVal = Std_Trim(strVal);
1340 
1341  if(!bThrowError && Std_IsBlank(strVal))
1342  return lDefault;
1343 
1344  if(bThrowError && Std_IsBlank(strVal))
1345  THROW_TEXT_ERROR(Std_Err_lBlankAttrib, Std_Err_strBlankAttrib, ValueErrorString(strVal));
1346 
1347  if(!Std_IsNumeric(strVal))
1348  THROW_TEXT_ERROR(Std_Err_lNotNumericType, Std_Err_strNotNumericType, ValueErrorString(strVal));
1349 
1350  if(!Std_IsIntegerType(strVal))
1351  THROW_TEXT_ERROR(Std_Err_lNotIntegerType, Std_Err_strNotIntegerType, ValueErrorString(strVal));
1352 
1353  //Need to add code here to verify it is a number.
1354  return atol(strVal.c_str());
1355 }
1356 
1369 int CStdXml::GetChildAttribInt(std::string strAttribName, bool bThrowError, int iDefault)
1370 {
1371  std::string strVal;
1372 
1373  strVal = GetChildAttrib(strAttribName.c_str());
1374  strVal = Std_Trim(strVal);
1375 
1376  if(!bThrowError && Std_IsBlank(strVal))
1377  return iDefault;
1378 
1379  if(bThrowError && Std_IsBlank(strVal))
1380  THROW_TEXT_ERROR(Std_Err_lBlankAttrib, Std_Err_strBlankAttrib, ValueErrorString(strVal));
1381 
1382  if(!Std_IsNumeric(strVal))
1383  THROW_TEXT_ERROR(Std_Err_lNotNumericType, Std_Err_strNotNumericType, ValueErrorString(strVal));
1384 
1385  if(!Std_IsIntegerType(strVal))
1386  THROW_TEXT_ERROR(Std_Err_lNotIntegerType, Std_Err_strNotIntegerType, ValueErrorString(strVal));
1387 
1388  //Need to add code here to verify it is a number.
1389  return atoi(strVal.c_str());
1390 }
1391 
1404 double CStdXml::GetChildAttribDouble(std::string strAttribName, bool bThrowError, double dblDefault)
1405 {
1406  std::string strVal;
1407 
1408  strVal = GetChildAttrib(strAttribName.c_str());
1409  strVal = Std_Trim(strVal);
1410 
1411  if(!bThrowError && Std_IsBlank(strVal))
1412  return dblDefault;
1413 
1414  if(bThrowError && Std_IsBlank(strVal))
1415  THROW_TEXT_ERROR(Std_Err_lBlankAttrib, Std_Err_strBlankAttrib, ValueErrorString(strVal));
1416 
1417  if(!Std_IsNumeric(strVal))
1418  THROW_TEXT_ERROR(Std_Err_lNotNumericType, Std_Err_strNotNumericType, ValueErrorString(strVal));
1419 
1420  //Need to add code here to verify it is a number.
1421  return atof(strVal.c_str());
1422 }
1423 
1436 float CStdXml::GetChildAttribFloat(std::string strAttribName, bool bThrowError, float fltDefault)
1437 {
1438  std::string strVal;
1439 
1440  strVal = GetChildAttrib(strAttribName.c_str());
1441  strVal = Std_Trim(strVal);
1442 
1443  if(!bThrowError && Std_IsBlank(strVal))
1444  return fltDefault;
1445 
1446  if(bThrowError && Std_IsBlank(strVal))
1447  THROW_TEXT_ERROR(Std_Err_lBlankAttrib, Std_Err_strBlankAttrib, ValueErrorString(strVal));
1448 
1449  if(!Std_IsNumeric(strVal))
1450  THROW_TEXT_ERROR(Std_Err_lNotNumericType, Std_Err_strNotNumericType, ValueErrorString(strVal));
1451 
1452  //Need to add code here to verify it is a number.
1453  return (float) atof(strVal.c_str());
1454 }
1455 
1468 bool CStdXml::GetChildAttribBool(std::string strAttribName, bool bThrowError, bool bDefault)
1469 {
1470  std::string strVal;
1471 
1472  strVal = GetChildAttrib(strAttribName.c_str());
1473  strVal = Std_CheckString(strVal);
1474 
1475  if(!bThrowError && Std_IsBlank(strVal))
1476  return bDefault;
1477 
1478  if(bThrowError && Std_IsBlank(strVal))
1479  THROW_TEXT_ERROR(Std_Err_lBlankAttrib, Std_Err_strBlankAttrib, ValueErrorString(strVal));
1480 
1481  if(strVal == "TRUE" || strVal == "1")
1482  return true;
1483  else if(strVal == "FALSE" || strVal == "0")
1484  return false;
1485  else
1486  THROW_TEXT_ERROR(Std_Err_lNotBoolType, Std_Err_strNotBoolType, ValueErrorString(strVal));
1487 
1488  return false;
1489 }
1490 
1500 void CStdXml::SetChildAttrib(std::string strAttribName, std::string strVal)
1501 {
1502  if(!CMarkupSTL::SetChildAttrib(strAttribName.c_str(), strVal.c_str()))
1503  THROW_PARAM_ERROR(Std_Err_lSettingAttrib, Std_Err_strSettingAttrib, "Attrib", (FullTagPath(false) + "\\" + strAttribName));
1504 }
1505 
1515 void CStdXml::SetChildAttrib(std::string strAttribName, char cVal)
1516 {
1517  std::ostringstream oStream;
1518  int iVal = (int) cVal;
1519 
1520  oStream << iVal;
1521  SetChildAttrib(strAttribName, oStream.str());
1522 }
1523 
1533 void CStdXml::SetChildAttrib(std::string strAttribName, unsigned char cVal)
1534 {
1535  std::ostringstream oStream;
1536  int iVal = (int) cVal;
1537 
1538  oStream << iVal;
1539  SetChildAttrib(strAttribName, oStream.str());
1540 }
1541 
1551 void CStdXml::SetChildAttrib(std::string strAttribName, long lVal)
1552 {
1553  std::ostringstream oStream;
1554 
1555  oStream << lVal;
1556  SetChildAttrib(strAttribName, oStream.str());
1557 }
1558 
1568 void CStdXml::SetChildAttrib(std::string strAttribName, int iVal)
1569 {
1570  std::ostringstream oStream;
1571 
1572  oStream << iVal;
1573  SetChildAttrib(strAttribName, oStream.str());
1574 }
1575 
1585 void CStdXml::SetChildAttrib(std::string strAttribName, double dblVal)
1586 {
1587  std::ostringstream oStream;
1588 
1589  oStream << dblVal;
1590  SetChildAttrib(strAttribName, oStream.str());
1591 }
1592 
1602 void CStdXml::SetChildAttrib(std::string strAttribName, float fltVal)
1603 {
1604  std::ostringstream oStream;
1605 
1606  oStream << fltVal;
1607  SetChildAttrib(strAttribName, oStream.str());
1608 }
1609 
1619 void CStdXml::SetChildAttrib(std::string strAttribName, bool bVal)
1620 {
1621  std::string strVal;
1622 
1623  if(bVal)
1624  strVal = "True";
1625  else
1626  strVal = "False";
1627 
1628  SetChildAttrib(strAttribName, strVal);
1629 }
1630 
1639 void CStdXml::AddChildDoc(std::string &strDoc)
1640 {
1641 
1642  if(!AddChildSubDoc(strDoc.c_str()))
1643  THROW_ERROR(Std_Err_lAddingChildDoc, Std_Err_strAddingChildDoc);
1644 }
1645 
1655 {
1656  return GetChildSubDoc();
1657 }
1658 
1668 {
1669  std::string strTagName;
1670 
1671  OutOfElem();
1672  strTagName = GetTagName();
1673  IntoElem();
1674  return strTagName;
1675 }
1676 
1685 void CStdXml::Load(std::string strFilename)
1686 {
1687  if(Std_IsBlank(strFilename))
1688  THROW_ERROR(Std_Err_lFilenameBlank, Std_Err_strFilenameBlank);
1689 
1690  if(!CMarkupSTL::Load(strFilename.c_str()))
1691  {
1692  if(!Std_IsBlank(m_strError))
1693  {
1694  std::string strError = STR("\nFilename: ") + strFilename + STR("\nReason: ") + m_strError;
1695  THROW_TEXT_ERROR(Std_Err_lOpeningFile, Std_Err_strOpeningFile, strError);
1696  }
1697  else
1698  THROW_PARAM_ERROR(Std_Err_lOpeningFile, Std_Err_strOpeningFile, "Filename", strFilename);
1699 
1700  }
1701 }
1702 
1711 void CStdXml::Save(std::string strFilename)
1712 {
1713  if(Std_IsBlank(strFilename))
1714  THROW_ERROR(Std_Err_lFilenameBlank, Std_Err_strFilenameBlank);
1715 
1716  if(!CMarkupSTL::Save(strFilename.c_str()))
1717  THROW_PARAM_ERROR(Std_Err_lOpeningFile, Std_Err_strOpeningFile, "Filename", strFilename);
1718 }
1719 
1720 } //StdUtils
virtual int GetAttribInt(std::string strAttribName, bool bThrowError=true, int iDefault=0)
Gets an attribute int.
Definition: StdXml.cpp:1024
virtual void Deserialize(std::string &strXml)
Deserializes a string into an xml document.
Definition: StdXml.cpp:162
virtual ~CStdXml()
Destructor.
Definition: StdXml.cpp:29
virtual bool FindChildElement(std::string strElementName, bool fThrowError=true)
Finds a child element by name.
Definition: StdXml.cpp:256
virtual void AddChildCData(std::string strElementName, std::string strCData)
Adds a child CDATA section.
Definition: StdXml.cpp:939
virtual double GetChildAttribDouble(std::string strAttribName, bool bThrowError=true, double dblDefault=0)
Gets a child attribute double.
Definition: StdXml.cpp:1404
virtual float GetChildFloat()
Gets a float value from the currently selected element.
Definition: StdXml.cpp:593
virtual int GetChildInt()
Gets an integer value from the currently selected element.
Definition: StdXml.cpp:429
virtual void Save(std::string strFilename)
Saves am xml data file.
Definition: StdXml.cpp:1711
virtual int GetChildAttribInt(std::string strAttribName, bool bThrowError=true, int iDefault=0)
Gets a child attribute int.
Definition: StdXml.cpp:1369
virtual float GetChildAttribFloat(std::string strAttribName, bool bThrowError=true, float fltDefault=0)
Gets a child attribute float.
Definition: StdXml.cpp:1436
bool Std_IsNumeric(std::string strVal)
Tests if this string is a number.
CStdXml()
Default constructor.
Definition: StdXml.cpp:18
virtual bool FindElement(std::string strElementName, bool fThrowError=true)
Finds an element with the specified name.
Definition: StdXml.cpp:179
virtual void AddChildElement(std::string strElementName)
Adds a child element to current element.
Definition: StdXml.cpp:799
virtual bool IntoElem()
Goes into the next element where the cursor is located.
Definition: StdXml.cpp:42
virtual bool GetChildAttribBool(std::string strAttribName, bool bThrowError=true, bool bDefault=false)
Gets a child attribute bool.
Definition: StdXml.cpp:1468
virtual bool GetAttribBool(std::string strAttribName, bool bThrowError=true, bool bDefault=false)
Gets an attribute bool.
Definition: StdXml.cpp:1129
std::string Std_Trim(std::string strVal)
Trims a string.
virtual void SetChildAttrib(std::string strAttribName, std::string strVal)
Sets a child attribute.
Definition: StdXml.cpp:1500
virtual std::string GetChildDoc()
Gets a child document.
Definition: StdXml.cpp:1654
virtual long GetChildLong()
Gets a long value from the currently selected element.
Definition: StdXml.cpp:344
virtual double GetChildDouble()
Gets a double value from the currently selected element.
Definition: StdXml.cpp:514
virtual void Load(std::string strFilename)
Loads an xml data file.
Definition: StdXml.cpp:1685
virtual bool GetChildBool()
Gets a bool value from the currently selected element.
Definition: StdXml.cpp:672
virtual float GetAttribFloat(std::string strAttribName, bool bThrowError=true, float fltDefault=0)
Gets an attribute float.
Definition: StdXml.cpp:1095
virtual double GetAttribDouble(std::string strAttribName, bool bThrowError=true, double dblDefault=0)
Gets an attribute double.
Definition: StdXml.cpp:1061
virtual std::string GetParentTagName()
Gets the parent tag name.
Definition: StdXml.cpp:1667
Namespace for the standard utility objects.
Definition: MarkupSTL.cpp:19
std::stack< std::string > m_aryTagStack
Stack of tags.
Definition: StdXml.h:23
virtual std::string GetChildAttribString(std::string strAttribName, bool bCanBeBlank=false, bool bThrowError=true, std::string strDefault="")
Gets a child attribute string.
Definition: StdXml.cpp:1307
virtual std::string Serialize()
Serializes the document to a string.
Definition: StdXml.cpp:151
virtual int NumberOfChildren()
Gets the number of children of the current element.
Definition: StdXml.cpp:202
bool Std_IsIntegerType(std::string strVal)
Tests if this string is an integer.
virtual std::string GetAttribString(std::string strAttribName, bool bCanBeBlank=false, bool bThrowError=true, std::string strDefault="")
Gets an attribute string of an element.
Definition: StdXml.cpp:960
virtual std::string ValueErrorString(std::string strValue)
Generates a value error string.
Definition: StdXml.cpp:122
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
Definition: StdXml.cpp:56
bool Std_IsBlank(std::string strVal)
Trims a string and tests if a string is blank.
virtual long GetAttribLong(std::string strAttribName, bool bThrowError=true, long lDefault=0)
Gets an attribute long.
Definition: StdXml.cpp:987
virtual bool IntoChildElement(std::string strElementName, bool bThrowError=true)
Goes into the child element with the specified name.
Definition: StdXml.cpp:278
virtual std::string GetChildString()
Gets a string value from the currently selected element.
Definition: StdXml.cpp:294
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
virtual void SetAttrib(std::string strAttribName, std::string strVal)
Sets an attribute.
Definition: StdXml.cpp:1163
virtual bool FindChildByIndex(int iIndex, bool bThrowError=true)
Finds a child element by index.
Definition: StdXml.cpp:225
virtual long GetChildAttribLong(std::string strAttribName, bool bThrowError=true, long lDefault=0)
Gets a child attribute long.
Definition: StdXml.cpp:1334
virtual std::string FullTagPath(bool bAddChildName=true)
Full tag path.
Definition: StdXml.cpp:73
virtual void AddChildDoc(std::string &strDoc)
Adds a child document.
Definition: StdXml.cpp:1639
virtual void ClearTagStack()
Clears the tag stack.
Definition: StdXml.cpp:135
virtual void AddElement(std::string strElementName, std::string strData="")
Adds an element to current element.
Definition: StdXml.cpp:770