void data_base::RestoreFileContents()
 {
   /*This method should be called immediately after opening a file in write mode
    *so the contents are kept in the file for other processes that may be using it.
    */
   CleanFileContentsOfArtifacts();
   TrimEndOfFile();
   FlushData();
 }
 void data_base::WriteValue(const std::string& value, const std::string& search)
 {
     /*Writes value into an specific 'tag' in file. i.e. value = 3; [search = value, value = 5] -> value = 5;*/
     if(buffer != "" && search != "")
     {
         int start = findString(search.c_str(), buffer.c_str()) + search.length() + 3;//3 is the number of spaces in the line that form the string " = ". Check the syntax of files
         int end = searchCharIndex(';', buffer, start);
         int size = end - start;
         buffer.replace(start, size, value);
         FlushData();
     }
     else if(buffer == "" && search != "")
     {
         std::cout<<"Error: File is empty!\n\r";
     }
     else
     {
         buffer = value;
         FlushData();
     }
 }
void FillZero( int nLength )
{
	int				nCount = 0;

	while( nCount < nLength )
	{
		if( nChars == 0 )
			memset( pHexText, 0, sizeof(pHexText) );

		sprintf( &pHexText[strlen(pHexText)], "0x00," );
		pComment[nChars] = 0x00;
		nChars++;
		nCount++;

		if( nChars == MAX_CHARS_PER_LINE )
			FlushData();
	}

	if( nChars )
		FlushData();
}
 data_base::~data_base()
 {
     /*Makes sure the file handle is properly closed from the constructor event. It helps prevent file handle leaks.*/
     if(file.is_open())
     {
         file.close();
     }
     if(output.is_open())
     {
         FlushData();
         output.close();
     }
 }
 void data_base::WriteValueWithLineIndex(const std::string& value, const std::string& search, int instanceIndex)
 {
     /*This methods find the instance of a keyword and modifies its value. i.e. value = 3;\nvalue = 4 [mod line 2 with 3] -> value = 3;\nvalue = 3.*/
     int start = GetLineIndex(search, instanceIndex) + 3;
     int end = searchCharIndex(';', buffer, start);
     int size = end - start;
     if(end == ENDOFFILE)
     {
         end = searchCharIndex('\n', buffer, start);
     }
     if(buffer != "")
     {
         buffer.replace(start, size, value);
         FlushData();
     }
 }
void ProduceData( unsigned char *pData, int nDataLen )
{
	int				nCount = 0;

	while( nCount < nDataLen )
	{
		if( nChars == 0 )
			memset( pHexText, 0, sizeof(pHexText) );

		sprintf( &pHexText[strlen(pHexText)], "0x%02X,", pData[nCount] );
		pComment[nChars] = pData[nCount];
		nChars++;
		nCount++;

		if( nChars == MAX_CHARS_PER_LINE )
			FlushData();
	}
}
Exemple #7
0
bool CXmlConfig::Save()
{
	return FlushData();
}