Example #1
0
bool CArchonProcess::TransformAddress (const CString &sAddress, 
									   const CString &sMsg, 
									   CDatum dPayload, 
									   CString *retsDestMsgAddress, 
									   CString *retsDestMsg, 
									   CDatum *retdPayload, 
									   CString *retsError)

//	TransformAddress
//
//	Transforms a Transpace Address.

	{
	CString sNamespace;
	if (!CTranspaceInterface::ParseAddress(sAddress, &sNamespace))
		{
		*retsError = strPattern(ERR_BAD_TRANSPACE_ADDRESS, sAddress);
		return false;
		}

	//	Is this a message namespace?

	char *pPos = sNamespace.GetParsePointer();
	if (*pPos == '@')
		{
		//	Send the message directly to the port specified by the namespace

		*retsDestMsgAddress = CString(pPos + 1);
		*retsDestMsg = sMsg;
		*retdPayload = dPayload;
		}

	//	Is this a service namespace?

	else if (*pPos == '#')
		{
		//	Parse the service endpoint

		CString sService(pPos + 1);

		//	Encode into the proper payload

		CComplexArray *pPayload = new CComplexArray;
		pPayload->Append(sService);
		pPayload->Append(sMsg);
		pPayload->Append(dPayload);

		//	Done

		*retsDestMsgAddress = ADDRESS_HYPERION_COMMAND;
		*retsDestMsg = MSG_HYPERION_SERVICE_MSG;
		*retdPayload = CDatum(pPayload);
		}

	//	If this is a slash, then convert to Aeon

	else if (*pPos == '/')
		{
		*retsDestMsgAddress = ADDRESS_AEON_COMMAND;
		*retsDestMsg = sMsg;
		*retdPayload = dPayload;
		}

	//	Otherwise, can't parse

	else
		{
		*retsError = strPattern(ERR_BAD_TRANSPACE_ADDRESS, sAddress);
		return false;
		}

	return true;
	}
Example #2
0
CDatum::Types CDatum::GetStringValueType (const CString &sValue)

//	GetStringValueType
//
//	Returns one of the following:
//
//	typeNil if sValue is empty
//	typeInteger32 if sValue is a 32-bit integer
//	typeIntegerIP if sValue is an integer (which may or may not be > 64-bits)
//	typeDouble if sValue is a double
//	typeString otherwise.

	{
	enum EStates
		{
		stateStart,
		stateHex0,
		stateHex,
		stateInteger,
		stateDoubleFrac,
		stateDoubleExp,
		stateDoubleExpSign,
		};

	char *pPos = sValue.GetParsePointer();
	char *pPosEnd = pPos + sValue.GetLength();
	int iState = stateStart;

	while (pPos < pPosEnd)
		{
		switch (iState)
			{
			case stateStart:
				{
				//	If 0 then we might be a hex number

				if (*pPos == '0')
					iState = stateHex0;

				//	If -, +, or a digit, we might be an integer

				else if (*pPos == '-' || *pPos == '+' || strIsDigit(pPos))
					iState = stateInteger;

				//	If . then we might be a double

				else if (*pPos == '.')
					iState = stateDoubleFrac;

				//	Otherwise, we are a string

				else
					return typeString;

				break;
				}

			case stateHex0:
				{
				if (*pPos == 'x' || *pPos == 'X')
					iState = stateHex;
				else if (strIsDigit(pPos))
					iState = stateInteger;
				else if (*pPos == '.')
					iState = stateDoubleFrac;
				else if (*pPos == 'e' || *pPos == 'E')
					iState = stateDoubleExp;
				else
					return typeString;

				break;
				}

			case stateHex:
				{
				if (strIsDigit(pPos)
						|| (*pPos >= 'A' && *pPos <= 'F')
						|| (*pPos >= 'a' && *pPos <= 'f'))
					NULL;
				else
					return typeString;

				break;
				}

			case stateInteger:
				{
				if (strIsDigit(pPos))
					NULL;
				else if (*pPos == '.')
					iState = stateDoubleFrac;
				else if (*pPos == 'e' || *pPos == 'E')
					iState = stateDoubleExp;
				else
					return typeString;

				break;
				}

			case stateDoubleFrac:
				{
				if (strIsDigit(pPos))
					NULL;
				else if (*pPos == 'e' || *pPos == 'E')
					iState = stateDoubleExp;
				else
					return typeString;

				break;
				}

			case stateDoubleExp:
				{
				if (*pPos == '+' || *pPos == '-' || strIsDigit(pPos))
					iState = stateDoubleExpSign;
				else
					return typeString;

				break;
				}

			case stateDoubleExpSign:
				{
				if (strIsDigit(pPos))
					NULL;
				else
					return typeString;

				break;
				}
			}

		pPos++;
		}

	switch (iState)
		{
		case stateStart:
			return typeNil;

		case stateHex:
			//	LATER:
			return typeString;

		case stateInteger:
			if (strOverflowsInteger32(sValue))
				return typeIntegerIP;
			else
				return typeInteger32;

		case stateDoubleFrac:
		case stateDoubleExpSign:
			return typeDouble;

		default:
			return typeString;
		}
	}