Ejemplo n.º 1
0
xsecsize_t XSECCanon::outputBuffer(unsigned char *outBuffer, xsecsize_t numBytes) {

	// numBytes of data are required to be placed in outBuffer.

	// Calculate amount left in buffer

	xsecsize_t remaining = m_bufferLength - m_bufferPoint;
	xsecsize_t bytesToGo = numBytes;
	xsecsize_t i = 0;					// current point in outBuffer


	// While we don't have enough, and have not completed - 

	while (!m_allNodesDone && (remaining < bytesToGo)) {

		// Copy what we have and get some more in the buffer
		memcpy(&outBuffer[i], &m_buffer[m_bufferPoint], remaining);
		i += remaining;
		m_bufferPoint += remaining;
		bytesToGo -= remaining;

		// Get more

		processNextNode();

		remaining = m_bufferLength - m_bufferPoint;		// This will be reset by processNextElement
													// "-bufferPoint" is just in case.

	}

	if (m_allNodesDone && (remaining < bytesToGo)) {

		// Was not enough data to fill everything up
		memcpy (&outBuffer[i], &m_buffer[m_bufferPoint], remaining);
		m_bufferPoint += remaining;
		return i + remaining;
	}
	
	// Copy the tail of the buffer

	memcpy(&outBuffer[i], &m_buffer[m_bufferPoint], bytesToGo);
	m_bufferPoint += bytesToGo;
	return (bytesToGo + i);
	
}
Ejemplo n.º 2
0
void SymbolTable::processGDLNode(const GDLNode *gdlNode, bool isIfHead) {
	switch (gdlNode->getInstanceOf()) {
		case INSTANCE_OF_BASE_NODE:
			if (!isIfHead) {
				throw Exception("Base cannot be in the body of if node");
			}
			processBaseNode((BaseNode*)gdlNode);
			break;
		case INSTANCE_OF_DISTINCT_NODE:
			if (isIfHead) {
				throw Exception("Distinct cannot be in the head of if node");
			}
			break;
		case INSTANCE_OF_DOES_NODE:
			if (isIfHead) {
				throw Exception("Does cannot be in the head of if node");
			}
			processDoesNode((DoesNode*)gdlNode);
			break;
		case INSTANCE_OF_GOAL_NODE:
			if (!isIfHead) {
				throw Exception("Goal cannot be in the body of if node");
			}
			break;
		case INSTANCE_OF_INIT_NODE:
			if (!isIfHead) {
				throw Exception("Init cannot be in the body of if node");
			}
			processInitNode((InitNode*)gdlNode);
			break;
		case INSTANCE_OF_INPUT_NODE:
			if (!isIfHead) {
				throw Exception("Input cannot be in the body of if node");
			}
			processInputNode((InputNode*)gdlNode);
			break;
		case INSTANCE_OF_LEGAL_NODE:
			if (!isIfHead) {
				throw Exception("Legal cannot be in the body of if node");
			}
			processLegalNode((LegalNode*)gdlNode);
			break;
		case INSTANCE_OF_NEXT_NODE:
			if (!isIfHead) {
				throw Exception("Next cannot be in the body of if node");
			}
			processNextNode((NextNode*)gdlNode);
			break;
		case INSTANCE_OF_NOT_NODE:
			if (isIfHead) {
				throw Exception("Not cannot be in the head of if node");
			}
			processNotNode((NotNode*)gdlNode);
			break;
		case INSTANCE_OF_OR_NODE:
			if (isIfHead) {
				throw Exception("Or cannot be in the head of if node");
			}
			processOrNode((OrNode*)gdlNode);
			break;
		case INSTANCE_OF_PROPOSITION_NODE:
			if (isIfHead) {
				addProposition((PropositionNode*)gdlNode, true);
			} else {
				addProposition((PropositionNode*)gdlNode);
			}
			break;
		case INSTANCE_OF_TERMINAL_NODE:
			if (!isIfHead) {
				throw Exception("Terminal cannot be in the body of if node");
			}
			break;
		case INSTANCE_OF_TRUE_NODE:
			if (isIfHead) {
				throw Exception("True cannot be in the head of if node");
			}
			processTrueNode((TrueNode*)gdlNode);
			break;
		case INSTANCE_OF_ROLE_NODE:
			break;
		default:
			throw Exception("processGDLNode function threw an exception: Unexpected Node of type " + std::to_string(gdlNode->getInstanceOf()));
	}
}