C++ Implementation

The C++ implementation is composed of the source files listed below.

  • CSVToXML.cpp: the main routine for the C++ application with CSV as the source

  • CSVSourceConverter.cpp: the class that drives conversion from CSV to XML

  • CSVSourceConverter.h: the header file for the CSVSourceConverter class

  • CSVRecordReader.cpp: the class that handles reading CSV records and converting to XML

  • CSVRecordReader.h: the header file for the CSVRecordReader class

  • XMLToCSV.cpp: the main routine for the C++ application with CSV as the target

  • CSVTargetConverter.cpp: the class that drives conversion from XML to CSV

  • CSVTargetConverter.h: the header file for the CSVTargetConverter class

  • CSVRecordWriter.cpp: the class that handles reading XML and building and writing CSV records

  • CSVRecordWriter.h: the header file for the CSVRecordWriter class

  • DataCellAN.cpp: the class that handles alphanumeric fields in legacy formats

  • DataCellAN.h: the header file for the DataCellAN class

  • DataCellReal.cpp: the class that handles real (or decimal) number fields in legacy formats

  • DataCellReal.h: the header file for the DataCellReal class

  • DataCellDateMMsDDsYYYY.cpp: the class that handles date fields in MM/DD/YYYY representation in legacy formats

  • DataCellDateMMsDDsYYYY.h: the header file for the DataCellDateMMsDDsYYYY class

Directory operations are the only new C++ and WIN32 coding concepts introduced in these programs. To create an output directory in the CSVSourceConverter's processFile method, we use the _mkdir function.

iReturn = _mkdir(cOutputDirectory);

To read an input directory in the XMLToCSV main program, we use the FindFirstFile library routine, followed by successive calls to FindNextFile. FindFirstFile returns a File HANDLE and a WIN32_FIND_DATA structure from which we can retrieve the file name. FindNextFile returns us the next HANDLE and its WIN32_FIND_DATA structure. Here are the relevant lines from the code.

HANDLE hFind;
WIN32_FIND_DATA FindFileData;
...
//  For FindFirstFile, append wildcards
if ( strcmp( &(cInputDirectoryFindPath[i-3]),"*.*") != 0)
{
  strcat(cInputDirectoryFindPath,"*.*");
}

//  Open input directory
//  Get first file from input directory
hFind = FindFirstFile(cInputDirectoryFindPath,
    &FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
{
  throw cInputDirectoryOpenError;
}

//  DO for all files in input directory
do
{
  //  Skip directory file paths
  if (FindFileData.cFileName[0] == '.')
  {
    continue;
  }

  //  Build input file name
  memset(cInputFileName,0,MAX_PATH_LENGTH);
  strcpy(cInputFileName,cInputDirectoryName);
  strcat(cInputFileName,FindFileData.cFileName);
  ... Load, parse, and process the document
} while (FindNextFile(hFind, &FindFileData) == TRUE);
//  ENDDO

//  Close the input directory
FindClose(hFind);

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset