예제 #1
0
void Network_Service::Read_Line (void)
{
	Line_File *file = (Line_File *) Network_Db_File (TRANSIT_ROUTE);

	//---- store the transit route data ----

	Show_Message ("Reading %s -- Record", file->File_Type ());
	Set_Progress ();

	if (Check_Data () || Renumber ()) {
		if (!Network_Data_Flag (TRANSIT_STOP) && 
			(Network_File_Flag (TRANSIT_STOP) || Network_Option_Flag (TRANSIT_STOP))) {
			Error (file_error, "Transit Stop", file->File_ID ());
		}
	}
	First_Record (true);
	int i, num;

	while (file->Read (false)) {
		Show_Progress ();

		if (Line_Processing (file)) {
			if (!line_data.Add ()) goto add_error;

		}
		First_Record (false);

		num = file->Stops ();

		for (i=1; i <= num; i++) {
			if (!file->Read (true)) {
				Error ("Number of Nested Records for Route %d", file->Route ());
			}
			Show_Progress ();

			if (Line_Processing (file)) {
				if (!line_data.Add ()) goto add_error;
			}			
		}	
	}
	End_Progress ();
	file->Close ();

	line_data.Route_Records (Progress_Count ());

	Print (2, "Number of %s Records = %d", file->File_Type (), Progress_Count ());

	num = line_data.Num_Records ();

	if (num && num != Progress_Count ()) {
		Print (1, "Number of Transit Route Data Records = %d", num);
	}
	line_data.Optimize ();

	if (num > 0) Network_Data_True (TRANSIT_ROUTE);
	return;

add_error:
	Error ("Adding Record to the Transit Route Data List");
}
예제 #2
0
void Data_Service::Read_Lines (Line_File &file)
{
	int i, num;
	bool keep_flag;
	Int_Map_Stat map_stat;
	Line_Data line_rec;

	//---- store the route data ----

	Show_Message (String ("Reading %s -- Record") % file.File_Type ());
	Set_Progress ();
	
	Initialize_Lines (file);

	while (file.Read (false)) {
		Show_Progress ();

		line_rec.Clear ();

		keep_flag = Get_Line_Data (file, line_rec);

		num = file.Num_Nest ();
		if (num > 0) line_rec.reserve (num);

		for (i=1; i <= num; i++) {
			if (!file.Read (true)) {
				Error (String ("Number of Stop Records for Route %d") % file.Route ());
			}
			Show_Progress ();

			Get_Line_Data (file, line_rec);
		}
		if (keep_flag) {
			map_stat = line_map.insert (Int_Map_Data (line_rec.Route (), (int) line_array.size ()));

			if (!map_stat.second) {
				Warning ("Duplicate Route Number = ") << line_rec.Route ();
			} else {
				line_array.push_back (line_rec);

				line_array.Add_Route_Stops ((int) line_rec.size ());
			}
		}
	}
	End_Progress ();
	file.Close ();

	Print (2, String ("Number of %s Records = %d") % file.File_Type () % Progress_Count ());

	num = (int) line_array.size ();

	if (num && num != Progress_Count ()) {
		Print (1, String ("Number of %s Data Records = %d") % file.File_ID () % num);
	}
	if (num > 0) System_Data_True (TRANSIT_ROUTE);
}
예제 #3
0
void Data_Service::Initialize_Lines (Line_File &file)
{
	Required_File_Check (file, TRANSIT_STOP);
	if (file.Version () > 40) {
		Required_File_Check (file, VEHICLE_TYPE);
	}
	int percent = System_Data_Reserve (TRANSIT_ROUTE);

	if (line_array.capacity () == 0 && percent > 0) {
		int num = file.Num_Records () / 25;

		if (percent != 100) {
			num = (int) ((double) num * percent / 100.0);
		}
		if (num > 1) {
			line_array.reserve (num);
			if (num > (int) line_array.capacity ()) Mem_Error (file.File_ID ());
		}
	}
}
예제 #4
0
bool Data_Service::Get_Line_Data (Line_File &file, Line_Data &line_rec)
{
	int route;

	//---- process a header line ----

	if (!file.Nested ()) {
		Int_Map_Itr map_itr;

		route = file.Route ();
		if (route == 0) return (false);
		line_rec.Route (route);

		if (file.Stops () < 2) return (false);

		line_rec.Mode (file.Mode ());
		line_rec.Type (file.Type ());
		line_rec.Name (file.Name ());
		line_rec.Notes (file.Notes ());

		if (file.Version () > 40 && veh_type_array.size () > 0) {
			map_itr = veh_type_map.find (line_rec.Type ());
			if (map_itr == veh_type_map.end ()) {
				Warning (String ("Transit Route %d Vehicle Type %d was Not Found") % route % line_rec.Type ());
			} else {
				line_rec.Type (map_itr->second);
			}
		}
		return (true);
	}

	//---- process a stop record ----

	int zone, stop;
	Line_Stop line_stop;
	Int_Map_Itr itr;

	route = line_rec.Route ();
	stop = file.Stop ();

	itr = stop_map.find (stop);
	if (itr == stop_map.end ()) {
		Warning (String ("Transit Stop %d on Route %d was Not Found") % stop % route);
		return (false);
	}
	line_stop.Stop (itr->second);

	zone = file.Zone ();

	if (Num_Fare_Zones () > 0 && (zone < 0 || zone > Num_Fare_Zones ())) {
		Warning (String ("Transit Zone %d on Route %d is Out of Range (1..%d)") % zone % route % Num_Fare_Zones ());
	}
	line_stop.Zone (zone);
	line_stop.Time_Flag ((file.Time_Flag () > 0));
	
	line_rec.push_back (line_stop);
	return (true);
}
예제 #5
0
bool Network_Service::Line_Processing (Db_File *fh)
{
	static int id, nstops, stop_num; 
	int zone;

	bool stop_flag;
	
	Line_Data *line_ptr = NULL;

	Line_File *file = (Line_File *) fh;

	stop_flag = Network_Data_Flag (TRANSIT_STOP);

	//---- process a header line ----

	if (!file->Nest ()) {	
		id = file->Route ();

		if (id == 0) return (false);

		if (id < 1) {
			return (Check_Message ("Transit Route ID %d is Out of Range", id));
		}
		line_ptr = line_data.New_Record (true);
		if (line_ptr == NULL) goto mem_error;

		line_ptr->Route (id);

		stop_num = 1;
		nstops = file->Stops ();

		if (nstops < 2) {
			return (Check_Message ("Number of Stops %d on Route %d is Out of Range", nstops, id));
		}
		if (!line_ptr->Stops (nstops)) {
			Error ("Insufficient Memory for %d Stops on Router %d", nstops, id);
		}
		line_ptr->Mode (Transit_Code (file->Mode ()));
		line_ptr->Null_Name ();
		line_ptr->Null_Notes ();

		if (Notes_Name_Flag ()) {
			char *str_ptr = file->Name ();

			if (str_ptr != NULL && *str_ptr != '\0') {
				line_ptr->Name (str_ptr);
			}
			str_ptr = file->Notes ();

			if (str_ptr != NULL && *str_ptr != '\0') {
				line_ptr->Notes (str_ptr);
			}
		}
	} else {
		line_ptr = line_data.New_Record (false);
		if (line_ptr == NULL) goto mem_error;

		//---- process a stop record ----

		int stop = file->Stop ();

		if (stop_flag) {
			int index = stop_data.Get_Index (stop);

			if (index == 0) {
				return (Check_Message ("Transit Stop %d on Route %d was Not Found in the Stop File", stop, id));
			}
			if (Renumber ()) stop = index;
		}
		line_ptr->Stop (stop_num, stop);

		zone = file->Zone ();

		if (Num_Fare_Zones () > 0 && (zone < 1 || zone > Num_Fare_Zones ())) {
			if (zone != 0 || !Zero_Fare_Zone ()) {
				Warning ("Transit Zone %d on Route %d is Out of Range (1..%d)", zone, id, Num_Fare_Zones ());
				if (zone == 0) Zero_Fare_Zone (true);
			}
		}
		line_ptr->Zone (stop_num, zone);
		line_ptr->Time_Flag (stop_num, file->Time_Flag ());

		if (stop_num == nstops) {
			return (true);
		} else {
			stop_num++;
			return (false);
		}
	}
	return (false);

mem_error:
	Error ("Insuffienct Memory for Transit Line Data");
	return (false);
}