2012-11-26 18:58:24 +00:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
|
|
|
|
Doom 3 BFG Edition GPL Source Code
|
2012-11-28 15:47:07 +00:00
|
|
|
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
In addition, the Doom 3 BFG Edition 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 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
===========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __TOKENPARSER_H__
|
|
|
|
#define __TOKENPARSER_H__
|
2012-11-28 15:47:07 +00:00
|
|
|
class idBinaryToken
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
public:
|
2012-11-28 15:47:07 +00:00
|
|
|
idBinaryToken()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
tokenType = 0;
|
|
|
|
tokenSubType = 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
idBinaryToken( const idToken& tok )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
token = tok.c_str();
|
|
|
|
tokenType = tok.type;
|
|
|
|
tokenSubType = tok.subtype;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
bool operator==( const idBinaryToken& b ) const
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return ( tokenType == b.tokenType && tokenSubType == b.tokenSubType && token.Cmp( b.token ) == 0 );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
void Read( idFile* inFile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
inFile->ReadString( token );
|
|
|
|
inFile->ReadBig( tokenType );
|
|
|
|
inFile->ReadBig( tokenSubType );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
void Write( idFile* inFile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
inFile->WriteString( token );
|
|
|
|
inFile->WriteBig( tokenType );
|
|
|
|
inFile->WriteBig( tokenSubType );
|
|
|
|
}
|
|
|
|
idStr token;
|
|
|
|
int8 tokenType;
|
|
|
|
short tokenSubType;
|
|
|
|
};
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
class idTokenIndexes
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
public:
|
|
|
|
idTokenIndexes() {}
|
2012-11-28 15:47:07 +00:00
|
|
|
void Clear()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
tokenIndexes.Clear();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
int Append( short sdx )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return tokenIndexes.Append( sdx );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
int Num()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return tokenIndexes.Num();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
void SetNum( int num )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
tokenIndexes.SetNum( num );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
short& operator[]( const int index )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return tokenIndexes[ index ];
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
void SetName( const char* name )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
fileName = name;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* GetName()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return fileName.c_str();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
void Write( idFile* outFile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
outFile->WriteString( fileName );
|
|
|
|
outFile->WriteBig( ( int )tokenIndexes.Num() );
|
|
|
|
outFile->WriteBigArray( tokenIndexes.Ptr(), tokenIndexes.Num() );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
void Read( idFile* inFile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
inFile->ReadString( fileName );
|
|
|
|
int num;
|
|
|
|
inFile->ReadBig( num );
|
|
|
|
tokenIndexes.SetNum( num );
|
|
|
|
inFile->ReadBigArray( tokenIndexes.Ptr(), num );
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
idList< short > tokenIndexes;
|
|
|
|
idStr fileName;
|
|
|
|
};
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
class idTokenParser
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
public:
|
2012-11-28 15:47:07 +00:00
|
|
|
idTokenParser()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
timeStamp = FILE_NOT_FOUND_TIMESTAMP;
|
|
|
|
preloaded = false;
|
|
|
|
currentToken = 0;
|
|
|
|
currentTokenList = 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
~idTokenParser()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
Clear();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
void Clear()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
tokens.Clear();
|
|
|
|
guiTokenIndexes.Clear();
|
|
|
|
currentToken = 0;
|
|
|
|
currentTokenList = -1;
|
|
|
|
preloaded = false;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
void LoadFromFile( const char* filename );
|
|
|
|
void WriteToFile( const char* filename );
|
|
|
|
void LoadFromParser( idParser& parser, const char* guiName );
|
|
|
|
|
|
|
|
bool StartParsing( const char* fileName );
|
|
|
|
void DoneParsing()
|
|
|
|
{
|
|
|
|
currentTokenList = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsLoaded()
|
|
|
|
{
|
|
|
|
return tokens.Num() > 0;
|
|
|
|
}
|
|
|
|
bool ReadToken( idToken* tok );
|
|
|
|
int ExpectTokenString( const char* string );
|
|
|
|
int ExpectTokenType( int type, int subtype, idToken* token );
|
|
|
|
int ExpectAnyToken( idToken* token );
|
2012-11-26 18:58:24 +00:00
|
|
|
void SetMarker() {}
|
2012-11-28 15:47:07 +00:00
|
|
|
void UnreadToken( const idToken* token );
|
|
|
|
void Error( VERIFY_FORMAT_STRING const char* str, ... );
|
|
|
|
void Warning( VERIFY_FORMAT_STRING const char* str, ... );
|
2012-11-26 18:58:24 +00:00
|
|
|
int ParseInt();
|
|
|
|
bool ParseBool();
|
2012-11-28 15:47:07 +00:00
|
|
|
float ParseFloat( bool* errorFlag = NULL );
|
|
|
|
void UpdateTimeStamp( ID_TIME_T& t )
|
|
|
|
{
|
|
|
|
if( t > timeStamp )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
timeStamp = t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
idList< idBinaryToken > tokens;
|
|
|
|
idList< idTokenIndexes > guiTokenIndexes;
|
|
|
|
int currentToken;
|
|
|
|
int currentTokenList;
|
|
|
|
ID_TIME_T timeStamp;
|
|
|
|
bool preloaded;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* !__TOKENPARSER_H__ */
|