AnimatLab  2
Test
StdUtilFunctions.cpp
Go to the documentation of this file.
1 
7 #include "StdAfx.h"
8 
9 namespace StdUtils
10 {
11 
13 //Error functions
14 
15 /*
16 void STD_UTILS_PORT RelayError(CStdErrorInfo oInfo)
17 {throw oInfo;}
18 
19 
20 void STD_UTILS_PORT ThrowError(long lError, std::string strSource, std::string strError, std::string strValueName, long lVal)
21 {
22  ostringstream oStream;
23 
24  oStream << " " << strValueName << ": " << lVal;
25 
26  ThrowError(lError, strSource, strError, oStream.str());
27 }
28 
29 void STD_UTILS_PORT ThrowError(long lError, std::string strSource, std::string strError, std::string strValueName, double dblVal)
30 {
31  ostringstream oStream;
32 
33  oStream << " " << strValueName << ": " << dblVal;
34 
35  ThrowError(lError, strSource, strError, oStream.str());
36 }
37 
38 void STD_UTILS_PORT ThrowError(long lError, std::string strSource, std::string strError, std::string strValueName, std::string strVal)
39 {
40  strVal = strError + " " + strValueName + ": " + strVal;
41 
42  ThrowError(lError, strSource, strVal);
43 }
44 
45 void STD_UTILS_PORT ThrowError(long lError, std::string strSource, std::string strError, std::string strAddToError)
46 {
47  CStdErrorInfo oInfo;
48 
49  oInfo.m_lError = lError;
50  oInfo.m_strSourceFile = strSource;
51  oInfo.m_strError = strError + strAddToError;
52 
53  Std_TraceMsg(StdLogError, oInfo.m_strError, oInfo.m_strSourceFile, oInfo.m_lSourceLine, true, true);
54 
55  throw oInfo;
56 }
57 */
58 
59 int g_iAppID = 1000;
60 
69 std::string STD_UTILS_PORT Std_CreateAppID()
70 {
71  //Need to make this threadsafe at somet point.
72 
73  g_iAppID++;
74  return STR(g_iAppID);
75 }
76 
87 void AddToErrorCallChain(CStdErrorInfo &oInfo, std::string strSourceFile, long lSourceLine)
88 {
89  if(lSourceLine > 0)
90  {
91  std::ostringstream oStream;
92  oStream << strSourceFile << " (" << lSourceLine << ")";
93  oInfo.m_aryCallChain.Add(oStream.str());
94  }
95 }
96 
111 void STD_UTILS_PORT Std_RelayError(CStdErrorInfo oInfo, std::string strSourceFile, long lSourceLine)
112 {
113  AddToErrorCallChain(oInfo, strSourceFile, lSourceLine);
114  throw oInfo;
115 }
116 
132 void STD_UTILS_PORT Std_ThrowError(long lError, std::string strError, std::string strSourceFile, long lSourceLine,
133  std::string strValueName, unsigned char iVal)
134 {
135  std::ostringstream oStream;
136  oStream << " (" << strValueName << ": " << (int) iVal << ")";
137  Std_ThrowError(lError, strError, strSourceFile, lSourceLine, oStream.str());
138 }
139 
155 void STD_UTILS_PORT Std_ThrowError(long lError, std::string strError, std::string strSourceFile, long lSourceLine,
156  std::string strValueName, unsigned short iVal)
157 {
158  std::ostringstream oStream;
159  oStream << " (" << strValueName << ": " << iVal << ")";
160  Std_ThrowError(lError, strError, strSourceFile, lSourceLine, oStream.str());
161 }
162 
178 void STD_UTILS_PORT Std_ThrowError(long lError, std::string strError, std::string strSourceFile, long lSourceLine,
179  std::string strValueName, int iVal)
180 {
181  std::ostringstream oStream;
182  oStream << " (" << strValueName << ": " << iVal << ")";
183  Std_ThrowError(lError, strError, strSourceFile, lSourceLine, oStream.str());
184 }
185 
201 void STD_UTILS_PORT Std_ThrowError(long lError, std::string strError, std::string strSourceFile, long lSourceLine,
202  std::string strValueName, long lVal)
203 {
204  std::ostringstream oStream;
205  oStream << " (" << strValueName << ": " << lVal << ")";
206  Std_ThrowError(lError, strError, strSourceFile, lSourceLine, oStream.str());
207 }
208 
224 void STD_UTILS_PORT Std_ThrowError(long lError, std::string strError, std::string strSourceFile, long lSourceLine,
225  std::string strValueName, float fltVal)
226 {
227  std::ostringstream oStream;
228  oStream << " (" << strValueName << ": " << fltVal << ")";
229  Std_ThrowError(lError, strError, strSourceFile, lSourceLine, oStream.str());
230 }
231 
247 void STD_UTILS_PORT Std_ThrowError(long lError, std::string strError, std::string strSourceFile, long lSourceLine,
248  std::string strValueName, double dblVal)
249 {
250  std::ostringstream oStream;
251  oStream << " (" << strValueName << ": " << dblVal << ")";
252  Std_ThrowError(lError, strError, strSourceFile, lSourceLine, oStream.str());
253 }
254 
270 void STD_UTILS_PORT Std_ThrowError(long lError, std::string strError, std::string strSourceFile, long lSourceLine,
271  std::string strValueName, std::string strVal)
272 {
273  std::ostringstream oStream;
274  oStream << " (" << strValueName << ": " << strVal << ")";
275  Std_ThrowError(lError, strError, strSourceFile, lSourceLine, oStream.str());
276 }
277 
294 void STD_UTILS_PORT Std_ThrowError(long lError, std::string strError, std::string strSourceFile, long lSourceLine,
295  std::string strText)
296 {
297  CStdErrorInfo oInfo;
298 
299  oInfo.m_lError = lError;
300  oInfo.m_strError = strError + strText;
301  oInfo.m_strSourceFile = strSourceFile;
302  oInfo.m_lSourceLine = lSourceLine;
303 
304  AddToErrorCallChain(oInfo, strSourceFile, lSourceLine);
305 
306  Std_TraceMsg(StdLogError, oInfo.m_strError, oInfo.m_strSourceFile, oInfo.m_lSourceLine, true, true);
307 
308  throw oInfo;
309 }
310 
321 std::string STD_UTILS_PORT Std_ToStr(std::string strVal)
322 {return strVal;}
323 
334 std::string STD_UTILS_PORT Std_ToStr(const char *strVal)
335 {
336  std::string strV = strVal;
337  return strV;
338 }
339 
350 std::string STD_UTILS_PORT Std_ToStr(unsigned char iVal)
351 {
352  std::ostringstream buf;
353  buf << iVal ;
354  std::string str = buf.str() ;
355  return str;
356 }
357 
368 std::string STD_UTILS_PORT Std_ToStr(unsigned short iVal)
369 {
370  std::ostringstream buf;
371  buf << iVal ;
372  std::string str = buf.str() ;
373  return str;
374 }
375 
386 std::string STD_UTILS_PORT Std_ToStr(int iVal)
387 {
388  std::ostringstream buf;
389  buf << iVal ;
390  std::string str = buf.str() ;
391  return str;
392 }
393 
404 std::string STD_UTILS_PORT Std_ToStr(unsigned int iVal)
405 {
406  std::ostringstream buf;
407  buf << iVal ;
408  std::string str = buf.str() ;
409  return str;
410 }
411 
422 std::string STD_UTILS_PORT Std_ToStr(long lVal)
423 {
424  std::ostringstream buf;
425  buf << lVal ;
426  std::string str = buf.str() ;
427  return str;
428 }
429 
440 std::string STD_UTILS_PORT Std_ToStr(unsigned long lVal)
441 {
442  std::ostringstream buf;
443  buf << lVal ;
444  std::string str = buf.str() ;
445  return str;
446 }
447 
458 std::string STD_UTILS_PORT Std_ToStr(float fltVal)
459 {
460  std::ostringstream buf;
461  buf << fltVal ;
462  std::string str = buf.str() ;
463  return str;
464 }
465 
476 std::string STD_UTILS_PORT Std_ToStr(double dblVal)
477 {
478  std::ostringstream buf;
479  buf << dblVal ;
480  std::string str = buf.str() ;
481  return str;
482 }
483 
494 std::string STD_UTILS_PORT Std_ToStr(bool bVal)
495 {
496  if(bVal)
497  return "True";
498  else
499  return "False";
500 }
501 
513 std::string STD_UTILS_PORT Std_ToStr(std::string strFormat, unsigned char iVal)
514 {return str(boost::format("%d") % iVal);}
515 
527 std::string STD_UTILS_PORT Std_ToStr(std::string strFormat, unsigned short iVal)
528 {return str(boost::format("%d") % iVal);}
529 
541 std::string STD_UTILS_PORT Std_ToStr(std::string strFormat, int iVal)
542 {return str(boost::format("%d") % iVal);}
543 
555 std::string STD_UTILS_PORT Std_ToStr(std::string strFormat, long lVal)
556 {return str(boost::format("%d") % lVal);}
557 
569 std::string STD_UTILS_PORT Std_ToStr(std::string strFormat, float fltVal)
570 {return str(boost::format("%f") % fltVal);}
571 
583 std::string STD_UTILS_PORT Std_ToStr(std::string strFormat, double dblVal)
584 {return str(boost::format("%f") % dblVal);}
585 
596 bool STD_UTILS_PORT Std_ToBool(int iVal)
597 {
598  if(iVal)
599  return true;
600  else
601  return false;
602 }
603 
614 bool STD_UTILS_PORT Std_ToBool(std::string strVal)
615 {
616  std::string strV = Std_ToUpper(Std_Trim(strVal));
617 
618  if(strV == "TRUE" || strV == "1")
619  return true;
620  else
621  return false;
622 }
623 
634 std::string STD_UTILS_PORT Std_NullStr(std::string strFormat)
635 {
636  if(strFormat.length())
637  return ("'" + strFormat + "'");
638  else
639  return "NULL";
640 }
641 
642 #ifdef WIN32
643 
654 std::string STD_UTILS_PORT Std_ConvertToANSI(LPCWSTR strData)
655 {
656  // len will hold the required length of converted string
657  int len = WideCharToMultiByte(CP_ACP, 0, strData, -1, 0, 0, 0, 0);
658  // allocate the buffer to hold the converted string
659  LPSTR result = new char[len];
660  // do the conversion
661  WideCharToMultiByte(CP_ACP, 0, strData, -1, result, len, 0, 0);
662 
663  std::string strVal = result;
664  if(result)
665  delete[] result;
666 
667  return strVal;
668 }
669 
680 LPWSTR STD_UTILS_PORT Std_ConvertFromANSI(std::string strData)
681 {
682  // len will hold the required length of converted string
683  int len = MultiByteToWideChar(CP_ACP, 0, strData.c_str(), -1, 0, 0);
684  // allocate the buffer to hold the converted string
685  wchar_t *result = new wchar_t[len];
686  // do the conversion
687  MultiByteToWideChar(CP_ACP, 0, strData.c_str(), -1, result, len);
688 
689  return result;
690 }
691 #endif
692 
703 int STD_UTILS_PORT Std_VariantTypeToConst(std::string strType)
704 {
705 
706  strType = Std_Trim(Std_ToUpper(strType));
707 
708  if(strType == "EMPTY")
709  return StdVtEmpty;
710  else if(strType == "SHORT")
711  return StdVtShort;
712  else if(strType == "LONG")
713  return StdVtLong;
714  else if(strType == "FLOAT")
715  return StdVtFloat;
716  else if(strType == "DOUBLE")
717  return StdVtDouble;
718  else if(strType == "bool")
719  return StdVtBool;
720  else if(strType == "CHAR")
721  return StdVtChar;
722  else if(strType == "UCHAR")
723  return StdVtUChar;
724  else if(strType == "USHORT")
725  return StdVtUShort;
726  else if(strType == "ULONG")
727  return StdVtULong;
728  else if(strType == "INT")
729  return StdVtInt;
730  else if(strType == "UINT")
731  return StdVtUInt;
732  else if(strType == "STRING")
733  return StdVtString;
734  else
735  THROW_PARAM_ERROR(Std_Err_lInvalidVariantType, Std_Err_strInvalidVariantType, "VariantType", strType);
736 
737  return -1;
738 }
739 
750 std::string STD_UTILS_PORT Std_ConstToVariantType(int iType)
751 {
752  switch(iType)
753  {
754  case StdVtEmpty:
755  return "Empty";
756  case StdVtShort:
757  return "Short";
758  case StdVtLong:
759  return "Long";
760  case StdVtFloat:
761  return "Float";
762  case StdVtBool:
763  return "Bool";
764  case StdVtChar:
765  return "Char";
766  case StdVtUChar:
767  return "UChar";
768  case StdVtUShort:
769  return "UShort";
770  case StdVtULong:
771  return "ULong";
772  case StdVtInt:
773  return "Int";
774  case StdVtUInt:
775  return "UInt";
776  case StdVtString:
777  return "String";
778 
779  default:
780  THROW_PARAM_ERROR(Std_Err_lInvalidVariantType, Std_Err_strInvalidVariantType, "VariantType", iType);
781  }
782 
783  return "";
784 }
785 
798 int STD_UTILS_PORT Std_Split(const std::string& input, const std::string& delimiter, CStdArray<std::string> &results)
799 {
800  int iPos = 0;
801  int newPos = -1;
802  int sizeS2 = delimiter.size();
803  int isize = input.size();
804 
805  std::vector<int> positions;
806  results.RemoveAll();
807 
808  newPos = input.find (delimiter, 0);
809 
810  if( newPos < 0 )
811  {
812  std::string strInput = input;
813 
814  if(!Std_IsBlank(input))
815  {
816  strInput = Std_Trim(strInput);
817  results.push_back(strInput);
818  return 1;
819  }
820  else
821  return 0;
822  }
823 
824  int numFound = 0;
825 
826  while( newPos > iPos )
827  {
828  numFound++;
829  positions.push_back(newPos);
830  iPos = newPos;
831  newPos = input.find (delimiter, iPos+sizeS2+1);
832  }
833 
834  for( int i=0; i <= positions.size(); i++ )
835  {
836  std::string s;
837  if( i == 0 )
838  {s = input.substr( i, positions[i] ); }
839  else
840  {
841  int offset = positions[i-1] + sizeS2;
842  if( offset < isize )
843  {
844  if( i == positions.size() )
845  {
846  s = input.substr(offset);
847  }
848  else if( i > 0 )
849  {
850  s = input.substr( positions[i-1] + sizeS2, positions[i] - positions[i-1] - sizeS2 );
851  }
852  }
853  }
854 
855  if( s.size() > 0 )
856  {
857  results.push_back(s);
858  }
859  }
860  return results.GetSize();
861 }
862 
874 std::string STD_UTILS_PORT Std_Combine(CStdArray<std::string> &aryParts, std::string strDelimiter)
875 {
876  std::string strCombined;
877  int iCount = aryParts.GetSize();
878  for(int iPart=0; iPart<iCount; iPart++)
879  {
880  strCombined += aryParts[iPart];
881  if(iPart<iCount-1) strCombined += strDelimiter;
882  }
883 
884  return strCombined;
885 }
886 
897 std::string STD_UTILS_PORT Std_Trim(std::string strVal)
898 {
899  return Std_TrimLeft(Std_TrimRight(strVal));
900 }
901 
912 bool NotSpace(char c)
913 {return !std::isspace(c);}
914 
925 std::string STD_UTILS_PORT Std_TrimLeft(std::string strVal)
926 {
927  strVal.erase(strVal.begin(), std::find_if(strVal.begin(), strVal.end(), NotSpace));
928  return strVal;
929 }
930 
941 std::string STD_UTILS_PORT Std_TrimRight(std::string strVal)
942 {
943  // NOTE: When comparing reverse_iterators here (MYRITER), I avoid using
944  // operator!=. This is because namespace rel_ops also has a template
945  // operator!= which conflicts with the global operator!= already defined
946  // for reverse_iterator in the header <utility>.
947  // Thanks to John James for alerting me to this.
948 
949  std::string::reverse_iterator it = std::find_if(strVal.rbegin(), strVal.rend(), NotSpace);
950  if ( !(strVal.rend() == it) )
951  strVal.erase(strVal.rend() - it);
952 
953  strVal.erase(!(it == strVal.rend()) ? strVal.find_last_of(*it) + 1 : 0);
954  return strVal;
955 }
956 
967 bool STD_UTILS_PORT Std_IsNumeric(std::string strVal)
968 {
969  int iPos = strVal.find_first_not_of("0123456789.+-eE");
970  if(iPos == -1 && strVal.length() > 0)
971  return true;
972  else
973  return false;
974 }
975 
986 bool STD_UTILS_PORT Std_IsIntegerType(std::string strVal)
987 {
988  int iPos = strVal.find_first_not_of("0123456789+-");
989  if(iPos == -1)
990  return true;
991  else
992  return false;
993 }
994 
1006 std::string STD_UTILS_PORT Std_Left(std::string strVal, int iCount)
1007 {
1008  iCount = SSMAX(0, SSMIN(iCount, static_cast<int>(strVal.length())));
1009  return strVal.substr(0, iCount);
1010 }
1011 
1023 std::string STD_UTILS_PORT Std_Right(std::string strVal, int iCount)
1024 {
1025  iCount = SSMAX(0, SSMIN(iCount, static_cast<int>(strVal.length())));
1026  return strVal.substr(strVal.length()-iCount);
1027 }
1028 
1039 std::string STD_UTILS_PORT Std_ToUpper(std::string strVal)
1040 {
1041  std::transform(strVal.begin(), strVal.end(), strVal.begin(), (int(*)(int))std::toupper);
1042  return strVal;
1043 }
1044 
1055 std::string STD_UTILS_PORT Std_ToLower(std::string strVal)
1056 {
1057  std::transform(strVal.begin(), strVal.end(), strVal.begin(), (int(*)(int))std::tolower);
1058  return strVal;
1059 }
1060 
1073 std::string STD_UTILS_PORT Std_Replace(std::string strVal, std::string strFind, std::string strReplace)
1074 {
1075  int i = strVal.find(strFind, 0);
1076  while(i != std::string::npos)
1077  {
1078  strVal.replace(i, strFind.size(), strReplace);
1079  i = strVal.find(strFind, 0);
1080  }
1081  return strVal;
1082 }
1083 
1096 long STD_UTILS_PORT Std_RGB(unsigned char iRed, unsigned char iGreen, unsigned char iBlue)
1097 {
1098  return ((iBlue << 16) | (iGreen << 8) | (iRed));
1099 }
1100 
1101 
1115 long STD_UTILS_PORT Std_LoadRGB(CStdXml &oXml, std::string strParamName, bool bThrowError, long lDefault)
1116 {
1117  long lVal=0;
1118 
1119  if(oXml.FindChildElement(strParamName, bThrowError))
1120  {
1121  int iRed = oXml.GetChildAttribInt("Red");
1122  Std_InValidRange((int) 0, (int) 255, iRed, true, (strParamName + "::Red"));
1123 
1124  int iGreen = oXml.GetChildAttribInt("Green");
1125  Std_InValidRange((int) 0, (int) 255, iGreen, true, (strParamName + "::Green"));
1126 
1127  int iBlue = oXml.GetChildAttribInt("Blue");
1128  Std_InValidRange((int) 0, (int) 255, iBlue, true, (strParamName + "::Blue"));
1129 
1130  lVal = Std_RGB(iRed, iGreen, iBlue);
1131  }
1132  else
1133  lVal = lDefault;
1134 
1135  return lVal;
1136 }
1137 
1150 void STD_UTILS_PORT Std_LoadColor(CStdXml &oXml, std::string strParamName, float *aryColor, bool bThrowError)
1151 {
1152  if(oXml.FindChildElement(strParamName, bThrowError))
1153  {
1154  oXml.IntoChildElement(strParamName);
1155  aryColor[0] = oXml.GetAttribFloat("Red");
1156  aryColor[1] = oXml.GetAttribFloat("Green");
1157  aryColor[2] = oXml.GetAttribFloat("Blue");
1158  aryColor[3] = oXml.GetAttribFloat("Alpha");
1159  oXml.OutOfElem();
1160  }
1161  else if(bThrowError)
1162  THROW_TEXT_ERROR(Std_Err_lParamNotFound, Std_Err_strParamNotFound, strParamName);
1163  else
1164  {
1165  aryColor[0] = 1;
1166  aryColor[1] = 1;
1167  aryColor[2] = 1;
1168  aryColor[3] = 1;
1169  }
1170 
1171  Std_InValidRange((float) 0, (float) 1, aryColor[0], bThrowError, strParamName);
1172  Std_InValidRange((float) 0, (float) 1, aryColor[1], bThrowError, strParamName);
1173  Std_InValidRange((float) 0, (float) 1, aryColor[2], bThrowError, strParamName);
1174  Std_InValidRange((float) 0, (float) 1, aryColor[3], bThrowError, strParamName);
1175 }
1176 
1189 void STD_UTILS_PORT Std_LoadColor(std::string strXml, std::string strParamName, float *aryColor, bool bThrowError)
1190 {
1191  CStdXml oXml;
1192  oXml.Deserialize(strXml);
1193  oXml.FindElement("Root");
1194  oXml.FindChildElement(strParamName);
1195 
1196  Std_LoadColor(oXml, strParamName, aryColor, bThrowError);
1197 }
1198 
1209 int STD_UTILS_PORT Std_Sign(float fltVal)
1210 {
1211  if(fltVal<0)
1212  return -1;
1213  else if(fltVal==0)
1214  return 0;
1215  else
1216  return 1;
1217 }
1218 
1229 int STD_UTILS_PORT Std_Sign(float fltVal, float fltDefault)
1230 {
1231  if(fltVal<0)
1232  return -1;
1233  else if(fltVal==0)
1234  return fltDefault;
1235  else
1236  return 1;
1237 }
1238 
1239 void init_genrand(unsigned long s);
1240 unsigned long genrand_int32(void);
1241 long genrand_int31(void);
1242 double genrand_real1(void);
1243 double genrand_real2(void);
1244 double genrand_real3(void);
1245 double genrand_res53(void);
1246 
1255 void STD_UTILS_PORT Std_SRand(unsigned long lSeed)
1256 {init_genrand(lSeed);}
1257 
1269 int STD_UTILS_PORT Std_IRand( int low, int high )
1270 {
1271  high++;
1272  return (int) (( abs(high-low) * genrand_real2() ) + low);
1273 }
1274 
1275 
1287 long STD_UTILS_PORT Std_LRand( long low, long high )
1288 {
1289  high++;
1290  return (long) (( abs(high-low) * genrand_real2() ) + low);
1291 }
1292 
1293 
1305 float STD_UTILS_PORT Std_FRand( float low, float high )
1306 {return (float) (( fabs(high-low) * genrand_real1() ) + low);}
1307 
1308 
1320 double STD_UTILS_PORT Std_DRand( double low, double high )
1321 {return (( fabs(high-low) * genrand_real1() ) + low);}
1322 
1337 bool STD_UTILS_PORT Std_InValidRange(int iMinVal, int iMaxVal, int iVal, bool bThrowError, std::string strParamName)
1338 {
1339 
1340  if( (iVal>=iMinVal) && (iVal<=iMaxVal) )
1341  return true;
1342  else
1343  {
1344  if(bThrowError)
1345  {
1346  std::ostringstream oss;
1347 
1348  if(!strParamName.empty())
1349  oss << "Paramater: " << strParamName;
1350 
1351  oss << " Value: " << iVal << " Range [";
1352  oss << iMinVal << ", " << iMaxVal << "]";
1353 
1354  THROW_TEXT_ERROR(Std_Err_lValueOutOfRange, Std_Err_strValueOutOfRange, oss.str().c_str());
1355  }
1356 
1357  return false;
1358  }
1359 
1360 }
1361 
1376 bool STD_UTILS_PORT Std_InValidRange(long lMinVal, long lMaxVal, long lVal, bool bThrowError, std::string strParamName)
1377 {
1378 
1379  if( (lVal>=lMinVal) && (lVal<=lMaxVal) )
1380  return true;
1381  else
1382  {
1383  if(bThrowError)
1384  {
1385  std::ostringstream oss;
1386 
1387  if(!strParamName.empty())
1388  oss << "Paramater: " << strParamName;
1389 
1390  oss << " Value: " << lVal << " Range [";
1391  oss << lMinVal << ", " << lMaxVal << "]";
1392 
1393  THROW_TEXT_ERROR(Std_Err_lValueOutOfRange, Std_Err_strValueOutOfRange, oss.str().c_str());
1394  }
1395 
1396  return false;
1397  }
1398 
1399 }
1400 
1415 bool STD_UTILS_PORT Std_InValidRange(float fltMinVal, float fltMaxVal, float fltVal, bool bThrowError, std::string strParamName)
1416 {
1417 
1418  if( (fltVal>=fltMinVal) && (fltVal<=fltMaxVal) )
1419  return true;
1420  else
1421  {
1422  if(bThrowError)
1423  {
1424  std::ostringstream oss;
1425 
1426  if(!strParamName.empty())
1427  oss << "Paramater: " << strParamName;
1428 
1429  oss << " Value: " << fltVal << " Range [";
1430  oss << fltMinVal << ", " << fltMaxVal << "]";
1431 
1432  THROW_TEXT_ERROR(Std_Err_lValueOutOfRange, Std_Err_strValueOutOfRange, oss.str().c_str());
1433  }
1434 
1435  return false;
1436  }
1437 
1438 }
1439 
1454 bool STD_UTILS_PORT Std_InValidRange(double dblMinVal, double dblMaxVal, double dblVal, bool bThrowError, std::string strParamName)
1455 {
1456 
1457  if( (dblVal>=dblMinVal) && (dblVal<=dblMaxVal) )
1458  return true;
1459  else
1460  {
1461  if(bThrowError)
1462  {
1463  std::ostringstream oss;
1464 
1465  if(!strParamName.empty())
1466  oss << "Paramater: " << strParamName;
1467 
1468  oss << " Value: " << dblVal << " Range [";
1469  oss << dblMinVal << ", " << dblMaxVal << "]";
1470 
1471  THROW_TEXT_ERROR(Std_Err_lValueOutOfRange, Std_Err_strValueOutOfRange, oss.str().c_str());
1472  }
1473 
1474  return false;
1475  }
1476 
1477 }
1478 
1493 bool STD_UTILS_PORT Std_IsBelowMax(int iMaxVal, int iVal, bool bThrowError, std::string strParamName, bool bInclusiveLimit)
1494 {
1495 
1496  if( (!bInclusiveLimit && iVal<iMaxVal) || (bInclusiveLimit && iVal<=iMaxVal) )
1497  return true;
1498  else
1499  {
1500  if(bThrowError)
1501  {
1502  std::ostringstream oss;
1503 
1504  if(!strParamName.empty())
1505  oss << "Paramater: " << strParamName;
1506 
1507  oss << " Value: " << iVal << " Maximum: " << iMaxVal;
1508 
1509  THROW_TEXT_ERROR(Std_Err_lAboveMaxValue, Std_Err_strAboveMaxValue, oss.str().c_str());
1510  }
1511 
1512  return false;
1513  }
1514 
1515 }
1516 
1531 bool STD_UTILS_PORT Std_IsBelowMax(long lMaxVal, long lVal, bool bThrowError, std::string strParamName, bool bInclusiveLimit)
1532 {
1533 
1534  if( (!bInclusiveLimit && lVal<lMaxVal) || (bInclusiveLimit && lVal<=lMaxVal) )
1535  return true;
1536  else
1537  {
1538  if(bThrowError)
1539  {
1540  std::ostringstream oss;
1541 
1542  if(!strParamName.empty())
1543  oss << "Paramater: " << strParamName;
1544 
1545  oss << " Value: " << lVal << " Maximum: " << lMaxVal;
1546 
1547  THROW_TEXT_ERROR(Std_Err_lAboveMaxValue, Std_Err_strAboveMaxValue, oss.str().c_str());
1548  }
1549 
1550  return false;
1551  }
1552 
1553 }
1554 
1569 bool STD_UTILS_PORT Std_IsBelowMax(float fltMaxVal, float fltVal, bool bThrowError, std::string strParamName, bool bInclusiveLimit)
1570 {
1571 
1572  if( (!bInclusiveLimit && fltVal<fltMaxVal) || (bInclusiveLimit && fltVal<=fltMaxVal) )
1573  return true;
1574  else
1575  {
1576  if(bThrowError)
1577  {
1578  std::ostringstream oss;
1579 
1580  if(!strParamName.empty())
1581  oss << "Paramater: " << strParamName;
1582 
1583  oss << " Value: " << fltVal << " Maximum: " << fltMaxVal;
1584 
1585  THROW_TEXT_ERROR(Std_Err_lAboveMaxValue, Std_Err_strAboveMaxValue, oss.str().c_str());
1586  }
1587 
1588  return false;
1589  }
1590 
1591 }
1592 
1607 bool STD_UTILS_PORT Std_IsBelowMax(double dblMaxVal, double dblVal, bool bThrowError, std::string strParamName, bool bInclusiveLimit)
1608 {
1609 
1610  if( (!bInclusiveLimit && dblVal<dblMaxVal) || (bInclusiveLimit && dblVal<=dblMaxVal) )
1611  return true;
1612  else
1613  {
1614  if(bThrowError)
1615  {
1616  std::ostringstream oss;
1617 
1618  if(!strParamName.empty())
1619  oss << "Paramater: " << strParamName;
1620 
1621  oss << " Value: " << dblVal << " Maximum: " << dblMaxVal;
1622 
1623  THROW_TEXT_ERROR(Std_Err_lAboveMaxValue, Std_Err_strAboveMaxValue, oss.str().c_str());
1624  }
1625 
1626  return false;
1627  }
1628 
1629 }
1630 
1645 bool STD_UTILS_PORT Std_IsAboveMin(int iMinVal, int iVal, bool bThrowError, std::string strParamName, bool bInclusiveLimit)
1646 {
1647 
1648  if( (!bInclusiveLimit && iVal>iMinVal) || (bInclusiveLimit && iVal>=iMinVal) )
1649  return true;
1650  else
1651  {
1652  if(bThrowError)
1653  {
1654  std::ostringstream oss;
1655 
1656  if(!strParamName.empty())
1657  oss << "Paramater: " << strParamName;
1658 
1659  oss << " Value: " << iVal << " Minimum: " << iMinVal;
1660 
1661  THROW_TEXT_ERROR(Std_Err_lBelowMinValue, Std_Err_strBelowMinValue, oss.str().c_str());
1662  }
1663 
1664  return false;
1665  }
1666 
1667 }
1668 
1683 bool STD_UTILS_PORT Std_IsAboveMin(long lMinVal, long lVal, bool bThrowError, std::string strParamName, bool bInclusiveLimit)
1684 {
1685 
1686  if( (!bInclusiveLimit && lVal>lMinVal) || (bInclusiveLimit && lVal>=lMinVal) )
1687  return true;
1688  else
1689  {
1690  if(bThrowError)
1691  {
1692  std::ostringstream oss;
1693 
1694  if(!strParamName.empty())
1695  oss << "Paramater: " << strParamName;
1696 
1697  oss << " Value: " << lVal << " Minimum: " << lMinVal;
1698 
1699  THROW_TEXT_ERROR(Std_Err_lBelowMinValue, Std_Err_strBelowMinValue, oss.str().c_str());
1700  }
1701 
1702  return false;
1703  }
1704 
1705 }
1706 
1721 bool STD_UTILS_PORT Std_IsAboveMin(float fltMinVal, float fltVal, bool bThrowError, std::string strParamName, bool bInclusiveLimit)
1722 {
1723 
1724  if( (!bInclusiveLimit && fltVal>fltMinVal) || (bInclusiveLimit && fltVal>=fltMinVal) )
1725  return true;
1726  else
1727  {
1728  if(bThrowError)
1729  {
1730  std::ostringstream oss;
1731 
1732  if(!strParamName.empty())
1733  oss << "Paramater: " << strParamName;
1734 
1735  oss << " Value: " << fltVal << " Minimum: " << fltMinVal;
1736 
1737  THROW_TEXT_ERROR(Std_Err_lBelowMinValue, Std_Err_strBelowMinValue, oss.str().c_str());
1738  }
1739 
1740  return false;
1741  }
1742 
1743 }
1744 
1759 bool STD_UTILS_PORT Std_IsAboveMin(double dblMinVal, double dblVal, bool bThrowError, std::string strParamName, bool bInclusiveLimit)
1760 {
1761 
1762  if( (!bInclusiveLimit && dblVal>dblMinVal) || (bInclusiveLimit && dblVal>=dblMinVal) )
1763  return true;
1764  else
1765  {
1766  if(bThrowError)
1767  {
1768  std::ostringstream oss;
1769 
1770  if(!strParamName.empty())
1771  oss << "Paramater: " << strParamName;
1772 
1773  oss << " Value: " << dblVal << " Minimum: " << dblMinVal;
1774 
1775  THROW_TEXT_ERROR(Std_Err_lBelowMinValue, Std_Err_strBelowMinValue, oss.str().c_str());
1776  }
1777 
1778  return false;
1779  }
1780 
1781 }
1782 
1793 std::string STD_UTILS_PORT Std_CheckString(std::string strVal)
1794 {
1795  std::string strTemp = strVal;
1796  strTemp = Std_ToUpper(Std_Trim(strTemp));
1797  return strTemp;
1798 }
1799 
1810 bool STD_UTILS_PORT Std_IsBlank(std::string strVal)
1811 {
1812  std::string strTemp = Std_Trim(strVal);
1813  if(!strTemp.length())
1814  return true;
1815  else
1816  return false;
1817 }
1818 
1819 
1820 std::string STD_UTILS_PORT Std_RetrieveParam(int argc, const char **argv, std::string strParamName, bool bThrowError)
1821 {
1822  int iParam=0;
1823  bool bRetrieved=false, bFound = false;
1824  std::string strParam="", strFound ="";
1825  while(!bRetrieved && iParam<argc)
1826  {
1827  strParam = Std_ToUpper(Std_Trim(argv[iParam]));
1828 
1829  if(bFound)
1830  {
1831  strFound = Std_Trim(argv[iParam]);
1832  bRetrieved = true;
1833  }
1834 
1835  if(strParam == strParamName)
1836  bFound = true;
1837 
1838  iParam++;
1839  }
1840 
1841  if(bThrowError && !bRetrieved)
1842  THROW_PARAM_ERROR(Std_Err_lNoProjectParamOnCommandLine, Std_Err_strNoProjectParamOnCommandLine, "Param", strParamName);
1843 
1844  return strFound;
1845 }
1846 
1847 //***************************************************************************************************************
1848 // Byte Array Functions
1849 
1850 // bit_get (x,i) is the value of bit i of x
1851 
1863 unsigned long bit_get (unsigned long x, int i)
1864 {return ( x >> i) & 1;}
1865 
1866 
1867 // bit_put (x, i, v) returns the same as x except that bit i is
1868 // set to the same value as bit 0 of v.
1869 
1882 unsigned long bit_put (unsigned long x, int i, unsigned long v)
1883 {
1884  if ( v & 1 ) {
1885  return x | (1 << i);
1886  } else {
1887  return x & ~(1 << i);
1888  }
1889 }
1890 
1901 std::string STD_UTILS_PORT Std_ByteArrayToHexString(CStdArray<unsigned char> &aryBytes)
1902 {
1903  std::string strHex;
1904  Std_ByteArrayToHexString(aryBytes, strHex);
1905  return strHex;
1906 }
1907 
1918 void STD_UTILS_PORT Std_ByteArrayToHexString(CStdArray<unsigned char> &aryBytes, std::string &strHex)
1919 {
1920  std::string strByte;
1921  int iByte, iByteLength;
1922 
1923  strHex = "";
1924  iByteLength = aryBytes.GetSize();
1925 
1926  for(iByte=0; iByte<iByteLength; iByte++)
1927  {
1928  str(boost::format("%02x") % aryBytes[iByte]);
1929  strHex += strByte;
1930  }
1931 
1932 }
1933 
1943 void STD_UTILS_PORT Std_HexStringToByteArray(std::string strHex, CStdArray<unsigned char> &aryBytes)
1944 {
1945  int iLength, iByteSize, iNibble0, iNibble1, iByte;
1946  unsigned char cVal;
1947 
1948  aryBytes.RemoveAll();
1949 
1950  iLength = strHex.length();
1951  iByteSize = iLength / 2;
1952  aryBytes.SetSize(iByteSize);
1953 
1954  for(iByte=0; iByte<iByteSize; iByte++)
1955  {
1956  iNibble0 = iByte*2;
1957  iNibble1 = (iByte*2) + 1;
1958 
1959  cVal = (Std_HexCharToByte(strHex[iNibble0]) << 4) + Std_HexCharToByte(strHex[iNibble1]);
1960  aryBytes[iByte] = cVal;
1961  }
1962 }
1963 
1975 unsigned char STD_UTILS_PORT *Std_HexStringToByteArray(std::string strHex, long &lArraySize)
1976 {
1977  int iLength, iByteSize, iNibble0, iNibble1, iByte;
1978  unsigned char cVal;
1979  unsigned char *lpBytes = NULL;
1980 
1981  iLength = strHex.length();
1982  iByteSize = iLength / 2;
1983 
1984  lpBytes = new unsigned char[iByteSize];
1985 
1986  for(iByte=0; iByte<iByteSize; iByte++)
1987  {
1988  iNibble0 = iByte*2;
1989  iNibble1 = (iByte*2) + 1;
1990 
1991  cVal = (Std_HexCharToByte(strHex[iNibble0]) << 4) + Std_HexCharToByte(strHex[iNibble1]);
1992  lpBytes[iByte] = cVal;
1993  }
1994 
1995  return lpBytes;
1996 }
1997 
2008 unsigned char STD_UTILS_PORT Std_HexToByte(std::string strVal)
2009 {
2010  unsigned char cVal;
2011 
2012  if(!(strVal.length() == 2 || (strVal.length() == 4 && Std_ToUpper(Std_Left(strVal, 2)) == "0X")))
2013  THROW_PARAM_ERROR(Std_Err_lInvalidHexChar, Std_Err_strInvalidHexChar, "HexValue", strVal);
2014 
2015  if(strVal.length() == 4 && Std_ToUpper(Std_Left(strVal, 2)) == "0X")
2016  strVal = Std_Right(strVal, 2);
2017 
2018  cVal = (Std_HexCharToByte(strVal[1]) << 4) + Std_HexCharToByte(strVal[0]);
2019 
2020  return cVal;
2021 }
2022 
2033 unsigned char STD_UTILS_PORT Std_HexCharToByte(char cVal)
2034 {
2035  if (cVal >= '0' && cVal <= '9')
2036  return (cVal - '0');
2037 
2038  if (cVal >= 'A' && cVal <= 'F')
2039  return ((cVal - 'A') + 0x0A);
2040 
2041  //if we get here then it is an invalid character sequence.
2042  std::string strVal;
2043  strVal = cVal;
2044  THROW_PARAM_ERROR(Std_Err_lInvalidHexChar, Std_Err_strInvalidHexChar, "HexValue", strVal);
2045  return 0;
2046 }
2047 
2048 
2049 
2050 
2061 long STD_UTILS_PORT Std_GetBitSize(CStdArray<unsigned char> &aryRawData)
2062 {return (8*aryRawData.GetSize());}
2063 
2098 void STD_UTILS_PORT Std_GetBinarySection(CStdArray<unsigned char> &aryRawData, long lStartBit, long lBitLength, unsigned char &cOut)
2099 {
2100  CStdArray<unsigned char> aryOutData;
2101 
2102  Std_InValidRange((long) 1, (long) 8, lBitLength, true, "Length");
2103 
2104  Std_GetBinarySection(aryRawData, lStartBit, lBitLength, aryOutData);
2105 
2106  cOut = aryOutData[aryOutData.GetSize()-1];
2107 }
2108 
2143 void STD_UTILS_PORT Std_GetBinarySection(CStdArray<unsigned char> &aryRawData, long lStartBit, long lBitLength, unsigned short &iOut)
2144 {
2145  CStdArray<unsigned char> aryOutData;
2146  short iByte, iByteCount, iArraySize;
2147 
2148  Std_InValidRange((long) 1, (long) 16, lBitLength, true, "Length");
2149 
2150  iOut = 0;
2151  Std_GetBinarySection(aryRawData, lStartBit, lBitLength, aryOutData);
2152  iArraySize = aryOutData.GetSize()-1;
2153 
2154  iByteCount=0;
2155  for(iByte=iArraySize; iByte>=0 && iByteCount<2; iByte--)
2156  {
2157  iOut += (aryOutData[iByte] << (iByteCount*8));
2158  iByteCount++;
2159  }
2160 }
2161 
2196 void STD_UTILS_PORT Std_GetBinarySection(CStdArray<unsigned char> &aryRawData, long lStartBit, long lBitLength, unsigned long &lOut)
2197 {
2198  CStdArray<unsigned char> aryOutData;
2199  short iByte, iByteCount, iArraySize;
2200 
2201  Std_InValidRange((long) 1, (long) 32, lBitLength, true, "Length");
2202 
2203  lOut = 0;
2204  Std_GetBinarySection(aryRawData, lStartBit, lBitLength, aryOutData);
2205  iArraySize = aryOutData.GetSize()-1;
2206 
2207  iByteCount=0;
2208  for(iByte=iArraySize; iByte>=0 && iByteCount<4; iByte--)
2209  {
2210  lOut += (aryOutData[iByte] << (iByteCount*8));
2211  iByteCount++;
2212  }
2213 }
2214 
2249 void STD_UTILS_PORT Std_GetBinarySection(CStdArray<unsigned char> &aryRawData, long lStartBit, long lBitLength,
2250  CStdArray<unsigned char> &aryOutData)
2251 {
2252  long lEndBit, lByteLength, lBit, lBitsNeeded, lByte;
2253 
2254  lEndBit = lStartBit + lBitLength - 1;
2255 
2256  Std_InValidRange((long) 0, (long) ((aryRawData.GetSize() * 8) - 1), lStartBit, true, "Starting Bit Position");
2257  Std_InValidRange((long) 0, (long) ((aryRawData.GetSize() * 8) - 1), lEndBit, true, "Ending Bit Position");
2258 
2259  if( lBitLength%8 )
2260  lByteLength = ((long) ceil((float) (lBitLength / 8))) + 1;
2261  else
2262  lByteLength = lBitLength / 8;
2263 
2264  aryOutData.RemoveAll();
2265  aryOutData.SetSize(lByteLength);
2266 
2267  lBit = lEndBit;
2268  for(lByte=(lByteLength-1); lByte>=0; lByte--)
2269  {
2270  lBitsNeeded = lBitLength - (lEndBit-lBit);
2271  if(lBitsNeeded>8) lBitsNeeded = 8;
2272 
2273  aryOutData[lByte] = Std_GetByteFromArray(aryRawData, lBit, lBitsNeeded);
2274  lBit-=lBitsNeeded;
2275  }
2276 
2277 }
2278 
2291 unsigned char STD_UTILS_PORT Std_GetByteFromArray(CStdArray<unsigned char> &aryRawData, long lEndBit, long lBitsNeeded)
2292 {
2293  unsigned char cVal=0;
2294  long lBitIndex, lBit;
2295 
2296  Std_InValidRange((long) 1, (long) 8, lBitsNeeded, true, "Bits Needed");
2297 
2298  for(lBitIndex=0; lBitIndex<lBitsNeeded; lBitIndex++)
2299  {
2300  lBit = lEndBit - lBitIndex;
2301 
2302  if(Std_GetBitFromArray(aryRawData, lBit))
2303  cVal += (1 << lBitIndex);
2304  }
2305 
2306  return cVal;
2307 }
2308 
2320 bool STD_UTILS_PORT Std_GetBitFromArray(CStdArray<unsigned char> &aryRawData, long lBit)
2321 {
2322  long lByte;
2323  int iShift;
2324  unsigned char cVal;
2325 
2326  lByte = (long) (lBit/8);
2327  iShift = lBit - (lByte*8);
2328  cVal = aryRawData[lByte];
2329 
2330  if(cVal & (0x80 >> iShift))
2331  return true;
2332  else
2333  return false;
2334 
2335 }
2336 
2349 void STD_UTILS_PORT Std_SetBinarySection(CStdArray<unsigned char> &aryRawData, long lStartBit, long lBitLength, unsigned char cIn)
2350 {
2351  long lEndBit;
2352 
2353  Std_InValidRange((long) 1, (long) 8, lBitLength, true, "Length");
2354 
2355  lEndBit = lStartBit + lBitLength-1;
2356  Std_SetByteInArray(aryRawData, cIn, lEndBit, lBitLength);
2357 }
2358 
2359 
2372 void STD_UTILS_PORT Std_SetBinarySection(CStdArray<unsigned char> &aryRawData, long lStartBit, long lBitLength, unsigned short iIn)
2373 {
2374  CStdArray<unsigned char> aryIn;
2375  unsigned char cVal;
2376 
2377  Std_InValidRange((long) 1, (long) 16, lBitLength, true, "Length");
2378 
2379  cVal = (unsigned char) ((iIn & 0xFF00) >> 8);
2380  aryIn.Add(cVal);
2381 
2382  cVal = (unsigned char) (iIn & 0x00FF);
2383  aryIn.Add(cVal);
2384 
2385  Std_SetBinarySection(aryRawData, lStartBit, lBitLength, aryIn);
2386 }
2387 
2400 void STD_UTILS_PORT Std_SetBinarySection(CStdArray<unsigned char> &aryRawData, long lStartBit, long lBitLength, unsigned long lIn)
2401 {
2402  CStdArray<unsigned char> aryIn;
2403  unsigned char cVal;
2404 
2405  Std_InValidRange((long) 1, (long) 32, lBitLength, true, "Length");
2406 
2407  cVal = (unsigned char) ((lIn & 0xFF000000) >> 24);
2408  aryIn.Add(cVal);
2409 
2410  cVal = (unsigned char) ((lIn & 0x00FF0000) >> 16);
2411  aryIn.Add(cVal);
2412 
2413  cVal = (unsigned char) ((lIn & 0x0000FF00) >> 8);
2414  aryIn.Add(cVal);
2415 
2416  cVal = (unsigned char) (lIn & 0x000000FF);
2417  aryIn.Add(cVal);
2418 
2419  Std_SetBinarySection(aryRawData, lStartBit, lBitLength, aryIn);
2420 }
2421 
2434 void STD_UTILS_PORT Std_SetBinarySection(CStdArray<unsigned char> &aryRawData, long lStartBit, long lBitLength,
2435  CStdArray<unsigned char> &aryInData)
2436 {
2437  long lEndBit, lByteLength, lBit, lBitsNeeded, lByte, lNumBytes, lLastByte;
2438 
2439  lEndBit = lStartBit + lBitLength - 1;
2440 
2441  Std_InValidRange((long) 1, (long) (aryInData.GetSize() * 8), lBitLength, true, "BitLength");
2442 
2443  if( lBitLength%8 )
2444  lByteLength = ((long) ceil((float) (lBitLength / 8))) + 1;
2445  else
2446  lByteLength = lBitLength / 8;
2447 
2448  lNumBytes = aryInData.GetSize();
2449  lLastByte = lNumBytes - lByteLength;
2450 
2451  lBit = lEndBit;
2452  for(lByte=(lNumBytes-1); lByte>=lLastByte; lByte--)
2453  {
2454  lBitsNeeded = lBitLength - (lEndBit-lBit);
2455  if(lBitsNeeded>8) lBitsNeeded = 8;
2456 
2457  Std_SetByteInArray(aryRawData, aryInData[lByte], lBit, lBitsNeeded);
2458  lBit-=lBitsNeeded;
2459  }
2460 
2461 }
2462 
2476 void STD_UTILS_PORT Std_CopyBinarySection(CStdArray<unsigned char> &aryInData, long lStartInBit,
2477  CStdArray<unsigned char> &aryOutData, long lStartOutBit,
2478  long lBitLength)
2479 {
2480  CStdArray<unsigned char> aryTempData;
2481 
2482  //Get the part that needs to be copied.
2483  Std_GetBinarySection(aryInData, lStartInBit, lBitLength, aryTempData);
2484  Std_SetBinarySection(aryOutData, lStartOutBit, lBitLength, aryTempData);
2485 }
2486 
2499 void STD_UTILS_PORT Std_SetByteInArray(CStdArray<unsigned char> &aryRawData, unsigned char cIn, long lEndBit, long lBitsNeeded)
2500 {
2501  long lBitIndex, lBit;
2502 
2503  Std_InValidRange((long) 1, (long) 8, lBitsNeeded, true, "Bits Needed");
2504 
2505  for(lBitIndex=0; lBitIndex<lBitsNeeded; lBitIndex++)
2506  {
2507  lBit = lEndBit - lBitIndex;
2508 
2509  if(bit_get(cIn, lBitIndex))
2510  Std_SetBitInArray(aryRawData, lBit, true);
2511  else
2512  Std_SetBitInArray(aryRawData, lBit, false);
2513  }
2514 
2515 }
2516 
2528 void STD_UTILS_PORT Std_SetBitInArray(CStdArray<unsigned char> &aryRawData, long lBit, bool bVal)
2529 {
2530  long lByte;
2531  int iShift;
2532  unsigned char cVal;
2533 
2534  lByte = (long) (lBit/8);
2535  iShift = lBit - (lByte*8);
2536 
2537  if(lByte>=aryRawData.GetSize())
2538  aryRawData.SetSize(lByte+1);
2539 
2540  cVal = aryRawData[lByte];
2541 
2542  if(bVal)
2543  cVal = cVal | (0x80 >> iShift);
2544  else
2545  cVal = cVal & (0xFF7F >> iShift);
2546 
2547  aryRawData[lByte] = cVal;
2548 }
2549 
2561 void STD_UTILS_PORT Std_SetBitRangeInArray(CStdArray<unsigned char> &aryRawData, long lStartBit, long lBitLength, bool bVal)
2562 {
2563  Std_IsAboveMin((long) -1, lBitLength, true, "SetBitRangeInArray::BitLength");
2564  Std_IsAboveMin((long) -1, lStartBit, true, "SetBitRangeInArray::StartBit");
2565 
2566  long lEndBit=lStartBit + lBitLength;
2567  for(long lBit=lStartBit; lBit<lEndBit; lBit++)
2568  Std_SetBitInArray(aryRawData, lBit, bVal);
2569 }
2570 
2580 void STD_UTILS_PORT Std_FlipBitInArray(CStdArray<unsigned char> &aryRawData, long lBit)
2581 {
2582  bool bVal = Std_GetBitFromArray(aryRawData, lBit);
2583  bVal = !bVal;
2584  Std_SetBitInArray(aryRawData, lBit, bVal);
2585 }
2586 
2598 void STD_UTILS_PORT Std_FlipBitRangeInArray(CStdArray<unsigned char> &aryRawData, long lStartBit, long lBitLength)
2599 {
2600  Std_IsAboveMin((long) -1, lBitLength, true, "FlipBitRangeInArray::BitLength");
2601  Std_IsAboveMin((long) -1, lStartBit, true, "FlipBitRangeInArray::StartBit");
2602 
2603  long lEndBit=lStartBit + lBitLength;
2604  for(long lBit=lStartBit; lBit<lEndBit; lBit++)
2605  Std_FlipBitInArray(aryRawData, lBit);
2606 }
2607 
2622 bool STD_UTILS_PORT Std_ReadBinaryData(CStdArray<unsigned char> &aryBinaryData, long lLastBit, long &lStartBit, long lBitLength, unsigned char &cOut)
2623 {
2624  long lEndBit;
2625 
2626  //Verify that is still enough left in the array for the read.
2627  lEndBit = lStartBit + lBitLength-1;
2628 
2629  if(!Std_InValidRange((long) 0, lLastBit, lStartBit, false)) return false;
2630  if(!Std_InValidRange((long) 0, lLastBit, lEndBit, false)) return false;
2631 
2632  Std_GetBinarySection(aryBinaryData, lStartBit, lBitLength, cOut);
2633 
2634  TRACE_DETAIL_NS("[ReadBinaryData(uchar)] Value: " + STR(cOut) + " StartBit: " + STR(lStartBit) + " BitLength: " + STR(lBitLength));
2635 
2636  //Now move the bit position pointer up.
2637  lStartBit+=lBitLength;
2638 
2639  return true;
2640 }
2641 
2656 bool STD_UTILS_PORT Std_ReadBinaryData(CStdArray<unsigned char> &aryBinaryData, long lLastBit, long &lStartBit, long lBitLength, unsigned short &iOut)
2657 {
2658  long lEndBit;
2659 
2660  //Verify that is still enough left in the array for the read.
2661  lEndBit = lStartBit + lBitLength-1;
2662 
2663  if(!Std_InValidRange((long) 0, lLastBit, lStartBit, false)) return false;
2664  if(!Std_InValidRange((long) 0, lLastBit, lEndBit, false)) return false;
2665 
2666  Std_GetBinarySection(aryBinaryData, lStartBit, lBitLength, iOut);
2667 
2668  TRACE_DETAIL_NS("[ReadBinaryData(ushort)] Value: " + STR(iOut) + " StartBit: " + STR(lStartBit) + " BitLength: " + STR(lBitLength));
2669 
2670  //Now move the bit position pointer up.
2671  lStartBit+=lBitLength;
2672 
2673  return true;
2674 }
2675 
2690 bool STD_UTILS_PORT Std_ReadBinaryData(CStdArray<unsigned char> &aryBinaryData, long lLastBit, long &lStartBit, long lBitLength, unsigned long &lOut)
2691 {
2692  long lEndBit;
2693 
2694  //Verify that is still enough left in the array for the read.
2695  lEndBit = lStartBit + lBitLength-1;
2696 
2697  if(!Std_InValidRange((long) 0, lLastBit, lStartBit, false)) return false;
2698  if(!Std_InValidRange((long) 0, lLastBit, lEndBit, false)) return false;
2699 
2700  Std_GetBinarySection(aryBinaryData, lStartBit, lBitLength, lOut);
2701 
2702  TRACE_DETAIL_NS("[ReadBinaryData(ulong)] Value: " + STR((long) lOut) + " StartBit: " + STR(lStartBit) + " BitLength: " + STR(lBitLength));
2703 
2704  //Now move the bit position pointer up.
2705  lStartBit+=lBitLength;
2706 
2707  return true;
2708 }
2709 
2722 void STD_UTILS_PORT Std_WriteBinaryData(CStdArray<unsigned char> &aryBinaryData, long &lStartBit, long lBitLength, unsigned char cIn)
2723 {
2724  TRACE_DETAIL_NS("[WriteBinaryData(uchar)] Value: " + STR(cIn) + " StartBit: " + STR(lStartBit) + " BitLength: " + STR(lBitLength));
2725 
2726  Std_SetBinarySection(aryBinaryData, lStartBit, lBitLength, cIn);
2727 
2728  //Now move the bit position pointer up.
2729  lStartBit+=lBitLength;
2730 }
2731 
2732 
2745 void STD_UTILS_PORT Std_WriteBinaryData(CStdArray<unsigned char> &aryBinaryData, long &lStartBit, long lBitLength, unsigned short iIn)
2746 {
2747  TRACE_DETAIL_NS("[WriteBinaryData(ushort)] Value: " + STR(iIn) + " StartBit: " + STR(lStartBit) + " BitLength: " + STR(lBitLength));
2748 
2749  Std_SetBinarySection(aryBinaryData, lStartBit, lBitLength, iIn);
2750 
2751  //Now move the bit position pointer up.
2752  lStartBit+=lBitLength;
2753 }
2754 
2755 
2768 void STD_UTILS_PORT Std_WriteBinaryData(CStdArray<unsigned char> &aryBinaryData, long &lStartBit, long lBitLength, unsigned long lIn)
2769 {
2770  TRACE_DETAIL_NS("[WriteBinaryData(ulong)] Value: " + STR((long) lIn) + " StartBit: " + STR(lStartBit) + " BitLength: " + STR(lBitLength));
2771 
2772  Std_SetBinarySection(aryBinaryData, lStartBit, lBitLength, lIn);
2773 
2774  //Now move the bit position pointer up.
2775  lStartBit+=lBitLength;
2776 }
2777 
2788 unsigned char STD_UTILS_PORT Std_BinaryToGreyCode(unsigned char cVal)
2789 {
2790  short iBit;
2791  unsigned char cOut=0;
2792 
2793  for(iBit=0; iBit< 7; iBit++)
2794  {
2795  cOut = (unsigned char) bit_put(cOut, iBit, bit_get(cVal, iBit) ^ bit_get(cVal, iBit+1) );
2796  }
2797  cOut = (unsigned char) bit_put(cOut, 7, bit_get(cVal, 7) );
2798 
2799  TRACE_DETAIL_NS("[BinaryToGreyCode(uchar)] Input: " + STR(cVal) + " Output: " + STR(cOut));
2800 
2801  return cOut;
2802 }
2803 
2804 
2815 unsigned short STD_UTILS_PORT Std_BinaryToGreyCode(unsigned short iVal)
2816 {
2817  short iBit;
2818  unsigned short iOut=0;
2819 
2820  for(iBit=0; iBit< 15; iBit++)
2821  {
2822  iOut = (unsigned short) bit_put(iOut, iBit, bit_get(iVal, iBit) ^ bit_get(iVal, iBit+1) );
2823  }
2824  iOut = (unsigned short) bit_put(iOut, 15, bit_get(iVal, 15) );
2825 
2826  TRACE_DETAIL_NS("[BinaryToGreyCode(ushort)] Input: " + STR(iVal) + " Output: " + STR(iOut));
2827 
2828  return iOut;
2829 }
2830 
2841 unsigned long STD_UTILS_PORT Std_BinaryToGreyCode(unsigned long lVal)
2842 {
2843  short iBit;
2844  unsigned long lOut=0;
2845 
2846  for(iBit=0; iBit< 31; iBit++)
2847  {
2848  lOut = bit_put(lOut, iBit, bit_get(lVal, iBit) ^ bit_get(lVal, iBit+1) );
2849  }
2850  lOut = bit_put(lOut, 31, bit_get(lVal, 31) );
2851 
2852  TRACE_DETAIL_NS("[BinaryToGreyCode(ulong)] Input: " + STR((long) lVal) + " Output: " + STR((long) lOut));
2853 
2854  return lOut;
2855 }
2856 
2857 
2868 unsigned char STD_UTILS_PORT Std_GreyCodeToBinary(unsigned char cVal)
2869 {
2870  short iBit, iTempBit;
2871  unsigned char cOut=0, cTemp;
2872 
2873  cOut = 0;
2874  for (iBit = 0; iBit <= 7; iBit++ )
2875  {
2876  cTemp = 0;
2877  for (iTempBit = iBit; iTempBit <= 7; iTempBit++ )
2878  cTemp ^= bit_get(cVal, iTempBit);
2879 
2880  cOut = (unsigned char) bit_put (cOut, iBit, cTemp);
2881  }
2882 
2883  TRACE_DETAIL_NS("[GreyCodeToBinary(uchar)] Input: " + STR(cVal) + " Output: " + STR(cOut));
2884 
2885  return cOut;
2886 }
2887 
2898 unsigned short STD_UTILS_PORT Std_GreyCodeToBinary(unsigned short iVal)
2899 {
2900  short iBit, iTempBit;
2901  unsigned short iOut=0, iTemp;
2902 
2903  iOut = 0;
2904  for (iBit = 0; iBit <= 15; iBit++ )
2905  {
2906  iTemp = 0;
2907  for (iTempBit = iBit; iTempBit <= 15; iTempBit++ )
2908  iTemp ^= bit_get(iVal, iTempBit);
2909 
2910  iOut = (unsigned short) bit_put (iOut, iBit, iTemp);
2911  }
2912 
2913  TRACE_DETAIL_NS("[BinaryToGreyCode(ushort)] Input: " + STR(iVal) + " Output: " + STR(iOut));
2914 
2915  return iOut;
2916 }
2917 
2918 
2929 unsigned long STD_UTILS_PORT Std_GreyCodeToBinary(unsigned long lVal)
2930 {
2931  short iBit, iTempBit;
2932  unsigned long lOut=0, lTemp;
2933 
2934  lOut = 0;
2935  for (iBit = 0; iBit <= 31; iBit++ )
2936  {
2937  lTemp = 0;
2938  for (iTempBit = iBit; iTempBit <= 31; iTempBit++ )
2939  lTemp ^= bit_get(lVal, iTempBit);
2940 
2941  lOut = bit_put (lOut, iBit, lTemp);
2942  }
2943 
2944  TRACE_DETAIL_NS("[BinaryToGreyCode(ulong)] Input: " + STR((long) lVal) + " Output: " + STR((long) lOut));
2945 
2946  return lOut;
2947 }
2948 
2949 // Byte Array Functions
2950 //***************************************************************************************************************
2951 
2952 
2953 //***************************************************************************************************************
2954 // Logging Functions
2955 
2956 #ifdef _WIN32_WCE
2957  int g_iTraceLevel = 0;
2958 
2959  int STD_UTILS_PORT Std_GetTraceLevel()
2960  {return g_iTraceLevel;}
2961 
2962  void STD_UTILS_PORT Std_SetTraceLevel(const int iLevel)
2963  {g_iTraceLevel = iLevel;}
2964 
2965  void STD_UTILS_PORT Std_SetLogLevel(const int iLevel)
2966  {g_iTraceLevel = iLevel;}
2967 
2968  void STD_UTILS_PORT Std_LogMsg(const int iLevel, std::string strMessage, std::string strSourceFile, int iSourceLine, bool bPrintHeader)
2969  {
2970  //if(g_iTraceLevel==0 || iLevel>g_iTraceLevel)
2971  if(iLevel>g_iTraceLevel)
2972  return;
2973 
2974  std::string strFinalMessage;
2975 
2976  if(iSourceLine>=0)
2977  strFinalMessage = STR(strSourceFile) + " (" + STR(iSourceLine) + ") \r\n" + STR(strMessage) + "\r\n";
2978  else
2979  strFinalMessage = strMessage;
2980 
2981  STLOG_WRITE(strFinalMessage.c_str());
2982  }
2983 
2984  void STD_UTILS_PORT Std_TraceMsg(const int iLevel, std::string strMessage, std::string strSourceFile, int iSourceLine, bool bLogToFile, bool bPrintHeader)
2985  {
2986  std::string strTemp = strMessage + "\r\n";
2987 
2988  #ifdef STD_TRACE_TO_DEBUGGER
2989  wchar_t *sMessage = Std_ConvertFromANSI(strTemp);
2990  if(sMessage)
2991  {
2992  OutputDebugString(sMessage);
2993  delete[] sMessage;
2994  sMessage = NULL;
2995  }
2996  #endif
2997 
2998  if(bLogToFile)
2999  Std_LogMsg(iLevel, strMessage, strSourceFile, iSourceLine, bPrintHeader);
3000  }
3001 
3002  void STD_UTILS_PORT Std_ResetLog()
3003  {
3004  CSTLogFile::GetLogFile()->Stop();
3005  }
3006 #else
3007 
3016  int STD_UTILS_PORT Std_GetTraceLevel()
3017  {
3018 #ifdef WIN32
3019  return GetTraceLevel();
3020 #else
3021  return 0;
3022 #endif
3023  }
3024 
3034  void STD_UTILS_PORT Std_SetTraceLevel(const int iVal)
3035  {
3036 #ifdef WIN32
3037  SetTraceLevel(iVal);
3038 #endif
3039  }
3040 
3050  void STD_UTILS_PORT Std_SetLogFilePrefix(std::string strFilePrefix)
3051  {
3052 #ifdef WIN32
3053  if(GetTraceFilePrefix() != strFilePrefix)
3054  SetTraceFilePrefix(strFilePrefix.c_str());
3055 #endif
3056  }
3057 
3066  std::string STD_UTILS_PORT Std_GetLogFilePrefix()
3067  {
3068 #ifdef WIN32
3069  return GetTraceFilePrefix();
3070 #else
3071  return "";
3072 #endif
3073  }
3074 
3084  void STD_UTILS_PORT Std_SetLogLevel(const int iLevel)
3085  {
3086 #ifdef WIN32
3087  SetTraceLevel(iLevel);
3088 #endif
3089  }
3090 
3104  void STD_UTILS_PORT Std_LogMsg(const int iLevel, std::string strMessage, std::string strSourceFile, int iSourceLine, bool bPrintHeader)
3105  {
3106 #ifdef WIN32
3107  if(GetTraceLevel()==0 || iLevel>GetTraceLevel())
3108  return;
3109 
3110  std::string strFinalMessage;
3111 
3112  if(iSourceLine>=0)
3113  strFinalMessage = STR(strSourceFile) + " (" + STR(iSourceLine) + ") \r\n" + STR(strMessage) + "\r\n";
3114  else
3115  strFinalMessage = strMessage;
3116 
3117  Std_Log(iLevel, bPrintHeader, strFinalMessage.c_str());
3118 #else
3119  std::cout << strMessage;
3120 #endif
3121  }
3122 
3137  void STD_UTILS_PORT Std_TraceMsg(const int iLevel, std::string strMessage, std::string strSourceFile, int iSourceLine, bool bLogToFile, bool bPrintHeader)
3138  {
3139 #ifdef WIN32
3140  int iLogLevel = GetTraceLevel();
3141  if(iLogLevel==0||iLevel>iLogLevel) return;
3142 
3143  std::string strTemp = strMessage + "\r\n";
3144 
3145  #ifdef STD_TRACE_TO_DEBUGGER
3146  OutputDebugString(strTemp.c_str());
3147  #endif
3148 
3149  if(bLogToFile)
3150  {
3151  if(iSourceLine>=0)
3152  strMessage = STR(strSourceFile) + " (" + STR(iSourceLine) + ") \r\n" + STR(strMessage) + "\r\n";
3153 
3154  Std_Log(iLevel, bPrintHeader, strMessage.c_str());
3155  }
3156 #endif
3157  }
3158 #endif
3159 
3160 
3161 // Logging Functions
3162 //***************************************************************************************************************
3163 
3164 
3165 //***************************************************************************************************************
3166 // Timing Functions
3167 
3168 
3169 #ifndef _WIN32_WCE
3170 
3179 unsigned long STD_UTILS_PORT Std_GetTick()
3180 {
3181 #ifdef WIN32
3182  return GetTickCount64();
3183 #else
3184  return -1;
3185 #endif
3186 }
3187 
3188 #endif
3189 
3190 void STD_UTILS_PORT Std_Sleep(unsigned long lMilliseconds)
3191 {
3192 #ifdef WIN32
3193  Sleep(lMilliseconds);
3194 #else
3195  sleep(lMilliseconds);
3196 #endif
3197 }
3198 
3199 
3200 // Timing Functions
3201 //***************************************************************************************************************
3202 
3203 //***************************************************************************************************************
3204 // File Functions
3205 
3218 bool STD_UTILS_PORT Std_IsFullPath(std::string strPath)
3219 {
3220  return boost::filesystem::path(strPath).has_root_path();
3221  //CStdArray<std::string> aryParts;
3222  //int iCount = Std_Split(strPath, ":", aryParts);
3223  //if(iCount>1)
3224  // return true;
3225  //else
3226  // return false;
3227 }
3228 
3240 void STD_UTILS_PORT Std_SplitPathAndFile(std::string &strFullPath, std::string &strPath, std::string &strFile)
3241 {
3242  try
3243  {
3244  boost::filesystem::path path = boost::filesystem::canonical(strFullPath);
3245  strFile = path.filename().string();
3246  strPath = Std_Replace(path.string(), strFile, "");
3247  strFullPath = path.generic_string();
3248  }
3249  catch(const boost::filesystem::filesystem_error& e)
3250  {
3251  if(e.code() == boost::system::errc::permission_denied)
3252  std::cout << "Search permission is denied for one of the directories "
3253  << "in the path prefix of " << "\n";
3254  else
3255  std::cout << "is_directory(" << ") failed with "
3256  << e.code().message() << '\n';
3257  }
3258 }
3259 
3270 bool STD_UTILS_PORT Std_DirectoryExists(std::string strPath)
3271 {
3272  boost::filesystem::path p = boost::filesystem::path(strPath);
3273  return boost::filesystem::is_directory(p);
3274 }
3275 
3285 bool STD_UTILS_PORT Std_FileExists(std::string strFullPath)
3286 {
3287  try
3288  {
3289  boost::filesystem::path path = boost::filesystem::canonical(strFullPath);
3290  return true;
3291  }
3292  catch(const boost::filesystem::filesystem_error& e)
3293  {
3294  if(e.code() == boost::system::errc::permission_denied)
3295  std::cout << "Search permission is denied for one of the directories "
3296  << "in the path prefix of " << "\n";
3297  else
3298  std::cout << "is_directory(" << ") failed with "
3299  << e.code().message() << '\n';
3300  return false;
3301  }
3302 }
3303 
3312 std::string STD_UTILS_PORT Std_ExecutablePath()
3313 {
3314  std::string strPath = "";
3315  char strBuffer[2000];
3316 
3317 #ifdef WIN32
3318  //Get the working directory for the exe.
3319  HINSTANCE hInst = GetModuleHandle(NULL);
3320  GetModuleFileName(hInst, strBuffer, 2000);
3321 #else
3322  ssize_t len = ::readlink("/proc/self/exe", strBuffer, sizeof(strBuffer)-1);
3323  if (len != -1)
3324  strBuffer[len] = '\0';
3325  else
3326  THROW_ERROR(Std_Err_lModuleNotLoaded, Std_Err_strModuleNotLoaded);
3327 #endif
3328 
3329  strPath = strBuffer;
3330  return strPath;
3331 }
3332 
3333 
3334 
3335 #ifdef WIN32
3336 
3337 void Std_SetFileTime(std::string strFilename, SYSTEMTIME newTime)
3338 {
3339  // Create a FILETIME struct and convert our new SYSTEMTIME
3340  // over to the FILETIME struct for use in SetFileTime below
3341  FILETIME thefiletime;
3342  SystemTimeToFileTime(&newTime,&thefiletime);
3343 
3344  // Get a handle to our file and with file_write_attributes access
3345  HANDLE filename = CreateFile(strFilename.c_str(), FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
3346 
3347  // Set the file time on the file
3348  SetFileTime(filename,(LPFILETIME) NULL,(LPFILETIME) NULL,&thefiletime);
3349 
3350  // Close our handle.
3351  CloseHandle(filename);
3352 }
3353 
3354 void STD_UTILS_PORT Std_SetFileTime(std::string strFilename)
3355 {
3356  // Create a systemtime struct
3357  SYSTEMTIME thesystemtime;
3358 
3359  // Get current system time and then change the day to the 3rd
3360  // You can also change year, month, day of week etc
3361  GetSystemTime(&thesystemtime);
3362 
3363  Std_SetFileTime(strFilename, thesystemtime);
3364 }
3365 
3366 #else
3367 
3368 //NEED TO TEST
3369 void STD_UTILS_PORT Std_SetFileTime(std::string strFilename)
3370 {
3371  utime(strFilename.c_str(), NULL);
3372 }
3373 
3374 #endif
3375 
3376 // File Functions
3377 //***************************************************************************************************************
3378 
3379 //class StdFixed;
3380 //
3381 //void TestTree()
3382 //
3383 //{
3384 // tree<CStdFixed *> tr;
3385 // tree<CStdFixed *>::iterator top, one;
3386 //
3387 // CStdFixed *lp1 = new CStdFixed();
3388 // top=tr.begin();
3389 // one=tr.insert(top, lp1);
3390 //
3391 // tr.clear();
3392 //
3393 // ostringstream str;
3394 // kptree::ptr_print_tree_bracketed(tr, str);
3395 // OutputDebugString(str.str().c_str());
3396 //}
3397 
3398 } //StdUtils
3399 
bool NotSpace(char c)
Test if this is a space.
int Std_VariantTypeToConst(std::string strType)
Standard variant type to constant.
std::string m_strSourceFile
The source file name where the error occurred.
Definition: StdErrorInfo.h:32
void Std_CopyBinarySection(CStdArray< unsigned char > &aryInData, long lStartInBit, CStdArray< unsigned char > &aryOutData, long lStartOutBit, long lBitLength)
Copies a section of a byte array to a new position within the array.
virtual void Deserialize(std::string &strXml)
Deserializes a string into an xml document.
Definition: StdXml.cpp:162
unsigned char Std_BinaryToGreyCode(unsigned char cVal)
Converts a binary value to grey code.
std::string Std_CreateAppID()
Gets the standard create application identifier.
virtual bool FindChildElement(std::string strElementName, bool fThrowError=true)
Finds a child element by name.
Definition: StdXml.cpp:256
void Std_FlipBitRangeInArray(CStdArray< unsigned char > &aryRawData, long lStartBit, long lBitLength)
Flips all the bits within a section of a byte array.
void Std_SetLogLevel(const int iLevel)
Sets the log level.
virtual int GetChildAttribInt(std::string strAttribName, bool bThrowError=true, int iDefault=0)
Gets a child attribute int.
Definition: StdXml.cpp:1369
std::string Std_Left(std::string strVal, int iCount)
Gets the left portion of a substring.
unsigned long bit_put(unsigned long x, int i, unsigned long v)
puts a bit in x.
std::string m_strError
The error message.
Definition: StdErrorInfo.h:26
bool Std_IsNumeric(std::string strVal)
Tests if this string is a number.
void Std_SplitPathAndFile(std::string &strFullPath, std::string &strPath, std::string &strFile)
Splits the path from the actual filename.
virtual bool FindElement(std::string strElementName, bool fThrowError=true)
Finds an element with the specified name.
Definition: StdXml.cpp:179
Information about the standard error.
Definition: StdErrorInfo.h:19
void Std_SetBinarySection(CStdArray< unsigned char > &aryRawData, long lStartBit, long lBitLength, unsigned char cIn)
Replaces a section of a byte array with a new byte array.
void Std_LoadColor(CStdXml &oXml, std::string strParamName, float *aryColor, bool bThrowError)
Loads a color.
long m_lError
The error number.
Definition: StdErrorInfo.h:23
int Std_Split(const std::string &input, const std::string &delimiter, CStdArray< std::string > &results)
Splits a string into an array of subparts based on a delimiter.
unsigned char Std_HexCharToByte(char cVal)
Converts a hexidecimal number to a byte.
int Std_Sign(float fltVal)
Determines the sign of a number.
bool Std_InValidRange(int iMinVal, int iMaxVal, int iVal, bool bThrowError, std::string strParamName)
Tests whether a number is within a valid range.
std::string Std_ConstToVariantType(int iType)
Standard constant to variant type.
std::string Std_Combine(CStdArray< std::string > &aryParts, std::string strDelimiter)
Combines an array of strings into a single string.
std::string Std_ByteArrayToHexString(CStdArray< unsigned char > &aryBytes)
Converts a byte array to hexadecimal string.
long Std_GetBitSize(CStdArray< unsigned char > &aryRawData)
Gets the number of bits in a byte array.
bool Std_IsAboveMin(int iMinVal, int iVal, bool bThrowError, std::string strParamName, bool bInclusiveLimit)
Tests if a number is above a minimum value.
std::string Std_Trim(std::string strVal)
Trims a string.
bool Std_DirectoryExists(std::string strPath)
Queries if a given directory exists.
void Std_WriteBinaryData(CStdArray< unsigned char > &aryBinaryData, long &lStartBit, long lBitLength, unsigned char cIn)
Writes data to a byte array.
void Std_HexStringToByteArray(std::string strHex, CStdArray< unsigned char > &aryBytes)
Converts a hex string to a byte array.
void Std_SetByteInArray(CStdArray< unsigned char > &aryRawData, unsigned char cIn, long lEndBit, long lBitsNeeded)
Sets a byte within an array.
int Std_IRand(int low, int high)
Generates a random number between two values.
unsigned char Std_GreyCodeToBinary(unsigned char cVal)
Converts a grey code to a binary value.
unsigned long Std_GetTick()
Gets the time tick.
CStdArray< std::string > m_aryCallChain
The call chain of the errorr.
Definition: StdErrorInfo.h:35
A standard xml manipulation class.
Definition: StdXml.h:19
int Std_GetTraceLevel()
Gets the trace level.
long m_lSourceLine
The source line code line where the error occurred.
Definition: StdErrorInfo.h:29
virtual float GetAttribFloat(std::string strAttribName, bool bThrowError=true, float fltDefault=0)
Gets an attribute float.
Definition: StdXml.cpp:1095
long Std_LoadRGB(CStdXml &oXml, std::string strParamName, bool bThrowError, long lDefault)
Loads a color.
std::string Std_GetLogFilePrefix()
Gets the log file prefix.
void Std_ThrowError(long lError, std::string strError, std::string strSourceFile, long lSourceLine, std::string strValueName, unsigned char iVal)
Standard throw error.
unsigned char Std_GetByteFromArray(CStdArray< unsigned char > &aryRawData, long lEndBit, long lBitsNeeded)
Gets a single byte from a byte array.
Namespace for the standard utility objects.
Definition: MarkupSTL.cpp:19
unsigned char Std_HexToByte(std::string strVal)
Converts a hexidecimal number to a byte.
bool Std_ToBool(int iVal)
Converts a value toa bool.
bool Std_IsBelowMax(int iMaxVal, int iVal, bool bThrowError, std::string strParamName, bool bInclusiveLimit)
Tests if a number is below a maximum value.
void Std_SetBitInArray(CStdArray< unsigned char > &aryRawData, long lBit, bool bVal)
Sets a bit within an array.
unsigned long bit_get(unsigned long x, int i)
Gets a bit of x.
bool Std_ReadBinaryData(CStdArray< unsigned char > &aryBinaryData, long lLastBit, long &lStartBit, long lBitLength, unsigned char &cOut)
Reads binary data from a byte array.
void Std_TraceMsg(const int iLevel, std::string strMessage, std::string strSourceFile, int iSourceLine, bool bLogToFile, bool bPrintHeader)
Traces a message to the debugger window.
void Std_SRand(unsigned long lSeed)
Sets the seed for generating a random number.
void Std_LogMsg(const int iLevel, std::string strMessage, std::string strSourceFile, int iSourceLine, bool bPrintHeader)
Logs a message,.
double Std_DRand(double low, double high)
Generates a random number between two values.
std::string Std_ToLower(std::string strVal)
Converts a string to lower case.
std::string Std_ExecutablePath()
Finds the name and path of the current executable.
float Std_FRand(float low, float high)
Generates a random number between two values.
bool Std_IsIntegerType(std::string strVal)
Tests if this string is an integer.
void AddToErrorCallChain(CStdErrorInfo &oInfo, std::string strSourceFile, long lSourceLine)
Adds to the error call chain.
void Std_SetBitRangeInArray(CStdArray< unsigned char > &aryRawData, long lStartBit, long lBitLength, bool bVal)
Sets an entire section within a byte array with a bit value.
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
Definition: StdXml.cpp:56
std::string Std_ToStr(std::string strVal)
Converts a value to a string.
bool Std_IsBlank(std::string strVal)
Trims a string and tests if a string is blank.
bool Std_GetBitFromArray(CStdArray< unsigned char > &aryRawData, long lBit)
Gets a single bit from a byte array.
virtual bool IntoChildElement(std::string strElementName, bool bThrowError=true)
Goes into the child element with the specified name.
Definition: StdXml.cpp:278
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
void Std_SetTraceLevel(const int iVal)
Sets teh trace level.
bool Std_IsFullPath(std::string strPath)
determines if this is a full path name.
long Std_RGB(unsigned char iRed, unsigned char iGreen, unsigned char iBlue)
Generates a long representation of a color.
void Std_GetBinarySection(CStdArray< unsigned char > &aryRawData, long lStartBit, long lBitLength, unsigned char &cOut)
Gets a section of bits from a byte array.
bool Std_FileExists(std::string strFullPath)
Finds if a given file exists.
std::string Std_TrimRight(std::string strVal)
Standard trim right.
void Std_FlipBitInArray(CStdArray< unsigned char > &aryRawData, long lBit)
Flips a bit within a byte array.
std::string Std_TrimLeft(std::string strVal)
Standard trim left.
void Std_RelayError(CStdErrorInfo oInfo, std::string strSourceFile, long lSourceLine)
Standard relay error.
std::string Std_ToUpper(std::string strVal)
Converts a string to upper case.
void Std_SetLogFilePrefix(std::string strFilePrefix)
Sets the log file prefix.
long Std_LRand(long low, long high)
Generates a random number between two values.
std::string Std_Replace(std::string strVal, std::string strFind, std::string strReplace)
Replaces a substring with another string.
std::string Std_Right(std::string strVal, int iCount)
Gets the right portion of a substring.
std::string Std_NullStr(std::string strFormat)
If string is blank it uses NULL instead.