...

/

The Core Parts

The Core Parts

Let's examine the core parts of our CSV Reader application.

We'll cover the following...

The Main

Let’s start with the main() function.

int main(int argc, const char** argv) {
if (argc <= 1)
return 1;
try {
const auto paths = CollectPaths(argv[1]);
if (paths.empty()) {
std::cout << "No files to process...\n";
return 0;
}
const auto startDate = argc > 2 ? Date(argv[2]) : Date();
const auto endDate = argc > 3 ? Date(argv[3]) : Date();
const auto results = CalcResults(paths, startDate, endDate);
ShowResults(startDate, endDate, results);
}
catch (const std::filesystem::filesystem_error& err) {
std::cerr << "filesystem error! " << err.what() << '\n';
}
catch (const std::runtime_error& err) {
std::cerr << "runtime error! " << err.what() << '\n';
}
return 0;
}

Once we’re sure that there are enough arguments in the command line we enter the main scope where all the processing happens:

  • line 6 - gather all the files to process in function CollectPaths
  • line 16 - convert data from the files into record data and calculate the results - in CalcResults
  • line 18
...