idTech4.Text.idLexer.ParseInt C# (CSharp) Method

ParseInt() public method

Parses an int.
public ParseInt ( ) : int
return int
		public int ParseInt()
		{
			idToken token;

			if((token = ReadToken()) == null)
			{
				Error("couldn't read expected integer");
				return 0;
			}

			string tokenValue = token.ToString();

			if((token.Type == TokenType.Punctuation) && (tokenValue == "-"))
			{
				token = ExpectTokenType(TokenType.Number, TokenSubType.Integer);

				return -token.ToInt32();
			}
			else if((token.Type != TokenType.Number) || (token.SubType == TokenSubType.Float))
			{
				Error("expected integer value, found '{0}'", tokenValue);
			}

			return token.ToInt32();
		}

Usage Example

		private void ParseJoint(idLexer lexer, idMD5Joint joint, ref idJointQuaternion defaultPose)
		{
			//
			// parse name
			//
			joint.Name = lexer.ReadToken().ToString();

			//
			// parse parent
			//
			int parentIndex = lexer.ParseInt();

			if(parentIndex >= 0)
			{
				if(parentIndex >= (_joints.Length - 1))
				{
					lexer.Error("Invalid parent for joint '{0}'", joint.Name);
				}

				joint.Parent = _joints[parentIndex];
			}
		
			//
			// parse default pose
			//
			float[] tmp = lexer.Parse1DMatrix(3);
			defaultPose.Translation = new Vector3(tmp[0], tmp[1], tmp[2]);

			tmp = lexer.Parse1DMatrix(3);
			defaultPose.Quaternion = new Quaternion(tmp[0], tmp[1], tmp[2], 0);
			defaultPose.Quaternion.W = idHelper.CalculateW(defaultPose.Quaternion);
		}
All Usage Examples Of idTech4.Text.idLexer::ParseInt