コード例 #1
0
bool SubareaNet::Location_Processing (Db_File *fh)
{
    static Location_File *new_file;

    int id;
    Location_Data *location_ptr;
    Link_Data *link_ptr;

    Location_File *file = (Location_File *) fh;

    if (First_Record ()) {
        new_file = (Location_File *) Network_Db_Base (NEW_ACTIVITY_LOCATION);

        if (!location_data.Max_Records (file->Num_Records ())) goto mem_error;
    }

    id = file->Location ();
    if (id == 0) return (false);

    location_ptr = location_data.New_Record ();
    if (location_ptr == NULL) goto mem_error;

    location_ptr->ID (id);

    if (id > max_location) max_location = id;

    id = file->Zone ();

    if (id > max_zone) max_zone = id;

    link_ptr = link_data.Get (file->Link ());

    if (link_ptr != NULL && link_ptr->Type () > 0) {

        //---- copy the fields to the subarea file ----

        new_file->Copy_Fields (file);

        if (!new_file->Write ()) {
            Error ("Writing %s", new_file->File_Type ());
        }
        nlocation++;
        return (true);
    }
    return (false);

mem_error:
    Error ("Insufficient Memory for Activity Location Data");
    return (false);
}
コード例 #2
0
ファイル: Read_Locations.cpp プロジェクト: kravitz/transims5
bool Data_Service::Get_Location_Data (Location_File &file, Location_Data &location_rec)
{
	int link, dir, offset;
	double setback;
	Link_Data *link_ptr;

	//---- read and save the data ----

	location_rec.Location (file.Location ());

	if (location_rec.Location () == 0) return (false);

	//---- check/convert the link number and direction  ----
	
	link = file.Link ();
	dir = file.Dir ();
	offset = Round (file.Offset ());

	link_ptr = Set_Link_Direction (file, link, dir, offset);

	location_rec.Link (link);
	location_rec.Dir (dir);
	location_rec.Offset (offset);

	setback = file.Setback ();
	location_rec.Setback (setback);

	if (Location_XY_Flag ()) {
		Points points;

		Link_Shape (link_ptr, dir, points, UnRound (offset), 0.0, setback);

		if (points.size () > 0) {
			location_rec.X (points [0].x);
			location_rec.Y (points [0].y);
		} else {
			Node_Data *node_ptr = &node_array [link_ptr->Anode ()];
		
			location_rec.X (node_ptr->X ());
			location_rec.Y (node_ptr->Y ());
		}
	}
	location_rec.Zone (file.Zone ());

	if (location_rec.Zone () > 0 && System_Data_Flag (ZONE)) {
		Int_Map_Itr map_itr = zone_map.find (location_rec.Zone ());
		if (map_itr == zone_map.end ()) {
			Warning (String ("Location %d Zone %d was Not Found") % location_rec.Location () % location_rec.Zone ());
			return (false);
		}
		location_rec.Zone (map_itr->second);
	} else if (location_rec.Zone () == 0) {
		location_rec.Zone (-1);

		//---- delete extra activity location used for transit stops ----

		if (file.Version () <= 40) return (false);
	}
	location_rec.Notes (file.Notes ());

	return (true);
}
コード例 #3
0
bool LinkSum::Get_Location_Data (Location_File &file, Location_Data &data)
{
	int i, field, link, lvalue1, lvalue2, zone;
	double dvalue1, dvalue2;
	String buffer;

	Db_Field *fld;
	Link_Location loc_rec;
	Int_Itr int_itr;
	Int_Map_Itr map_itr;

	//---- get the link number ----

	link = file.Link ();
	if (link == 0) return (false);
	data.Link (link);

	//---- sum the activities on links ----

	if (activity_flag) {
		if (!link_db.Read_Record (link)) {
			Error (String ("Reading Link Database Record %d") % link);
		}

		//---- sum the data fields ----

		for (i=1, int_itr = field_list.begin (); int_itr != field_list.end (); int_itr++, i++) {
			field = *int_itr;

			fld = file.Field (field);

			if (fld->Type () == DB_INTEGER) {
				lvalue1 = file.Get_Integer (field);
				lvalue2 = link_db.Get_Integer (i);

				lvalue2 += lvalue1;
				link_db.Put_Field (i, lvalue2);
			} else if (fld->Type () == DB_DOUBLE) {
				dvalue1 = file.Get_Double (field);
				dvalue2 = link_db.Get_Double (i);

				dvalue2 += dvalue1;
				link_db.Put_Field (i, dvalue2);
			} else if (fld->Type () == DB_STRING) {
				link_db.Put_Field (i, file.Get_String (field));
			}
		}

		//---- save the changes ----

		if (!link_db.Write_Record (link)) {
			Error (String ("Writing Link Database Record %d") % link);
		}
	}

	//---- add a link location record ----

	if (zone_flag || group_flag) {
		zone = file.Zone ();

		if (zone > 0) {
			map_itr = link_map.find (link);
			if (map_itr == link_map.end ()) return (false);
			link = map_itr->second;

			loc_rec.link = link;
			loc_rec.location = i = file.Location ();
			loc_rec.zone = zone;
			loc_rec.count = 0;

			link_location.insert (Link_Loc_Map_Data (Int2_Key (link, i), loc_rec));
		}
	}

	//---- don't save the location data ----

	return (false);
}