Example #1
0
void widgetDestroyImpl(widget *self)
{
	eventTableEntry *currEntry;

	// Release the container
	vectorMapAndDestroy(self->children, (mapCallback) widgetDestroy);

	// Release the event handler table
	while ((currEntry = vectorHead(self->eventVtbl)))
	{
		widgetRemoveEventHandler(self, currEntry->id);
	}

	vectorDestroy(self->eventVtbl);

	// Destroy the cairo context
	cairo_destroy(self->cr);

	// Destroy the texture
	glDeleteTextures(1, &self->textureId);

	// If we use a mask, destroy it
	if (self->maskEnabled)
	{
		cairo_destroy(self->maskCr);
	}

	// If GL content support is enabled, disable it
	if (self->openGLEnabled)
	{
		widgetDisableGL(self);
	}

	// Free the ID
	free((char *) self->id);

	// Free the tool-tip (if any)
	free((char *) self->toolTip);

	// Free ourself
	free(self);
}
Example #2
0
void vectorResize(Vector *v, const int size)
{
	VECTOR_TYPE *ptr = NULL;

	if (size < 0)
		return;

	if (size == 0)
	{
		vectorDestroy(v);

		return;
	}

	ptr = (VECTOR_TYPE *)realloc(v->_data, sizeof(VECTOR_TYPE) * size);

	if (ptr != NULL)
	{
		v->_data = ptr;
		v->_size = size;
		v->_capacity = size;
	}
}
Example #3
0
int main(void)
{
	int i, maxBFS;
	char cmd[255], arg;
	TreeNode *root = NULL, *tmpNode = NULL;
	Vector v;

	do
	{
		printf("Введите команду (h - справка):\n");
		scanf("%s", cmd);

		if (cmd[0] == '+')
		{
			scanf(" %c", &arg);

			if (cmd[1] == 'r')
			{
				if (root == NULL)
				{
					if (arg >= 'A' && arg <= 'Z')
					{
						treeAddNode(&root, arg - 'A');

						printf("Корень %c создан\n", arg);
					}
					else
						printf("Ошибка. Введена недопустимая буква\n");
				}
				else
					printf("Корень уже существует\n");
			}
			else if (root == NULL)
				printf("Корень не создан\n");
			else
			{
				tmpNode = root;

				if (cmd[1] != '\0')
					tmpNode = getNodeByPath(&root, &cmd[1]);

				if (tmpNode == NULL)
					printf("Ошибка. Такого пути не существует\n");
				else if (arg >= 'A' && arg <= 'Z')
				{
					if (treeAddNode(&tmpNode, arg - 'A') != NULL)
						printf("Узел %c добавлен к узлу %c\n", arg, tmpNode->_data + 'A');
				}
				else
					printf("Ошибка. Введена недопустимая буква\n");
			}
		}
		else if (cmd[0] == '-')
		{
			scanf(" %c", &arg);

			if (arg >= 'A' && arg <= 'Z')
			{
				if (treeRemoveNode(&root, arg - 'A'))
					printf("Узел %c удален\n", arg);
				else
					printf("Узел %c не найден\n", arg);
			}
			else
				printf("Ошибка. Введена недопустимая буква\n");
		}
		else if (cmd[0] == 'p')
		{
			KLP(&root, 0);
		}
		else if (cmd[0] == 't')
		{
			if (root != NULL)
			{
				vectorCreate(&v, treeDFS(&root));

				for (i = 0; i < vectorSize(&v); i++)
					vectorSave(&v, i, 0);

				countNodesOnLevels(&root, &v, 0);

				maxBFS = 0;

				for (i = 0; i < vectorSize(&v); i++)
					if (vectorLoad(&v, i) > maxBFS)
						maxBFS = vectorLoad(&v, i);

				printf("Ширина дерева: %d\n", maxBFS);

				vectorDestroy(&v);
			}
			else
				printf("Дерево пусто\n");
		}
		else if (cmd[0] == 'h')
		{
			printf("================================\n");
			printf("Список команд:\n");
			printf("+r CHAR - создать корень CHAR (A, B, ..., Z)\n");
			printf("+ CHAR - добавить сына CHAR к корню\n");
			printf("+PATH CHAR - добавить CHAR узел по заданому пути (s - сын, b - брат)\n");
			printf("- CHAR - удалить первый найденный узел CHAR и его поддерево\n");
			printf("p - распечатать дерево\n");
			printf("t - выполнить задание над деревом\n");
			printf("q - завершить программу\n");
			printf("================================\n");
		}
		else if (cmd[0] != 'q')
		{
			printf("Неизвестная команда\n");
		}
	}
	while (cmd[0] != 'q');

	treeDestroy(&root);

	return 0;
}
Example #4
0
void vectorMapAndDestroy(vector *v, mapCallback cb)
{
	vectorMap(v, cb);
	vectorDestroy(v);
}
Example #5
0
void lmListDestroy(LargeMessageList msgList)
{
	vectorDestroy(msgList->messages, (void *)jausMessageDestroy);
	jausAddressDestroy(msgList->source);
	free(msgList);
}
Example #6
0
void lmHandlerDestroy(LargeMessageHandler lmh)
{
	vectorDestroy(lmh->messageLists, (void *)lmListDestroy);
	free(lmh);
}
Example #7
0
void wdShutdownState(void)
{
	RejectComponentControlMessage rejectComponentControl;
	ReleaseComponentControlMessage releaseControl = NULL;
	JausMessage txMessage;
		
	scManagerRemoveSupportedMessage(wdNmi, JAUS_REPORT_COMPONENT_STATUS);	

	if(wd->controller.active)
	{
		// Terminate control of current component
		rejectComponentControl = rejectComponentControlMessageCreate();
		rejectComponentControl->source->id = wd->address->id;
		rejectComponentControl->destination->id = wd->controller.address->id;

		txMessage = rejectComponentControlMessageToJausMessage(rejectComponentControl);
		nodeManagerSend(wdNmi, txMessage);
		jausMessageDestroy(txMessage);

		rejectComponentControlMessageDestroy(rejectComponentControl);
	}
	
	// USER: Insert Shutdown Code Here, NOTE: Terminate any active service connections
	
	// Release Control
	if(wdInControl)
	{
		cDebug(4, "wd: Releasing control of PD\n");
	
		releaseControl = releaseComponentControlMessageCreate();
		releaseControl->source->id = wd->address->id;
		releaseControl->destination->id = pd->address->id;
		
		txMessage = releaseComponentControlMessageToJausMessage(releaseControl);
		nodeManagerSend(wdNmi, txMessage);
		jausMessageDestroy(txMessage);
		
		releaseComponentControlMessageDestroy(releaseControl);
		
		wdInControl = JAUS_FALSE;
		wd->state = JAUS_INITIALIZE_STATE;
	}
	
	if(pdStatusSc->isActive)
	{	
		scManagerTerminateServiceConnection(wdNmi, pdStatusSc);
		serviceConnectionDestroy(pdStatusSc);
	}
	
	if(pdWrenchSc->isActive)
	{	
		scManagerTerminateServiceConnection(wdNmi, pdWrenchSc);		
		serviceConnectionDestroy(pdWrenchSc);
	}	

	if(gposSc->isActive)
	{	
		scManagerTerminateServiceConnection(wdNmi, gposSc);		
		serviceConnectionDestroy(gposSc);
	}	

	if(vssSc->isActive)
	{	
		scManagerTerminateServiceConnection(wdNmi, vssSc);		
		serviceConnectionDestroy(vssSc);
	}
	
	// Destory Global Messages
	if(wdSpeed)
	{
		setTravelSpeedMessageDestroy(wdSpeed);
	}

	if(wdReportGpos)
	{
		reportGlobalPoseMessageDestroy(wdReportGpos);
	}

	if(wdReportVss)
	{
		reportVelocityStateMessageDestroy(wdReportVss);
	}

	if(wdReportWrench)
	{
		reportWrenchEffortMessageDestroy(wdReportWrench);
	}

	// Destroy Global Variables
	vehicleStateDestroy(vehicleState);	
	vectorDestroy(wdWaypoints, (void *)setGlobalWaypointMessageDestroy);
	setWrenchEffortMessageDestroy(wdWrench);
	jausComponentDestroy(pd);
}
Example #8
0
File: kp7.c Project: BlagoProg/MAI
int main(void)
{
	const int N = 100;
	int m, n, i, j, isRowBegin, lastInd, cnt, maxCols[N];
	Vector v;
	Comp tmpComp, maxComp;
	Item tmpItem;
	Cell cell;

	for (i = 0; i < N; i++)
		maxCols[i] = 0;

	printf("Введите количество строк: ");
	scanf("%d", &m);
	printf("Введите количество столбцов: ");
	scanf("%d", &n);

	if (m < 1 || m > N)
	{
		printf("Количество строк должно быть в диапозоне от 1 до %d\n", N);

		return 0;
	}

	if (n < 1 || n > N)
	{
		printf("Количество столбцов должно быть в диапозоне от 1 до %d\n", N);

		return 0;
	}

	vectorCreate(&v, 1);

	tmpItem.ind = EMPTY;

	vectorPushBack(&v, tmpItem);

	for (i = 0; i < m; i++)
	{
		isRowBegin = 0;

		for (j = 0; j < n; j++)
		{
			printf("Введите действительную и мнимую части ячейки [%d][%d]: ", i, j);
			scanf("%lf %lf", &tmpComp.a, &tmpComp.b);

			if (tmpComp.a == 0.0 && tmpComp.b == 0.0)
				continue;

			if (!isRowBegin)
			{
				isRowBegin = 1;

				tmpItem.ind = i;

				vectorPushBack(&v, tmpItem);
			}

			tmpItem.ind = j;

			vectorPushBack(&v, tmpItem);

			tmpItem.c = tmpComp;
			tmpItem.ind = COMP;

			vectorPushBack(&v, tmpItem);
		}

		if (isRowBegin)
		{
			tmpItem.ind = EMPTY;

			vectorPushBack(&v, tmpItem);
		}
	}

	tmpItem.ind = END;

	vectorPushBack(&v, tmpItem);

	printf("Обычное представление:\n");
	printSourceMatrix(&v, m, n);
	printf("Внутреннее представление\n");
	printInnerMatrix(&v);

	maxComp.a = 0.0;
	maxComp.b = 0.0;

	cell = cellFirst(&v);

	while (cell.row != END)
	{
		if (complexModule(cell.data) > complexModule(maxComp))
			maxComp = cell.data;

		cellNext(&cell);
	}

	printf("Максимальное комплексное число по модулю: (%.2lf, %.2lf), модуль равен: %.2lf\n", maxComp.a, maxComp.b, complexModule(maxComp));

	if (maxComp.a == 0.0 && maxComp.b == 0)
	{
		printf("Делить на него нельзя, так как его модуль равен нулю\n");

		return 0;
	}

	lastInd = 0;
	cnt = 0;

	cell = cellFirst(&v);

	while (cell.row != END)
	{
		if (complexModule(cell.data) == complexModule(maxComp))
		{
			maxCols[cell.col] = 1;
			lastInd = cell.col;
			cnt++;
		}

		cellNext(&cell);
	}

	if (cnt > 1)
		for (i = lastInd - 1; i >= 0; i--)
			if (maxCols[i])
			{
				lastInd = i;

				break;
			}

	cell = cellFirst(&v);

	while (cell.row != END)
	{
		if (cell.col == lastInd)
		{
			tmpItem = vectorLoad(&v, cell.ind + 1);
			tmpItem.c = complexDivide(cell.data, maxComp);

			vectorSave(&v, cell.ind + 1, tmpItem);
		}

		cellNext(&cell);
	}

	printf("Обычное представление после преобразования:\n");
	printSourceMatrix(&v, m, n);
	printf("Внутреннее представление после преобразования:\n");
	printInnerMatrix(&v);

	vectorDestroy(&v);

	return 0;
}