91 std::ostringstream oStream;
92 oStream << strSourceFile <<
" (" << lSourceLine <<
")";
132 void STD_UTILS_PORT
Std_ThrowError(
long lError, std::string strError, std::string strSourceFile,
long lSourceLine,
133 std::string strValueName,
unsigned char iVal)
135 std::ostringstream oStream;
136 oStream <<
" (" << strValueName <<
": " << (int) iVal <<
")";
137 Std_ThrowError(lError, strError, strSourceFile, lSourceLine, oStream.str());
155 void STD_UTILS_PORT
Std_ThrowError(
long lError, std::string strError, std::string strSourceFile,
long lSourceLine,
156 std::string strValueName,
unsigned short iVal)
158 std::ostringstream oStream;
159 oStream <<
" (" << strValueName <<
": " << iVal <<
")";
160 Std_ThrowError(lError, strError, strSourceFile, lSourceLine, oStream.str());
178 void STD_UTILS_PORT
Std_ThrowError(
long lError, std::string strError, std::string strSourceFile,
long lSourceLine,
179 std::string strValueName,
int iVal)
181 std::ostringstream oStream;
182 oStream <<
" (" << strValueName <<
": " << iVal <<
")";
183 Std_ThrowError(lError, strError, strSourceFile, lSourceLine, oStream.str());
201 void STD_UTILS_PORT
Std_ThrowError(
long lError, std::string strError, std::string strSourceFile,
long lSourceLine,
202 std::string strValueName,
long lVal)
204 std::ostringstream oStream;
205 oStream <<
" (" << strValueName <<
": " << lVal <<
")";
206 Std_ThrowError(lError, strError, strSourceFile, lSourceLine, oStream.str());
224 void STD_UTILS_PORT
Std_ThrowError(
long lError, std::string strError, std::string strSourceFile,
long lSourceLine,
225 std::string strValueName,
float fltVal)
227 std::ostringstream oStream;
228 oStream <<
" (" << strValueName <<
": " << fltVal <<
")";
229 Std_ThrowError(lError, strError, strSourceFile, lSourceLine, oStream.str());
247 void STD_UTILS_PORT
Std_ThrowError(
long lError, std::string strError, std::string strSourceFile,
long lSourceLine,
248 std::string strValueName,
double dblVal)
250 std::ostringstream oStream;
251 oStream <<
" (" << strValueName <<
": " << dblVal <<
")";
252 Std_ThrowError(lError, strError, strSourceFile, lSourceLine, oStream.str());
270 void STD_UTILS_PORT
Std_ThrowError(
long lError, std::string strError, std::string strSourceFile,
long lSourceLine,
271 std::string strValueName, std::string strVal)
273 std::ostringstream oStream;
274 oStream <<
" (" << strValueName <<
": " << strVal <<
")";
275 Std_ThrowError(lError, strError, strSourceFile, lSourceLine, oStream.str());
294 void STD_UTILS_PORT
Std_ThrowError(
long lError, std::string strError, std::string strSourceFile,
long lSourceLine,
321 std::string STD_UTILS_PORT
Std_ToStr(std::string strVal)
334 std::string STD_UTILS_PORT
Std_ToStr(
const char *strVal)
336 std::string strV = strVal;
350 std::string STD_UTILS_PORT
Std_ToStr(
unsigned char iVal)
352 std::ostringstream buf;
354 std::string str = buf.str() ;
368 std::string STD_UTILS_PORT
Std_ToStr(
unsigned short iVal)
370 std::ostringstream buf;
372 std::string str = buf.str() ;
388 std::ostringstream buf;
390 std::string str = buf.str() ;
406 std::ostringstream buf;
408 std::string str = buf.str() ;
424 std::ostringstream buf;
426 std::string str = buf.str() ;
440 std::string STD_UTILS_PORT
Std_ToStr(
unsigned long lVal)
442 std::ostringstream buf;
444 std::string str = buf.str() ;
460 std::ostringstream buf;
462 std::string str = buf.str() ;
478 std::ostringstream buf;
480 std::string str = buf.str() ;
513 std::string STD_UTILS_PORT
Std_ToStr(std::string strFormat,
unsigned char iVal)
514 {
return str(boost::format(
"%d") % iVal);}
527 std::string STD_UTILS_PORT
Std_ToStr(std::string strFormat,
unsigned short iVal)
528 {
return str(boost::format(
"%d") % iVal);}
541 std::string STD_UTILS_PORT
Std_ToStr(std::string strFormat,
int iVal)
542 {
return str(boost::format(
"%d") % iVal);}
555 std::string STD_UTILS_PORT
Std_ToStr(std::string strFormat,
long lVal)
556 {
return str(boost::format(
"%d") % lVal);}
569 std::string STD_UTILS_PORT
Std_ToStr(std::string strFormat,
float fltVal)
570 {
return str(boost::format(
"%f") % fltVal);}
583 std::string STD_UTILS_PORT
Std_ToStr(std::string strFormat,
double dblVal)
584 {
return str(boost::format(
"%f") % dblVal);}
618 if(strV ==
"TRUE" || strV ==
"1")
636 if(strFormat.length())
637 return (
"'" + strFormat +
"'");
654 std::string STD_UTILS_PORT Std_ConvertToANSI(LPCWSTR strData)
657 int len = WideCharToMultiByte(CP_ACP, 0, strData, -1, 0, 0, 0, 0);
659 LPSTR result =
new char[len];
661 WideCharToMultiByte(CP_ACP, 0, strData, -1, result, len, 0, 0);
663 std::string strVal = result;
680 LPWSTR STD_UTILS_PORT Std_ConvertFromANSI(std::string strData)
683 int len = MultiByteToWideChar(CP_ACP, 0, strData.c_str(), -1, 0, 0);
685 wchar_t *result =
new wchar_t[len];
687 MultiByteToWideChar(CP_ACP, 0, strData.c_str(), -1, result, len);
708 if(strType ==
"EMPTY")
710 else if(strType ==
"SHORT")
712 else if(strType ==
"LONG")
714 else if(strType ==
"FLOAT")
716 else if(strType ==
"DOUBLE")
718 else if(strType ==
"bool")
720 else if(strType ==
"CHAR")
722 else if(strType ==
"UCHAR")
724 else if(strType ==
"USHORT")
726 else if(strType ==
"ULONG")
728 else if(strType ==
"INT")
730 else if(strType ==
"UINT")
732 else if(strType ==
"STRING")
735 THROW_PARAM_ERROR(Std_Err_lInvalidVariantType, Std_Err_strInvalidVariantType,
"VariantType", strType);
780 THROW_PARAM_ERROR(Std_Err_lInvalidVariantType, Std_Err_strInvalidVariantType,
"VariantType", iType);
798 int STD_UTILS_PORT
Std_Split(
const std::string& input,
const std::string& delimiter, CStdArray<std::string> &results)
802 int sizeS2 = delimiter.size();
803 int isize = input.size();
805 std::vector<int> positions;
808 newPos = input.find (delimiter, 0);
812 std::string strInput = input;
817 results.push_back(strInput);
826 while( newPos > iPos )
829 positions.push_back(newPos);
831 newPos = input.find (delimiter, iPos+sizeS2+1);
834 for(
int i=0; i <= positions.size(); i++ )
838 {s = input.substr( i, positions[i] ); }
841 int offset = positions[i-1] + sizeS2;
844 if( i == positions.size() )
846 s = input.substr(offset);
850 s = input.substr( positions[i-1] + sizeS2, positions[i] - positions[i-1] - sizeS2 );
857 results.push_back(s);
860 return results.GetSize();
874 std::string STD_UTILS_PORT
Std_Combine(CStdArray<std::string> &aryParts, std::string strDelimiter)
876 std::string strCombined;
877 int iCount = aryParts.GetSize();
878 for(
int iPart=0; iPart<iCount; iPart++)
880 strCombined += aryParts[iPart];
881 if(iPart<iCount-1) strCombined += strDelimiter;
897 std::string STD_UTILS_PORT
Std_Trim(std::string strVal)
913 {
return !std::isspace(c);}
927 strVal.erase(strVal.begin(), std::find_if(strVal.begin(), strVal.end(),
NotSpace));
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);
953 strVal.erase(!(it == strVal.rend()) ? strVal.find_last_of(*it) + 1 : 0);
969 int iPos = strVal.find_first_not_of(
"0123456789.+-eE");
970 if(iPos == -1 && strVal.length() > 0)
988 int iPos = strVal.find_first_not_of(
"0123456789+-");
1006 std::string STD_UTILS_PORT
Std_Left(std::string strVal,
int iCount)
1008 iCount = SSMAX(0, SSMIN(iCount, static_cast<int>(strVal.length())));
1009 return strVal.substr(0, iCount);
1023 std::string STD_UTILS_PORT
Std_Right(std::string strVal,
int iCount)
1025 iCount = SSMAX(0, SSMIN(iCount, static_cast<int>(strVal.length())));
1026 return strVal.substr(strVal.length()-iCount);
1041 std::transform(strVal.begin(), strVal.end(), strVal.begin(), (int(*)(int))std::toupper);
1057 std::transform(strVal.begin(), strVal.end(), strVal.begin(), (int(*)(int))std::tolower);
1073 std::string STD_UTILS_PORT
Std_Replace(std::string strVal, std::string strFind, std::string strReplace)
1075 int i = strVal.find(strFind, 0);
1076 while(i != std::string::npos)
1078 strVal.replace(i, strFind.size(), strReplace);
1079 i = strVal.find(strFind, 0);
1096 long STD_UTILS_PORT
Std_RGB(
unsigned char iRed,
unsigned char iGreen,
unsigned char iBlue)
1098 return ((iBlue << 16) | (iGreen << 8) | (iRed));
1115 long STD_UTILS_PORT
Std_LoadRGB(
CStdXml &oXml, std::string strParamName,
bool bThrowError,
long lDefault)
1122 Std_InValidRange((
int) 0, (
int) 255, iRed,
true, (strParamName +
"::Red"));
1125 Std_InValidRange((
int) 0, (
int) 255, iGreen,
true, (strParamName +
"::Green"));
1128 Std_InValidRange((
int) 0, (
int) 255, iBlue,
true, (strParamName +
"::Blue"));
1130 lVal =
Std_RGB(iRed, iGreen, iBlue);
1161 else if(bThrowError)
1162 THROW_TEXT_ERROR(Std_Err_lParamNotFound, Std_Err_strParamNotFound, strParamName);
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);
1189 void STD_UTILS_PORT
Std_LoadColor(std::string strXml, std::string strParamName,
float *aryColor,
bool bThrowError)
1229 int STD_UTILS_PORT
Std_Sign(
float fltVal,
float fltDefault)
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);
1256 {init_genrand(lSeed);}
1272 return (
int) (( abs(high-low) * genrand_real2() ) + low);
1290 return (
long) (( abs(high-low) * genrand_real2() ) + low);
1306 {
return (
float) (( fabs(high-low) * genrand_real1() ) + low);}
1321 {
return (( fabs(high-low) * genrand_real1() ) + low);}
1337 bool STD_UTILS_PORT
Std_InValidRange(
int iMinVal,
int iMaxVal,
int iVal,
bool bThrowError, std::string strParamName)
1340 if( (iVal>=iMinVal) && (iVal<=iMaxVal) )
1346 std::ostringstream oss;
1348 if(!strParamName.empty())
1349 oss <<
"Paramater: " << strParamName;
1351 oss <<
" Value: " << iVal <<
" Range [";
1352 oss << iMinVal <<
", " << iMaxVal <<
"]";
1354 THROW_TEXT_ERROR(Std_Err_lValueOutOfRange, Std_Err_strValueOutOfRange, oss.str().c_str());
1376 bool STD_UTILS_PORT
Std_InValidRange(
long lMinVal,
long lMaxVal,
long lVal,
bool bThrowError, std::string strParamName)
1379 if( (lVal>=lMinVal) && (lVal<=lMaxVal) )
1385 std::ostringstream oss;
1387 if(!strParamName.empty())
1388 oss <<
"Paramater: " << strParamName;
1390 oss <<
" Value: " << lVal <<
" Range [";
1391 oss << lMinVal <<
", " << lMaxVal <<
"]";
1393 THROW_TEXT_ERROR(Std_Err_lValueOutOfRange, Std_Err_strValueOutOfRange, oss.str().c_str());
1415 bool STD_UTILS_PORT
Std_InValidRange(
float fltMinVal,
float fltMaxVal,
float fltVal,
bool bThrowError, std::string strParamName)
1418 if( (fltVal>=fltMinVal) && (fltVal<=fltMaxVal) )
1424 std::ostringstream oss;
1426 if(!strParamName.empty())
1427 oss <<
"Paramater: " << strParamName;
1429 oss <<
" Value: " << fltVal <<
" Range [";
1430 oss << fltMinVal <<
", " << fltMaxVal <<
"]";
1432 THROW_TEXT_ERROR(Std_Err_lValueOutOfRange, Std_Err_strValueOutOfRange, oss.str().c_str());
1454 bool STD_UTILS_PORT
Std_InValidRange(
double dblMinVal,
double dblMaxVal,
double dblVal,
bool bThrowError, std::string strParamName)
1457 if( (dblVal>=dblMinVal) && (dblVal<=dblMaxVal) )
1463 std::ostringstream oss;
1465 if(!strParamName.empty())
1466 oss <<
"Paramater: " << strParamName;
1468 oss <<
" Value: " << dblVal <<
" Range [";
1469 oss << dblMinVal <<
", " << dblMaxVal <<
"]";
1471 THROW_TEXT_ERROR(Std_Err_lValueOutOfRange, Std_Err_strValueOutOfRange, oss.str().c_str());
1493 bool STD_UTILS_PORT
Std_IsBelowMax(
int iMaxVal,
int iVal,
bool bThrowError, std::string strParamName,
bool bInclusiveLimit)
1496 if( (!bInclusiveLimit && iVal<iMaxVal) || (bInclusiveLimit && iVal<=iMaxVal) )
1502 std::ostringstream oss;
1504 if(!strParamName.empty())
1505 oss <<
"Paramater: " << strParamName;
1507 oss <<
" Value: " << iVal <<
" Maximum: " << iMaxVal;
1509 THROW_TEXT_ERROR(Std_Err_lAboveMaxValue, Std_Err_strAboveMaxValue, oss.str().c_str());
1531 bool STD_UTILS_PORT
Std_IsBelowMax(
long lMaxVal,
long lVal,
bool bThrowError, std::string strParamName,
bool bInclusiveLimit)
1534 if( (!bInclusiveLimit && lVal<lMaxVal) || (bInclusiveLimit && lVal<=lMaxVal) )
1540 std::ostringstream oss;
1542 if(!strParamName.empty())
1543 oss <<
"Paramater: " << strParamName;
1545 oss <<
" Value: " << lVal <<
" Maximum: " << lMaxVal;
1547 THROW_TEXT_ERROR(Std_Err_lAboveMaxValue, Std_Err_strAboveMaxValue, oss.str().c_str());
1569 bool STD_UTILS_PORT
Std_IsBelowMax(
float fltMaxVal,
float fltVal,
bool bThrowError, std::string strParamName,
bool bInclusiveLimit)
1572 if( (!bInclusiveLimit && fltVal<fltMaxVal) || (bInclusiveLimit && fltVal<=fltMaxVal) )
1578 std::ostringstream oss;
1580 if(!strParamName.empty())
1581 oss <<
"Paramater: " << strParamName;
1583 oss <<
" Value: " << fltVal <<
" Maximum: " << fltMaxVal;
1585 THROW_TEXT_ERROR(Std_Err_lAboveMaxValue, Std_Err_strAboveMaxValue, oss.str().c_str());
1607 bool STD_UTILS_PORT
Std_IsBelowMax(
double dblMaxVal,
double dblVal,
bool bThrowError, std::string strParamName,
bool bInclusiveLimit)
1610 if( (!bInclusiveLimit && dblVal<dblMaxVal) || (bInclusiveLimit && dblVal<=dblMaxVal) )
1616 std::ostringstream oss;
1618 if(!strParamName.empty())
1619 oss <<
"Paramater: " << strParamName;
1621 oss <<
" Value: " << dblVal <<
" Maximum: " << dblMaxVal;
1623 THROW_TEXT_ERROR(Std_Err_lAboveMaxValue, Std_Err_strAboveMaxValue, oss.str().c_str());
1645 bool STD_UTILS_PORT
Std_IsAboveMin(
int iMinVal,
int iVal,
bool bThrowError, std::string strParamName,
bool bInclusiveLimit)
1648 if( (!bInclusiveLimit && iVal>iMinVal) || (bInclusiveLimit && iVal>=iMinVal) )
1654 std::ostringstream oss;
1656 if(!strParamName.empty())
1657 oss <<
"Paramater: " << strParamName;
1659 oss <<
" Value: " << iVal <<
" Minimum: " << iMinVal;
1661 THROW_TEXT_ERROR(Std_Err_lBelowMinValue, Std_Err_strBelowMinValue, oss.str().c_str());
1683 bool STD_UTILS_PORT
Std_IsAboveMin(
long lMinVal,
long lVal,
bool bThrowError, std::string strParamName,
bool bInclusiveLimit)
1686 if( (!bInclusiveLimit && lVal>lMinVal) || (bInclusiveLimit && lVal>=lMinVal) )
1692 std::ostringstream oss;
1694 if(!strParamName.empty())
1695 oss <<
"Paramater: " << strParamName;
1697 oss <<
" Value: " << lVal <<
" Minimum: " << lMinVal;
1699 THROW_TEXT_ERROR(Std_Err_lBelowMinValue, Std_Err_strBelowMinValue, oss.str().c_str());
1721 bool STD_UTILS_PORT
Std_IsAboveMin(
float fltMinVal,
float fltVal,
bool bThrowError, std::string strParamName,
bool bInclusiveLimit)
1724 if( (!bInclusiveLimit && fltVal>fltMinVal) || (bInclusiveLimit && fltVal>=fltMinVal) )
1730 std::ostringstream oss;
1732 if(!strParamName.empty())
1733 oss <<
"Paramater: " << strParamName;
1735 oss <<
" Value: " << fltVal <<
" Minimum: " << fltMinVal;
1737 THROW_TEXT_ERROR(Std_Err_lBelowMinValue, Std_Err_strBelowMinValue, oss.str().c_str());
1759 bool STD_UTILS_PORT
Std_IsAboveMin(
double dblMinVal,
double dblVal,
bool bThrowError, std::string strParamName,
bool bInclusiveLimit)
1762 if( (!bInclusiveLimit && dblVal>dblMinVal) || (bInclusiveLimit && dblVal>=dblMinVal) )
1768 std::ostringstream oss;
1770 if(!strParamName.empty())
1771 oss <<
"Paramater: " << strParamName;
1773 oss <<
" Value: " << dblVal <<
" Minimum: " << dblMinVal;
1775 THROW_TEXT_ERROR(Std_Err_lBelowMinValue, Std_Err_strBelowMinValue, oss.str().c_str());
1795 std::string strTemp = strVal;
1812 std::string strTemp =
Std_Trim(strVal);
1813 if(!strTemp.length())
1820 std::string STD_UTILS_PORT Std_RetrieveParam(
int argc,
const char **argv, std::string strParamName,
bool bThrowError)
1823 bool bRetrieved=
false, bFound =
false;
1824 std::string strParam=
"", strFound =
"";
1825 while(!bRetrieved && iParam<argc)
1835 if(strParam == strParamName)
1841 if(bThrowError && !bRetrieved)
1842 THROW_PARAM_ERROR(Std_Err_lNoProjectParamOnCommandLine, Std_Err_strNoProjectParamOnCommandLine,
"Param", strParamName);
1864 {
return ( x >> i) & 1;}
1882 unsigned long bit_put (
unsigned long x,
int i,
unsigned long v)
1885 return x | (1 << i);
1887 return x & ~(1 << i);
1920 std::string strByte;
1921 int iByte, iByteLength;
1924 iByteLength = aryBytes.GetSize();
1926 for(iByte=0; iByte<iByteLength; iByte++)
1928 str(boost::format(
"%02x") % aryBytes[iByte]);
1945 int iLength, iByteSize, iNibble0, iNibble1, iByte;
1948 aryBytes.RemoveAll();
1950 iLength = strHex.length();
1951 iByteSize = iLength / 2;
1952 aryBytes.SetSize(iByteSize);
1954 for(iByte=0; iByte<iByteSize; iByte++)
1957 iNibble1 = (iByte*2) + 1;
1960 aryBytes[iByte] = cVal;
1977 int iLength, iByteSize, iNibble0, iNibble1, iByte;
1979 unsigned char *lpBytes = NULL;
1981 iLength = strHex.length();
1982 iByteSize = iLength / 2;
1984 lpBytes =
new unsigned char[iByteSize];
1986 for(iByte=0; iByte<iByteSize; iByte++)
1989 iNibble1 = (iByte*2) + 1;
1992 lpBytes[iByte] = cVal;
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);
2035 if (cVal >=
'0' && cVal <=
'9')
2036 return (cVal -
'0');
2038 if (cVal >=
'A' && cVal <=
'F')
2039 return ((cVal -
'A') + 0x0A);
2044 THROW_PARAM_ERROR(Std_Err_lInvalidHexChar, Std_Err_strInvalidHexChar,
"HexValue", strVal);
2062 {
return (8*aryRawData.GetSize());}
2098 void STD_UTILS_PORT
Std_GetBinarySection(CStdArray<unsigned char> &aryRawData,
long lStartBit,
long lBitLength,
unsigned char &cOut)
2100 CStdArray<unsigned char> aryOutData;
2106 cOut = aryOutData[aryOutData.GetSize()-1];
2143 void STD_UTILS_PORT
Std_GetBinarySection(CStdArray<unsigned char> &aryRawData,
long lStartBit,
long lBitLength,
unsigned short &iOut)
2145 CStdArray<unsigned char> aryOutData;
2146 short iByte, iByteCount, iArraySize;
2152 iArraySize = aryOutData.GetSize()-1;
2155 for(iByte=iArraySize; iByte>=0 && iByteCount<2; iByte--)
2157 iOut += (aryOutData[iByte] << (iByteCount*8));
2196 void STD_UTILS_PORT
Std_GetBinarySection(CStdArray<unsigned char> &aryRawData,
long lStartBit,
long lBitLength,
unsigned long &lOut)
2198 CStdArray<unsigned char> aryOutData;
2199 short iByte, iByteCount, iArraySize;
2205 iArraySize = aryOutData.GetSize()-1;
2208 for(iByte=iArraySize; iByte>=0 && iByteCount<4; iByte--)
2210 lOut += (aryOutData[iByte] << (iByteCount*8));
2250 CStdArray<unsigned char> &aryOutData)
2252 long lEndBit, lByteLength, lBit, lBitsNeeded, lByte;
2254 lEndBit = lStartBit + lBitLength - 1;
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");
2260 lByteLength = ((long) ceil((
float) (lBitLength / 8))) + 1;
2262 lByteLength = lBitLength / 8;
2264 aryOutData.RemoveAll();
2265 aryOutData.SetSize(lByteLength);
2268 for(lByte=(lByteLength-1); lByte>=0; lByte--)
2270 lBitsNeeded = lBitLength - (lEndBit-lBit);
2271 if(lBitsNeeded>8) lBitsNeeded = 8;
2291 unsigned char STD_UTILS_PORT
Std_GetByteFromArray(CStdArray<unsigned char> &aryRawData,
long lEndBit,
long lBitsNeeded)
2293 unsigned char cVal=0;
2294 long lBitIndex, lBit;
2298 for(lBitIndex=0; lBitIndex<lBitsNeeded; lBitIndex++)
2300 lBit = lEndBit - lBitIndex;
2303 cVal += (1 << lBitIndex);
2326 lByte = (long) (lBit/8);
2327 iShift = lBit - (lByte*8);
2328 cVal = aryRawData[lByte];
2330 if(cVal & (0x80 >> iShift))
2349 void STD_UTILS_PORT
Std_SetBinarySection(CStdArray<unsigned char> &aryRawData,
long lStartBit,
long lBitLength,
unsigned char cIn)
2355 lEndBit = lStartBit + lBitLength-1;
2372 void STD_UTILS_PORT
Std_SetBinarySection(CStdArray<unsigned char> &aryRawData,
long lStartBit,
long lBitLength,
unsigned short iIn)
2374 CStdArray<unsigned char> aryIn;
2379 cVal = (
unsigned char) ((iIn & 0xFF00) >> 8);
2382 cVal = (
unsigned char) (iIn & 0x00FF);
2400 void STD_UTILS_PORT
Std_SetBinarySection(CStdArray<unsigned char> &aryRawData,
long lStartBit,
long lBitLength,
unsigned long lIn)
2402 CStdArray<unsigned char> aryIn;
2407 cVal = (
unsigned char) ((lIn & 0xFF000000) >> 24);
2410 cVal = (
unsigned char) ((lIn & 0x00FF0000) >> 16);
2413 cVal = (
unsigned char) ((lIn & 0x0000FF00) >> 8);
2416 cVal = (
unsigned char) (lIn & 0x000000FF);
2435 CStdArray<unsigned char> &aryInData)
2437 long lEndBit, lByteLength, lBit, lBitsNeeded, lByte, lNumBytes, lLastByte;
2439 lEndBit = lStartBit + lBitLength - 1;
2441 Std_InValidRange((
long) 1, (
long) (aryInData.GetSize() * 8), lBitLength,
true,
"BitLength");
2444 lByteLength = ((long) ceil((
float) (lBitLength / 8))) + 1;
2446 lByteLength = lBitLength / 8;
2448 lNumBytes = aryInData.GetSize();
2449 lLastByte = lNumBytes - lByteLength;
2452 for(lByte=(lNumBytes-1); lByte>=lLastByte; lByte--)
2454 lBitsNeeded = lBitLength - (lEndBit-lBit);
2455 if(lBitsNeeded>8) lBitsNeeded = 8;
2477 CStdArray<unsigned char> &aryOutData,
long lStartOutBit,
2480 CStdArray<unsigned char> aryTempData;
2499 void STD_UTILS_PORT
Std_SetByteInArray(CStdArray<unsigned char> &aryRawData,
unsigned char cIn,
long lEndBit,
long lBitsNeeded)
2501 long lBitIndex, lBit;
2505 for(lBitIndex=0; lBitIndex<lBitsNeeded; lBitIndex++)
2507 lBit = lEndBit - lBitIndex;
2534 lByte = (long) (lBit/8);
2535 iShift = lBit - (lByte*8);
2537 if(lByte>=aryRawData.GetSize())
2538 aryRawData.SetSize(lByte+1);
2540 cVal = aryRawData[lByte];
2543 cVal = cVal | (0x80 >> iShift);
2545 cVal = cVal & (0xFF7F >> iShift);
2547 aryRawData[lByte] = cVal;
2563 Std_IsAboveMin((
long) -1, lBitLength,
true,
"SetBitRangeInArray::BitLength");
2564 Std_IsAboveMin((
long) -1, lStartBit,
true,
"SetBitRangeInArray::StartBit");
2566 long lEndBit=lStartBit + lBitLength;
2567 for(
long lBit=lStartBit; lBit<lEndBit; lBit++)
2600 Std_IsAboveMin((
long) -1, lBitLength,
true,
"FlipBitRangeInArray::BitLength");
2601 Std_IsAboveMin((
long) -1, lStartBit,
true,
"FlipBitRangeInArray::StartBit");
2603 long lEndBit=lStartBit + lBitLength;
2604 for(
long lBit=lStartBit; lBit<lEndBit; lBit++)
2622 bool STD_UTILS_PORT
Std_ReadBinaryData(CStdArray<unsigned char> &aryBinaryData,
long lLastBit,
long &lStartBit,
long lBitLength,
unsigned char &cOut)
2627 lEndBit = lStartBit + lBitLength-1;
2634 TRACE_DETAIL_NS(
"[ReadBinaryData(uchar)] Value: " + STR(cOut) +
" StartBit: " + STR(lStartBit) +
" BitLength: " + STR(lBitLength));
2637 lStartBit+=lBitLength;
2656 bool STD_UTILS_PORT
Std_ReadBinaryData(CStdArray<unsigned char> &aryBinaryData,
long lLastBit,
long &lStartBit,
long lBitLength,
unsigned short &iOut)
2661 lEndBit = lStartBit + lBitLength-1;
2668 TRACE_DETAIL_NS(
"[ReadBinaryData(ushort)] Value: " + STR(iOut) +
" StartBit: " + STR(lStartBit) +
" BitLength: " + STR(lBitLength));
2671 lStartBit+=lBitLength;
2690 bool STD_UTILS_PORT
Std_ReadBinaryData(CStdArray<unsigned char> &aryBinaryData,
long lLastBit,
long &lStartBit,
long lBitLength,
unsigned long &lOut)
2695 lEndBit = lStartBit + lBitLength-1;
2702 TRACE_DETAIL_NS(
"[ReadBinaryData(ulong)] Value: " + STR((
long) lOut) +
" StartBit: " + STR(lStartBit) +
" BitLength: " + STR(lBitLength));
2705 lStartBit+=lBitLength;
2722 void STD_UTILS_PORT
Std_WriteBinaryData(CStdArray<unsigned char> &aryBinaryData,
long &lStartBit,
long lBitLength,
unsigned char cIn)
2724 TRACE_DETAIL_NS(
"[WriteBinaryData(uchar)] Value: " + STR(cIn) +
" StartBit: " + STR(lStartBit) +
" BitLength: " + STR(lBitLength));
2729 lStartBit+=lBitLength;
2745 void STD_UTILS_PORT
Std_WriteBinaryData(CStdArray<unsigned char> &aryBinaryData,
long &lStartBit,
long lBitLength,
unsigned short iIn)
2747 TRACE_DETAIL_NS(
"[WriteBinaryData(ushort)] Value: " + STR(iIn) +
" StartBit: " + STR(lStartBit) +
" BitLength: " + STR(lBitLength));
2752 lStartBit+=lBitLength;
2768 void STD_UTILS_PORT
Std_WriteBinaryData(CStdArray<unsigned char> &aryBinaryData,
long &lStartBit,
long lBitLength,
unsigned long lIn)
2770 TRACE_DETAIL_NS(
"[WriteBinaryData(ulong)] Value: " + STR((
long) lIn) +
" StartBit: " + STR(lStartBit) +
" BitLength: " + STR(lBitLength));
2775 lStartBit+=lBitLength;
2791 unsigned char cOut=0;
2793 for(iBit=0; iBit< 7; iBit++)
2799 TRACE_DETAIL_NS(
"[BinaryToGreyCode(uchar)] Input: " + STR(cVal) +
" Output: " + STR(cOut));
2818 unsigned short iOut=0;
2820 for(iBit=0; iBit< 15; iBit++)
2826 TRACE_DETAIL_NS(
"[BinaryToGreyCode(ushort)] Input: " + STR(iVal) +
" Output: " + STR(iOut));
2844 unsigned long lOut=0;
2846 for(iBit=0; iBit< 31; iBit++)
2852 TRACE_DETAIL_NS(
"[BinaryToGreyCode(ulong)] Input: " + STR((
long) lVal) +
" Output: " + STR((
long) lOut));
2870 short iBit, iTempBit;
2871 unsigned char cOut=0, cTemp;
2874 for (iBit = 0; iBit <= 7; iBit++ )
2877 for (iTempBit = iBit; iTempBit <= 7; iTempBit++ )
2878 cTemp ^=
bit_get(cVal, iTempBit);
2880 cOut = (
unsigned char)
bit_put (cOut, iBit, cTemp);
2883 TRACE_DETAIL_NS(
"[GreyCodeToBinary(uchar)] Input: " + STR(cVal) +
" Output: " + STR(cOut));
2900 short iBit, iTempBit;
2901 unsigned short iOut=0, iTemp;
2904 for (iBit = 0; iBit <= 15; iBit++ )
2907 for (iTempBit = iBit; iTempBit <= 15; iTempBit++ )
2908 iTemp ^=
bit_get(iVal, iTempBit);
2910 iOut = (
unsigned short)
bit_put (iOut, iBit, iTemp);
2913 TRACE_DETAIL_NS(
"[BinaryToGreyCode(ushort)] Input: " + STR(iVal) +
" Output: " + STR(iOut));
2931 short iBit, iTempBit;
2932 unsigned long lOut=0, lTemp;
2935 for (iBit = 0; iBit <= 31; iBit++ )
2938 for (iTempBit = iBit; iTempBit <= 31; iTempBit++ )
2939 lTemp ^=
bit_get(lVal, iTempBit);
2941 lOut =
bit_put (lOut, iBit, lTemp);
2944 TRACE_DETAIL_NS(
"[BinaryToGreyCode(ulong)] Input: " + STR((
long) lVal) +
" Output: " + STR((
long) lOut));
2957 int g_iTraceLevel = 0;
2960 {
return g_iTraceLevel;}
2963 {g_iTraceLevel = iLevel;}
2966 {g_iTraceLevel = iLevel;}
2968 void STD_UTILS_PORT
Std_LogMsg(
const int iLevel, std::string strMessage, std::string strSourceFile,
int iSourceLine,
bool bPrintHeader)
2971 if(iLevel>g_iTraceLevel)
2974 std::string strFinalMessage;
2977 strFinalMessage = STR(strSourceFile) +
" (" + STR(iSourceLine) +
") \r\n" + STR(strMessage) +
"\r\n";
2979 strFinalMessage = strMessage;
2981 STLOG_WRITE(strFinalMessage.c_str());
2984 void STD_UTILS_PORT
Std_TraceMsg(
const int iLevel, std::string strMessage, std::string strSourceFile,
int iSourceLine,
bool bLogToFile,
bool bPrintHeader)
2986 std::string strTemp = strMessage +
"\r\n";
2988 #ifdef STD_TRACE_TO_DEBUGGER
2989 wchar_t *sMessage = Std_ConvertFromANSI(strTemp);
2992 OutputDebugString(sMessage);
2999 Std_LogMsg(iLevel, strMessage, strSourceFile, iSourceLine, bPrintHeader);
3002 void STD_UTILS_PORT Std_ResetLog()
3004 CSTLogFile::GetLogFile()->Stop();
3019 return GetTraceLevel();
3037 SetTraceLevel(iVal);
3053 if(GetTraceFilePrefix() != strFilePrefix)
3054 SetTraceFilePrefix(strFilePrefix.c_str());
3069 return GetTraceFilePrefix();
3087 SetTraceLevel(iLevel);
3104 void STD_UTILS_PORT
Std_LogMsg(
const int iLevel, std::string strMessage, std::string strSourceFile,
int iSourceLine,
bool bPrintHeader)
3107 if(GetTraceLevel()==0 || iLevel>GetTraceLevel())
3110 std::string strFinalMessage;
3113 strFinalMessage = STR(strSourceFile) +
" (" + STR(iSourceLine) +
") \r\n" + STR(strMessage) +
"\r\n";
3115 strFinalMessage = strMessage;
3117 Std_Log(iLevel, bPrintHeader, strFinalMessage.c_str());
3119 std::cout << strMessage;
3137 void STD_UTILS_PORT
Std_TraceMsg(
const int iLevel, std::string strMessage, std::string strSourceFile,
int iSourceLine,
bool bLogToFile,
bool bPrintHeader)
3140 int iLogLevel = GetTraceLevel();
3141 if(iLogLevel==0||iLevel>iLogLevel)
return;
3143 std::string strTemp = strMessage +
"\r\n";
3145 #ifdef STD_TRACE_TO_DEBUGGER
3146 OutputDebugString(strTemp.c_str());
3152 strMessage = STR(strSourceFile) +
" (" + STR(iSourceLine) +
") \r\n" + STR(strMessage) +
"\r\n";
3154 Std_Log(iLevel, bPrintHeader, strMessage.c_str());
3182 return GetTickCount64();
3190 void STD_UTILS_PORT Std_Sleep(
unsigned long lMilliseconds)
3193 Sleep(lMilliseconds);
3195 sleep(lMilliseconds);
3220 return boost::filesystem::path(strPath).has_root_path();
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();
3249 catch(
const boost::filesystem::filesystem_error& e)
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";
3255 std::cout <<
"is_directory(" <<
") failed with "
3256 << e.code().message() <<
'\n';
3272 boost::filesystem::path p = boost::filesystem::path(strPath);
3273 return boost::filesystem::is_directory(p);
3289 boost::filesystem::path path = boost::filesystem::canonical(strFullPath);
3292 catch(
const boost::filesystem::filesystem_error& e)
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";
3298 std::cout <<
"is_directory(" <<
") failed with "
3299 << e.code().message() <<
'\n';
3314 std::string strPath =
"";
3315 char strBuffer[2000];
3319 HINSTANCE hInst = GetModuleHandle(NULL);
3320 GetModuleFileName(hInst, strBuffer, 2000);
3322 ssize_t len = ::readlink(
"/proc/self/exe", strBuffer,
sizeof(strBuffer)-1);
3324 strBuffer[len] =
'\0';
3326 THROW_ERROR(Std_Err_lModuleNotLoaded, Std_Err_strModuleNotLoaded);
3329 strPath = strBuffer;
3337 void Std_SetFileTime(std::string strFilename, SYSTEMTIME newTime)
3341 FILETIME thefiletime;
3342 SystemTimeToFileTime(&newTime,&thefiletime);
3345 HANDLE filename = CreateFile(strFilename.c_str(), FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
3348 SetFileTime(filename,(LPFILETIME) NULL,(LPFILETIME) NULL,&thefiletime);
3351 CloseHandle(filename);
3354 void STD_UTILS_PORT Std_SetFileTime(std::string strFilename)
3357 SYSTEMTIME thesystemtime;
3361 GetSystemTime(&thesystemtime);
3363 Std_SetFileTime(strFilename, thesystemtime);
3369 void STD_UTILS_PORT Std_SetFileTime(std::string strFilename)
3371 utime(strFilename.c_str(), NULL);
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.
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.
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.
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.
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.
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.
Information about the standard error.
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.
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.
A standard xml manipulation class.
int Std_GetTraceLevel()
Gets the trace level.
long m_lSourceLine
The source line code line where the error occurred.
virtual float GetAttribFloat(std::string strAttribName, bool bThrowError=true, float fltDefault=0)
Gets an attribute float.
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.
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.
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.
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.