2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
26 ===========================================================================
33 ===============================================================================
35 idToken is a token read from a file or memory with idLexer or idParser
37 ===============================================================================
41 #define TT_STRING 1 // string
42 #define TT_LITERAL 2 // literal
43 #define TT_NUMBER 3 // number
44 #define TT_NAME 4 // name
45 #define TT_PUNCTUATION 5 // punctuation
48 #define TT_INTEGER 0x00001 // integer
49 #define TT_DECIMAL 0x00002 // decimal number
50 #define TT_HEX 0x00004 // hexadecimal number
51 #define TT_OCTAL 0x00008 // octal number
52 #define TT_BINARY 0x00010 // binary number
53 #define TT_LONG 0x00020 // long int
54 #define TT_UNSIGNED 0x00040 // unsigned int
55 #define TT_FLOAT 0x00080 // floating point number
56 #define TT_SINGLE_PRECISION 0x00100 // float
57 #define TT_DOUBLE_PRECISION 0x00200 // double
58 #define TT_EXTENDED_PRECISION 0x00400 // long double
59 #define TT_INFINITE 0x00800 // infinite 1.#INF
60 #define TT_INDEFINITE 0x01000 // indefinite 1.#IND
61 #define TT_NAN 0x02000 // NaN
62 #define TT_IPADDRESS 0x04000 // ip address
63 #define TT_IPPORT 0x08000 // ip port
64 #define TT_VALUESVALID 0x10000 // set if intvalue and floatvalue are valid
66 // string sub type is the length of the string
67 // literal sub type is the ASCII code
68 // punctuation sub type is the punctuation id
69 // name sub type is the length of the name
71 class idToken : public idStr {
73 friend class idParser;
77 int type; // token type
78 int subtype; // token sub type
79 int line; // line in script the token was on
80 int linesCrossed; // number of lines crossed in white space before token
81 int flags; // token flags, used for recursive defines
85 idToken( const idToken *token );
88 void operator=( const idStr& text );
89 void operator=( const char *text );
91 double GetDoubleValue( void ); // double value of TT_NUMBER
92 float GetFloatValue( void ); // float value of TT_NUMBER
93 unsigned long GetUnsignedLongValue( void ); // unsigned long value of TT_NUMBER
94 int GetIntValue( void ); // int value of TT_NUMBER
95 int WhiteSpaceBeforeToken( void ) const;// returns length of whitespace before token
96 void ClearTokenWhiteSpace( void ); // forget whitespace before token
98 void NumberValue( void ); // calculate values for a TT_NUMBER
101 unsigned long intvalue; // integer value
102 double floatvalue; // floating point value
103 const char * whiteSpaceStart_p; // start of white space before token, only used by idLexer
104 const char * whiteSpaceEnd_p; // end of white space before token, only used by idLexer
105 idToken * next; // next token in chain, only used by idParser
107 void AppendDirty( const char a ); // append character without adding trailing zero
110 ID_INLINE idToken::idToken( void ) {
113 ID_INLINE idToken::idToken( const idToken *token ) {
117 ID_INLINE idToken::~idToken( void ) {
120 ID_INLINE void idToken::operator=( const char *text) {
121 *static_cast<idStr *>(this) = text;
124 ID_INLINE void idToken::operator=( const idStr& text ) {
125 *static_cast<idStr *>(this) = text;
128 ID_INLINE double idToken::GetDoubleValue( void ) {
129 if ( type != TT_NUMBER ) {
132 if ( !(subtype & TT_VALUESVALID) ) {
138 ID_INLINE float idToken::GetFloatValue( void ) {
139 return (float) GetDoubleValue();
142 ID_INLINE unsigned long idToken::GetUnsignedLongValue( void ) {
143 if ( type != TT_NUMBER ) {
146 if ( !(subtype & TT_VALUESVALID) ) {
152 ID_INLINE int idToken::GetIntValue( void ) {
153 return (int) GetUnsignedLongValue();
156 ID_INLINE int idToken::WhiteSpaceBeforeToken( void ) const {
157 return ( whiteSpaceEnd_p > whiteSpaceStart_p );
160 ID_INLINE void idToken::AppendDirty( const char a ) {
161 EnsureAlloced( len + 2, true );
165 #endif /* !__TOKEN_H__ */