Esempio n. 1
0
void write_scenario_file(File_IO::File_Info& scenario, File_IO::File_Info& db, File_IO::File_Info& historical_db)
{
	// strip out the extension and db schema info (just retain the base db name - until this is changed in the DB schema - which it should be.)
	string database_name("");
	if (db.Is_File_Type("sqlite"))
		database_name = db.db_name();
	else if (!db.Has_Extension())
		database_name = db.full_name();
	else
		THROW_EXCEPTION("ERROR, the input db should be specified as either a .sqlite file or an extensionless db name.");
	string historical_db_name("");
	if (historical_db.Is_File_Type("sqlite"))
		historical_db_name = historical_db.db_name();
	else if (!historical_db.Has_Extension())
		historical_db_name = historical_db.full_name();
	else
		THROW_EXCEPTION("ERROR, the historical db should be specified as either a .sqlite file or an extensionless db name.");

	//if (!historical_db.Is_File_Type("sqlite")) THROW_EXCEPTION("ERROR: historical database_filename must be a .sqlite file");
	if (!scenario.Is_File_Type("json")) THROW_EXCEPTION("ERROR: scenario filename must be a .json file");

	File_IO::File_Writer fw;
	fw.Open(scenario.full_name());
	fw.Write_Line("{");
	fw.Write_Line("\t\"output_dir_name\" : \"batch_router\",");
	fw.Write_Line("\t\"io_source_flag\" : \"ODB_IO_SOURCE\",");
	stringstream s("");
	s<<"\t\"database_name\" : \""<<database_name<<"\",";
	fw.Write_Line(s);
	s.clear(); s.str("");
	s<<"\t\"historical_results_database_name\" : \""<<historical_db_name<<"\",";
	fw.Write_Line(s);
	fw.Write_Line("\t\"time_dependent_routing\" : true\n}");
	fw.Close();
}
Esempio n. 2
0
void write_scenario_file(char* database_name, char* scenario_name)
{
	// strip extension from database name
	string db_name(database_name);
	int pos = db_name.find('.');
	int len = db_name.length();
	string db(db_name.c_str());
	string ext("");
	if (pos != std::string::npos)
	{
		db = db_name.substr(0,pos);
		ext = db_name.substr(pos+1,len-pos-1);

		if (strcmp(ext.c_str(),"sqlite") != 0) THROW_EXCEPTION("ERROR: database_filename must be a sqlite file");
	}

	File_IO::File_Writer fw;
	fw.Open(string(scenario_name));
	fw.Write_Line("{");
	fw.Write_Line("\t\"io_source_flag\" : \"ODB_IO_SOURCE\",");
	stringstream s("");
	s<<"\t\"database_name\" : \""<<db<<"\"\n}";
	fw.Write(s);
	fw.Close();

	cout <<"Reading information from '"<<db<<"' sqlite file."<<endl;
}