bethyw.cpp
/*
 *

  Parse the datasets argument passed into the command line. 

  The datasets argument is optional, and if it is not included, all datasets 
  should be imported. If it is included, it should be a comma-separated list of 
  datasets to import. If the argument contains the value "all"


  This function validates the passed in dataset names against the codes in
  DATASETS array in the InputFiles namespace in datasets.h. If an invalid code
  is entered, throw a std::invalid_argument with the message:
  No dataset matches key: <input code>
  where <input name> is the name supplied by the user through the argument.

  @param args
    Parsed program arguments

  @return
    A std::vector of BethYw::InputFileSource instances to import

  @throws
    std::invalid_argument if the argument contains an invalid dataset with
    message: No dataset matches key <input code>

  @example
    auto cxxopts = BethYw::cxxoptsSetup();
    auto args = cxxopts.parse(argc, argv);

    auto datasetsToImport = BethYw::parseDatasetsArg(args);
 */
Parse the datasets argument passed into the command line.
The datasets argument is optional, and if it is not included, all datasets
should be imported. If it is included, it should be a comma-separated list of
datasets to import. If the argument contains the value "all"

This function validates the passed in dataset names against the codes in
DATASETS array in the InputFiles namespace in datasets.h. If an invalid code
is entered, throw a std::invalid_argument with the message:
No dataset matches key: 
where  is the name supplied by the user through the argument.
Parse the datasets argument passed into the command line . The datasets argument is optional and if it is not included all datasets should be imported . If it is included it should be a comma - separated list of datasets to import . If the argument contains the value " all " This function validates the passed in dataset names against the codes in DATASETS array in the InputFiles namespace in datasets . h . If an invalid code is entered throw a std :: invalid_argument with the message : No dataset matches key : where is the name supplied by the user through the argument .
std::vector<BethYw::InputFileSource> BethYw::parseDatasetsArg(
    cxxopts::ParseResult& args) {
  size_t numDatasets = InputFiles::NUM_DATASETS;
  auto &allDatasets = InputFiles::DATASETS;
  std::vector<InputFileSource> datasetsToImport;
  if(args.count("datasets") == 0){
      for(unsigned int i = 0; i < numDatasets; i++){
          datasetsToImport.push_back(allDatasets[i]);
      }
      return datasetsToImport;
  }
  auto inputDatasets = args["datasets"].as<std::vector<std::string>>();
  for(auto input = inputDatasets.begin(); input != inputDatasets.end(); input++) {
      std::string &inputString = *input;
      if(BethYw::insensitiveEquals(inputString, "all")) {
          datasetsToImport.clear();
          for(unsigned int i = 0; i < numDatasets; i++){
              datasetsToImport.push_back(allDatasets[i]);
          }
          return datasetsToImport;
      }
      bool found = false;
      for (unsigned int x = 0; x < numDatasets; x++) {
          if (inputString == allDatasets[x].CODE) {
              datasetsToImport.push_back(allDatasets[x]);
              found = true;
          }
      }
      if(!found) {
          std::cerr << "No dataset matches key: " << inputString;
          exit(0);
      }
    }
    return datasetsToImport;
}
std :: vector < BethYw :: InputFileSource > BethYw :: parseDatasetsArg ( cxxopts :: ParseResult & args ) { size_t numDatasets = InputFiles :: NUM_DATASETS ; auto & allDatasets = InputFiles :: DATASETS ; std :: vector < InputFileSource > datasetsToImport ; if ( args . count ( " " ) == 0 ) { for ( unsigned int i = 0 ; i < numDatasets ; i ++ ) { datasetsToImport . push_back ( allDatasets [ i ] ) ; } return datasetsToImport ; } auto inputDatasets = args [ " " ] . as < std :: vector < std :: string > > ( ) ; for ( auto input = inputDatasets . begin ( ) ; input != inputDatasets . end ( ) ; input ++ ) { std :: string & inputString = * input ; if ( BethYw :: insensitiveEquals ( inputString , " " ) ) { datasetsToImport . clear ( ) ; for ( unsigned int i = 0 ; i < numDatasets ; i ++ ) { datasetsToImport . push_back ( allDatasets [ i ] ) ; } return datasetsToImport ; } bool found = false ; for ( unsigned int x = 0 ; x < numDatasets ; x ++ ) { if ( inputString == allDatasets [ x ] . CODE ) { datasetsToImport . push_back ( allDatasets [ x ] ) ; found = true ; } } if ( ! found ) { std :: cerr << " " << inputString ; exit ( 0 ) ; } } return datasetsToImport ; }
Parse the datasets argument passed into the command line.
Parse the datasets argument passed into the command line .
// This function is incomplete, but to get you started... // You may want to delete much of these // comments too! // Retrieve all valid datasets, see datasets.h // Create the container for the return type // You can get the std::vector of arguments from cxxopts like this. // Note that this function will throw an exception if datasets is not set as  // an argument. Check the documentation! Read it and understand it.