Ejemplo n.º 1
0
void Data_Service::Initialize_Connects (Connect_File &file)
{
	Required_File_Check (file, LINK);
	if (file.Version () <= 40) {
		Required_File_Check (file, POCKET);
	}
	int percent = System_Data_Reserve (CONNECTION);

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

		if (percent != 100) {
			num = (int) ((double) num * percent / 100.0);
		} else if (file.Version () <= 40) {
			num = (int) (num / 2.25);
		}
		if (num > 1) {
			connect_array.reserve (num);
			if (num > (int) connect_array.capacity ()) Mem_Error (file.File_ID ());
		}
	}
}
Ejemplo n.º 2
0
void Data_Service::Read_Connections (void)
{
	Connect_File *file = (Connect_File *) System_File_Handle (CONNECTION);

	int num, in, out;
	Int2_Map_Stat map_stat;
	Connect_Data connect_rec;

	//---- store the lane connectivity data ----

	Show_Message (String ("Reading %s -- Record") % file->File_Type ());
	Set_Progress ();
	
	Initialize_Connects (*file);
	
	num = 0;

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

		connect_rec.Clear ();

		if (Get_Connect_Data (*file, connect_rec)) {
			in = connect_rec.Dir_Index ();
			out = connect_rec.To_Index ();

			map_stat = connect_map.insert (Int2_Map_Data (Int2_Key (in, out), (int) connect_array.size ()));

			if (!map_stat.second) {
				Dir_Data *dir_ptr;
				Link_Data *link_ptr;

				dir_ptr = &dir_array [in];
			
				link_ptr = &link_array [dir_ptr->Link ()];
				in = link_ptr->Link ();

				dir_ptr = &dir_array [out];

				link_ptr = &link_array [dir_ptr->Link ()];
				out = link_ptr->Link ();

				Warning (String ("Duplicate Link Connection = %d to %d") % in % out);
				continue;
			} else {
				connect_array.push_back (connect_rec);
			}
		}
	}
	End_Progress ();
	file->Close ();

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

	num = (int) connect_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 (CONNECTION);

		Connect_Data *connect_ptr;
		Dir_Data *dir_ptr;

		//---- create directional link list ---- 

		while (num--) {
			connect_ptr = &connect_array [num];

			dir_ptr = &dir_array [connect_ptr->Dir_Index ()];
			connect_ptr->Next_To (dir_ptr->First_Connect_To ());
			dir_ptr->First_Connect_To (num);

			dir_ptr = &dir_array [connect_ptr->To_Index ()];
			connect_ptr->Next_From (dir_ptr->First_Connect_From ());
			dir_ptr->First_Connect_From (num);
		}
	}
}