Exemplo n.º 1
0
/* Test for the required minimum number of columns selected and
 * the selection is consistent.
 * @param An ErrorList object to which all found issues are added.
 */
void GncTxImport::verify_column_selections (ErrorList& error_msg)
{

    /* Verify if a date column is selected and it's parsable.
     */
    if (!check_for_column_type(GncTransPropType::DATE))
        error_msg.add_error( _("Please select a date column."));

    /* Verify if an account is selected either in the base account selector
     * or via a column in the import data.
     */
    if (!check_for_column_type(GncTransPropType::ACCOUNT))
    {
        if (m_settings.m_multi_split)
            error_msg.add_error( _("Please select an account column."));
        else if (!m_settings.m_base_account)
            error_msg.add_error( _("Please select an account column or set a base account in the Account field."));
    }

    /* Verify a description column is selected.
     */
    if (!check_for_column_type(GncTransPropType::DESCRIPTION))
        error_msg.add_error( _("Please select a description column."));

    /* Verify at least one amount column (deposit or withdrawal) column is selected.
     */
    if (!check_for_column_type(GncTransPropType::DEPOSIT) &&
        !check_for_column_type(GncTransPropType::WITHDRAWAL))
        error_msg.add_error( _("Please select a deposit or withdrawal column."));

    /* Verify a transfer account is selected if any of the other transfer properties
     * are selected.
     */
    if ((check_for_column_type(GncTransPropType::TACTION) ||
         check_for_column_type(GncTransPropType::TMEMO) ||
         check_for_column_type(GncTransPropType::TREC_STATE) ||
         check_for_column_type(GncTransPropType::TREC_DATE)) &&
        !check_for_column_type(GncTransPropType::TACCOUNT))
        error_msg.add_error( _("Please select a transfer account column or remove the other transfer related columns."));
}
Exemplo n.º 2
0
Route::Route(std::string &line, HighwaySystem *sys, ErrorList &el, std::unordered_map<std::string, Region*> &region_hash)
{	/* initialize object from a .csv file line,
	but do not yet read in waypoint file */
	con_route = 0;
	mileage = 0;
	rootOrder = -1;  // order within connected route
	if (line.back() == 0x0D) line.erase(line.end()-1);	// trim DOS newlines

	// system
	size_t left = line.find(';');
	if (left == std::string::npos)
	{	el.add_error("Could not parse " + system->systemname + ".csv line: [" + line + "], expected 8 fields, found 1");
		return;
	}
	system = sys;
	if (system->systemname != line.substr(0,left))
	    {	el.add_error("System mismatch parsing " + system->systemname + ".csv line [" + line + "], expected " + system->systemname);
		return;
	    }

	// region
	size_t right = line.find(';', left+1);
	if (right == std::string::npos)
	{	el.add_error("Could not parse " + system->systemname + ".csv line: [" + line + "], expected 8 fields, found 2");
		return;
	}
	try { region = region_hash.at(line.substr(left+1, right-left-1));
	    }
	catch (const std::out_of_range& oor)
	    {	el.add_error("Unrecognized region in " + system->systemname + ".csv line: [" + line + "], " + line.substr(left+1, right-left-1));
		region = 0;
		return;
	    }

	// route
	left = right;
	right = line.find(';', left+1);
	if (right == std::string::npos)
	{	el.add_error("Could not parse " + system->systemname + ".csv line: [" + line + "], expected 8 fields, found 3");
		return;
	}
	route = line.substr(left+1, right-left-1);

	// banner
	left = right;
	right = line.find(';', left+1);
	if (right == std::string::npos)
	{	el.add_error("Could not parse " + system->systemname + ".csv line: [" + line + "], expected 8 fields, found 4");
		return;
	}
	banner = line.substr(left+1, right-left-1);
	if (banner.size() > 6)
	    {	el.add_error("Banner >6 characters in " + system->systemname + ".csv line: [" + line + "], " + banner);
		return;
	    }

	// abbrev
	left = right;
	right = line.find(';', left+1);
	if (right == std::string::npos)
	{	el.add_error("Could not parse " + system->systemname + ".csv line: [" + line + "], expected 8 fields, found 5");
		return;
	}
	abbrev = line.substr(left+1, right-left-1);
	if (abbrev.size() > 3)
	    {	el.add_error("Abbrev >3 characters in " + system->systemname + ".csv line: [" + line + "], " + abbrev);
		return;
	    }

	// city
	left = right;
	right = line.find(';', left+1);
	if (right == std::string::npos)
	{	el.add_error("Could not parse " + system->systemname + ".csv line: [" + line + "], expected 8 fields, found 6");
		return;
	}
	city = line.substr(left+1, right-left-1);

	// root
	left = right;
	right = line.find(';', left+1);
	if (right == std::string::npos)
	{	el.add_error("Could not parse " + system->systemname + ".csv line: [" + line + "], expected 8 fields, found 7");
		return;
	}
	root = line.substr(left+1, right-left-1);

	// alt_route_names
	left = right;
	right = line.find(';', left+1);
	if (right != std::string::npos)
	{	el.add_error("Could not parse " + system->systemname + ".csv line: [" + line + "], expected 8 fields, found more");
		return;
	}
	char *arnstr = new char[line.size()-left];
	strcpy(arnstr, line.substr(left+1).data());
	for (char *token = strtok(arnstr, ","); token; token = strtok(0, ","))
		alt_route_names.push_back(token);
	delete[] arnstr;
	//yDEBUG*/ std::cout << "returning from Route ctor" << endl;
}