// *************************************************************** // Function: ConfigLoader.cpp // *************************************************************** #include "ConfigLoader.h" #include "Utility.h" ConfigLoader::ConfigLoader() { mErrorCode=0; } //************************************ // Name: GetDataAsInt // // Gets data by name as an integer. // // Parameters: // pName - tag name // pDestBuf - Destination buffer // // Return: // 0 - no errors // -1 - errors //************************************ int ConfigLoader::GetDataAsInt(char* pName, int* pDestBuf) { int index=-1; if ((index=GetCFIndexByName(pName))!=-1) { int t=0; if (mArgs[index].info[1]=='x' || mArgs[index].info[1]=='X') { t=Util::HexToDecimal(mArgs[index].info); Util::ReverseLongByteOrder((long*)&t); } else { t=atoi(mArgs[index].info); } *pDestBuf=t; return 0; } else { mErrorCode=-1; return -1; } } ConfigLoader::~ConfigLoader() { mArgs.clear(); } //************************************ // Name: CleanUp // // Cleans up // // Parameters: // // Return: // //************************************ void ConfigLoader::CleanUp() { mArgs.clear(); } //************************************ // Name: GetDataAsUInt // // Gets a tag as an unsigned integer // // Parameters: // pName - tag name // pDest - Destination buffer // // Return: // 0 - no errors // -1 - errors //************************************ int ConfigLoader::GetDataAsUInt(char* pName, unsigned int* pDest) { int index=-1; if ((index=GetCFIndexByName(pName))!=-1) { unsigned int t=0; if (mArgs[index].info[1]=='x' || mArgs[index].info[1]=='X') { t=Util::HexToDecimal(mArgs[index].info); Util::ReverseLongByteOrder((long*)&t); } else { t=atoi(mArgs[index].info); } *pDest=t; return 0; } else { mErrorCode=-1; return -1; } } //************************************ // Name: GetDataAsShort // // Gets a tag as a short. // // Parameters: // pName - tag name // pDest - Destination buffer // // Return: // 0 - no errors // -1 - errors //************************************ int ConfigLoader::GetDataAsShort(char* pName, short* pDest) { int index=-1; if ((index=GetCFIndexByName(pName))!=-1) { short t=atoi(mArgs[index].info); *pDest=t; return 0; } else { mErrorCode=-1; return -1; } } //************************************ // Name: GetDataAsShortX // // Gets a tag as a short and reverses the byte order. // // Parameters: // pName - tag name // pDestBuf - Dest buffer // // Return: // 0 - no errors // -1 - errors //************************************ int ConfigLoader::GetDataAsShortX(char* pName, unsigned short* pDestBuf) { int index=-1; if ((index=GetCFIndexByName(pName))!=-1) { unsigned short t=(unsigned short)Util::HexToDecimal(mArgs[index].info); Util::ReverseShortByteOrder((short*)&t); *pDestBuf=t; return 0; } else { mErrorCode=-1; return -1; } } //************************************ // Name: GetDataAsBool // // Gets a tag as boolean. // // Parameters: // pName - tag name // pDestBuf - Dest buffer // // Return: // 0 - no errors // -1 - errors //************************************ int ConfigLoader::GetDataAsBool(char* pName, bool* pDestBuf) { int index=-1; if ((index=GetCFIndexByName(pName))!=-1) { if (strcmp(mArgs[index].info, "true")==0) *pDestBuf=true; else *pDestBuf=false; return 0; } else { mErrorCode=-1; return -1; } } //************************************ // Name: GetDataAsIPBytes // // Gets a tag as an IP Address (byte form) // // Parameters: // pName - tag name // pDestBuf - Dest buffer // // Return: // 0 - no errors // -1 - errors //************************************ int ConfigLoader::GetDataAsIPBytes(char* pName, unsigned char* pDestBuf) { int index=-1; if ((index=GetCFIndexByName(pName))!=-1) { char temp[500]; strcpy(temp, mArgs[index].info); char *p=strtok(temp, "."); for (int i=0; i<4; i++) { pDestBuf[i]=(char)atoi(p); p=strtok(0, "."); } return 0; } else { mErrorCode=-1; return -1; } } //************************************ // Name: ErrorOccurred // // Checks for internal class errors. // // Parameters: // // Return: // true - An error has occurred. // false - No errors //************************************ bool ConfigLoader::ErrorOccurred() { if (mErrorCode!=0) { return true; } return false; } //************************************ // Name: GetDataAsString // // Gets a tag as a string. // // Parameters: // pName - tag name // pDestBuf - Dest buffer // // Return: // 0 - no errors // -1 - errors //************************************ int ConfigLoader::GetDataAsString(char* pName, char* pDestBuf) { int index=-1; if ((index=GetCFIndexByName(pName))!=-1) { strcpy(pDestBuf, mArgs[index].info); return 0; } else { mErrorCode=-1; return -1; } } //************************************ // Name: GetCFIndexByName // // Get tag index by name (Internal only) // // Parameters: // pName - tag name // // Return: // >-1 - index of tag data // -1 - No tag exists with specified name //************************************ int ConfigLoader::GetCFIndexByName(char* pName) { char name2[100]; memset(name2, 0, 100); //Convert to lowercase for (unsigned int i=0; i32) { for (unsigned int i=0; i32 || (ty==32 && in_quotes)) && ty!='\n' && ty!=';')/* || ty==0*/) { eq2++; } else{break;} } *(eq2)=0; } mArgs.push_back(CF(temp, eq+1+start_of_info)); } lc++; } fin.close(); return 0; }