imgtools/imglib/parameterfileprocessor/source/parameterfileprocessor.cpp
changeset 590 360bd6b35136
parent 0 044383f39525
equal deleted inserted replaced
588:c7c26511138f 590:360bd6b35136
    29 @param aParamFileName parameter-file name
    29 @param aParamFileName parameter-file name
    30 
    30 
    31 @internalComponent
    31 @internalComponent
    32 @released
    32 @released
    33 */
    33 */
    34 CParameterFileProcessor::CParameterFileProcessor(String aParamFileName):
    34 CParameterFileProcessor::CParameterFileProcessor(const string& aParamFileName):
    35 												 iParamFileName(aParamFileName),iNoOfArguments(0),
    35 												 iParamFileName(aParamFileName),iNoOfArguments(0),
    36 												 iParamFileArgs(NULL)
    36 												 iParamFileArgs(NULL)
    37 {
    37 {
    38 }	
    38 }	
    39 
    39 
    47 @return True/False depending on the status of parameter-file open statement.
    47 @return True/False depending on the status of parameter-file open statement.
    48 */
    48 */
    49 bool CParameterFileProcessor::OpenFile()
    49 bool CParameterFileProcessor::OpenFile()
    50 {
    50 {
    51 	
    51 	
    52 	iParamFile.open(iParamFileName.data(),std::ios::binary);
    52 	iParamFile.open(iParamFileName.data(),ios_base::binary);
    53 	if (iParamFile.is_open())
    53 	if (iParamFile.is_open())
    54 		return true;
    54 		return true;
    55 	else
    55 	else
    56 	{		
    56 	{		
    57 		std::cout<<"Error: Couldn't open parameter-file for reading:"<<iParamFileName.c_str()<<"\n";
    57 		cout<<"Error: Couldn't open parameter-file for reading:"<<iParamFileName.c_str()<<"\n";
    58 		return false;
    58 		return false;
    59 	}
    59 	}
    60 }
    60 }
    61 
    61 
    62 
    62 
    73 	if(OpenFile())
    73 	if(OpenFile())
    74 	{
    74 	{
    75 		while(!iParamFile.eof())
    75 		while(!iParamFile.eof())
    76 		{
    76 		{
    77 			// Read the parameter-file line by line.
    77 			// Read the parameter-file line by line.
    78 			String line;
    78 			string line;
    79 			std::getline(iParamFile,line);
    79 			getline(iParamFile,line);
    80 
    80 
    81 			// Read the line till the occurence of character ';' or EOL.
    81 			// Read the line till the occurence of character ';' or EOL.
    82 			unsigned int pos = line.find_first_of(";\r\n");
    82 			unsigned int pos = line.find_first_of(";\r\n");
    83 			if (pos != std::string::npos)
    83 			if (pos != string::npos)
    84 				line = line.substr(0,pos);
    84 				line = line.substr(0,pos);
    85 			
    85 			
    86 			// Split the line if multiple parameters are provided
    86 			// Split the line if multiple parameters are provided
    87 			// in a single line.
    87 			// in a single line.
    88 			if(!SplitLine(line))
    88 			if(!SplitLine(line))
   114 @internalComponent
   114 @internalComponent
   115 @released
   115 @released
   116 
   116 
   117 @return True/False depending on the status of spliting.
   117 @return True/False depending on the status of spliting.
   118 */
   118 */
   119 bool CParameterFileProcessor::SplitLine(String& aLine)
   119 bool CParameterFileProcessor::SplitLine(string& aLine)
   120 {
   120 {
   121 	unsigned int startPos=0;
   121 	unsigned int startPos=0;
   122 	unsigned int endPos=0; 	
   122 	unsigned int endPos=0; 	
   123 
   123 
   124 	// Segregate parameters based on white-space or tabs.
   124 	// Segregate parameters based on white-space or tabs.
   125 	startPos= aLine.find_first_not_of(" \t",endPos);
   125 	startPos= aLine.find_first_not_of(" \t",endPos);
   126 	while(startPos != std::string::npos)
   126 	while(startPos != string::npos)
   127 	{		
   127 	{		
   128 		endPos= aLine.find_first_of(" \t",startPos);
   128 		endPos= aLine.find_first_of(" \t",startPos);
   129 		String paramStr= aLine.substr(startPos,endPos-startPos);
   129 		string paramStr= aLine.substr(startPos,endPos-startPos);
   130 
   130 
   131 		unsigned int position= aLine.find_first_of("\"",startPos);
   131 		unsigned int position= aLine.find_first_of("\"",startPos);
   132 
   132 
   133 		// If the parameter contains double quotes('"') then also include the spaces(if provided)
   133 		// If the parameter contains double quotes('"') then also include the spaces(if provided)
   134 		// within the quotes.		
   134 		// within the quotes.		
   135 		if((position!=std::string::npos) && position<=endPos)
   135 		if((position!=string::npos) && position<=endPos)
   136 		{
   136 		{
   137 			endPos= aLine.find_first_of("\"",position+1);
   137 			endPos= aLine.find_first_of("\"",position+1);
   138 			if(endPos!= std::string::npos)
   138 			if(endPos!= string::npos)
   139 			{				
   139 			{				
   140 				endPos= aLine.find_first_of(" \t",endPos+1);
   140 				endPos= aLine.find_first_of(" \t",endPos+1);
   141 				if(endPos != std::string::npos)
   141 				if(endPos != string::npos)
   142 				{
   142 				{
   143 					paramStr= aLine.substr(startPos,endPos-startPos);
   143 					paramStr= aLine.substr(startPos,endPos-startPos);
   144 				}
   144 				}
   145 				
   145 				
   146 				// Remove '"' from parameter
   146 				// Remove '"' from parameter
   153 				}
   153 				}
   154 			}
   154 			}
   155 			// Generate error message if enclosing quotes are not found.
   155 			// Generate error message if enclosing quotes are not found.
   156 			else
   156 			else
   157 			{
   157 			{
   158 				std::cout<<"Error while parsing parameter-file"<<iParamFileName.c_str()<<". Closing \"\"\" not found\n";
   158 				cout<<"Error while parsing parameter-file"<<iParamFileName.c_str()<<". Closing \"\"\" not found\n";
   159 				return false;				
   159 				return false;				
   160 			}
   160 			}
   161 		}
   161 		}
   162 
   162 
   163 		iParameters.push_back(paramStr);
   163 		iParameters.push_back(paramStr);
   177 bool CParameterFileProcessor::SetNoOfArguments()
   177 bool CParameterFileProcessor::SetNoOfArguments()
   178 {
   178 {
   179 	unsigned int noOfArguements = iParameters.size();	
   179 	unsigned int noOfArguements = iParameters.size();	
   180 	if (!noOfArguements)
   180 	if (!noOfArguements)
   181 	{
   181 	{
   182 		std::cout<<"Warning: No parameters specified in paramer-file:"<<iParamFileName.data()<<"\n";
   182 		cout<<"Warning: No parameters specified in paramer-file:"<<iParamFileName.data()<<"\n";
   183 		return false;
   183 		return false;
   184 	}
   184 	}
   185 	iNoOfArguments = noOfArguements+1;
   185 	iNoOfArguments = noOfArguements+1;
   186 	return true;
   186 	return true;
   187 }
   187 }
   200 	unsigned int paramSize = iParameters.size();
   200 	unsigned int paramSize = iParameters.size();
   201 	iParamFileArgs=new char*[paramSize+1];			  
   201 	iParamFileArgs=new char*[paramSize+1];			  
   202 	
   202 	
   203 	for (unsigned int count=1; count<=paramSize; count++)
   203 	for (unsigned int count=1; count<=paramSize; count++)
   204 	{
   204 	{
   205 		String param = iParameters.at(count-1);
   205 		string param = iParameters.at(count-1);
   206 		*(iParamFileArgs+count) = new char[param.size()+1];
   206 		*(iParamFileArgs+count) = new char[param.size()+1];
   207 		strcpy(*(iParamFileArgs+count),param.c_str());
   207 		strcpy(*(iParamFileArgs+count),param.c_str());
   208 	}
   208 	}
   209 }
   209 }
   210 
   210