areas.cpp
/*
  This function specifically parses the compiled areas.csv file of local 
  authority codes, and their names in English and Welsh.

 The CSV File fomate:
 !!!!THEY MUST have the same three columns in the same order.!!!
  This is a simple dataset that is a comma-separated values file (CSV), where
  the first row gives the name of the columns, and then each row is a set of
  data.

  @param is
    The input stream from InputSource

  @param cols
    A map of the enum BethyYw::SourceColumnMapping (see datasets.h) to strings
    that give the column header in the CSV file

  @param areasFilter
    An umodifiable pointer to set of umodifiable strings for areas to import,
    or an empty set if all areas should be imported

  @return
    void

  @see
    See datasets.h for details of how the variable cols is organised

  @see
    See bethyw.cpp for details of how the variable areasFilter is created

  @example
    InputFile input("data/areas.csv");
    auto is = input.open();

    auto cols = InputFiles::AREAS.COLS;

    auto areasFilter = BethYw::parseAreasArg();

    Areas data = Areas();
    areas.populateFromAuthorityCodeCSV(is, cols, &areasFilter);

  @throws 
    std::runtime_error if a parsing error occurs (e.g. due to a malformed file)
    std::std::out_of_range if there are not enough columns in cols if there are not enough columns in cols
*/
This function specifically parses the compiled areas.csv file of local
authority codes, and their names in English and Welsh.

The CSV File fomate:
THEY MUST have the same three columns in the same order.
This is a simple dataset that is a comma-separated values file (CSV), where
the first row gives the name of the columns, and then each row is a set of
data.

@param is
The input stream from InputSource

@param cols
A map of the enum BethyYw::SourceColumnMapping  to strings
that give the column header in the CSV file

@param areasFilter
An umodifiable pointer to set of umodifiable strings for areas to import,
or an empty set if all areas should be imported

@return
void

@see
See datasets.h for details of how the variable cols is organised

@see
See bethyw.cpp for details of how the variable areasFilter is created







Areas data = Areas();
areas.populateFromAuthorityCodeCSV(is, cols, &areasFilter).


This function specifically parses the compiled areas . csv file of local authority codes and their names in English and Welsh . The CSV File fomate : THEY MUST have the same three columns in the same order . This is a simple dataset that is a comma - separated values file ( CSV ) where the first row gives the name of the columns and then each row is a set of data . @param is The input stream from InputSource @param cols A map of the enum BethyYw :: SourceColumnMapping to strings that give the column header in the CSV file @param areasFilter An umodifiable pointer to set of umodifiable strings for areas to import or an empty set if all areas should be imported @return void @see See datasets . h for details of how the variable cols is organised @see See bethyw . cpp for details of how the variable areasFilter is created Areas data = Areas () ; areas . populateFromAuthorityCodeCSV ( is cols &areasFilter ) .
void Areas::populateFromAuthorityCodeCSV(
    std::istream &is,
    const BethYw::SourceColumnMapping &cols,
    const StringFilterSet * const areasFilter) {
    if(cols.size() < 3)
        throw std::out_of_range("Not enough columns");
    if(!(is.good()))
        throw (std::runtime_error("Failed to open file"));
    std::string line;
    std::getline(is,line);
    while (std::getline(is, line)) {
        std::string code = getVariableCSV(line);
        if(isFilterEmpty(areasFilter) || areasFilter->find(code) != areasFilter->end()){
            Area temp(code);
            temp.setName("eng", getVariableCSV(line));
            temp.setName("cym", getVariableCSV(line));
            this->setArea(code, temp);
        }
    }
}
void Areas :: populateFromAuthorityCodeCSV ( std :: istream & is , const BethYw :: SourceColumnMapping & cols , const StringFilterSet * const areasFilter ) { if ( cols . size ( ) < 3 ) throw std :: out_of_range ( " " ) ; if ( ! ( is . good ( ) ) ) throw ( std :: runtime_error ( " " ) ) ; std :: string line ; std :: getline ( is , line ) ; while ( std :: getline ( is , line ) ) { std :: string code = getVariableCSV ( line ) ; if ( isFilterEmpty ( areasFilter ) || areasFilter -> find ( code ) != areasFilter -> end ( ) ) { Area temp ( code ) ; temp . setName ( " " , getVariableCSV ( line ) ) ; temp . setName ( " " , getVariableCSV ( line ) ) ; this -> setArea ( code , temp ) ; } } }
This function specifically parses the compiled areas.csv file of local
authority codes, and their names in English and Welsh.
This function specifically parses the compiled areas . csv file of local authority codes and their names in English and Welsh .
//reading first line which is just the name of cols //As coursework states that this should remain constant, throw away the line