Пример #1
0
HLFileSystemObject*	HLDirectoryFactory::Create_Path(const char* inPath, bool inCreateParentDirectories, const void* inData, UInt32 inDataSize)
{
	//	can't make the directory if it already exists
	ThrowIf(HLFileSystem::ObjectExists(inPath), CAException(dupFNErr), "HLDirectoryFactory::Create: the directory already exists");
	
	//	normalize the path
	char theNormalizedPath[PATH_MAX];
	HLFileSystem::NormalizePath(inPath, theNormalizedPath, PATH_MAX);
	
	//	extract the directory name
	CACFString theDirectoryName(HLFileSystem::CopyNameFromPath(theNormalizedPath));
	
	//	extract the parent path
	char theParentPath[PATH_MAX];
	HLFileSystem::CopyParentPathFromPath(theNormalizedPath, theParentPath, PATH_MAX);
	
	//	make an FSRef for the parent path
	FSRef theParentFSRef;
	bool theParentExists = HLFileSystem::MakeFSRefFromPath(theParentPath, theParentFSRef);
	if(!theParentExists && inCreateParentDirectories)
	{
		//	the parent directory doesn't exist, but we're allowed to create it
		CAAutoDelete<HLFileSystemObject> theObject(Create_Path(theParentPath, inCreateParentDirectories, NULL, 0));
		theObject->GetFSRef(theParentFSRef);
	}
	else if(!theParentExists)
	{
		//	don't have an FSRef for the parent, so we have to bail
		DebugMessage("HLFileSystemObject::CreateDirectory: couldn't make an FSRef for the parent");
		throw CAException(fnfErr);
	}
	
	//	we have the parent FSRef and the CFString name, so create the directory
	return Create_FSRef(theParentFSRef, theDirectoryName.GetCFString(), inData, inDataSize);
}
Пример #2
0
int Find_Shortest_Path (int** graph_matrix , int* shortest_path , int num_of_junctions, int source , int target )
{
	BOOL* queue = NULL ;
	int *distance = NULL , *previous = NULL , curr_vertex = 0 , alt = 0 ;
	int i=0 , path_length = 0;

	queue = (BOOL*)malloc (num_of_junctions * sizeof(BOOL)  );
	if (queue == NULL)
	{
		printf("FATAL ERROR: Memory allocation failed\n");
		return (-1);
	}
	
	distance = (int*)malloc (num_of_junctions * sizeof(int) );
	if (distance == NULL)
	{
		printf("FATAL ERROR: Memory allocation failed\n");
		return (-1);
	}
	
	previous = (int*)malloc (num_of_junctions * sizeof(int) );
	if (previous == NULL)
	{
		printf("FATAL ERROR: Memory allocation failed\n");
		return (-1);
	}

	for ( i = 0 ; i < num_of_junctions ; i++ )
	{
		if (i == source)
			distance[i] = 0 ;
		else
			distance[i] = -1 ;
		previous[i] = -1 ;
		queue[i] = TRUE ;
	}

	while ( ( curr_vertex = Find_Min_Junction_In_Queue(distance , queue , num_of_junctions) )   !=   target  )
	{
		for ( i = 0  ;  i < num_of_junctions  ;  i++  )
		{
			if ( graph_matrix[curr_vertex][i] != -1   &&   queue[i] == TRUE  )
			{
				alt = distance[curr_vertex] + graph_matrix[curr_vertex][i];
				if (  alt < distance[i]   ||   distance[i] == -1   )
				{
					distance[i] = alt;
					previous[i] = curr_vertex;
				}
			}
		}
	}
	path_length = Create_Path (previous , shortest_path , source , target );
	free( queue );
	free( distance );
	free( previous );
	return (  path_length   );
}