Added std:: infront of string refrences to solve compile problems under gcc 3.0.3.
Also converted to unix file endings so other the windows style files.
This commit is contained in:
@@ -18,62 +18,62 @@
|
||||
#include <stdio.h>
|
||||
|
||||
/* trpage_parse.cpp
|
||||
This source file contains methods for the trpgr_Parser and trpgr_Token classes.
|
||||
trpgr_Parser is the main class. It parses the basic structure of paging archive
|
||||
data out of Read Buffers. You should not need to change this.
|
||||
If you want to parse data out of a different structure instead, look at
|
||||
subclassing trpgReadBuffer and replacing its virtual methods. That's what
|
||||
trpgMemReadBuffer is doing.
|
||||
This source file contains methods for the trpgr_Parser and trpgr_Token classes.
|
||||
trpgr_Parser is the main class. It parses the basic structure of paging archive
|
||||
data out of Read Buffers. You should not need to change this.
|
||||
If you want to parse data out of a different structure instead, look at
|
||||
subclassing trpgReadBuffer and replacing its virtual methods. That's what
|
||||
trpgMemReadBuffer is doing.
|
||||
|
||||
This file also contains the implementation of trpgSceneParser().
|
||||
That class implements a set of callbacks for handling the Pushes and Pops
|
||||
in an archive. You fill in the Start/EndChildren callbacks and register
|
||||
for the rest of the tokens that you want.
|
||||
*/
|
||||
That class implements a set of callbacks for handling the Pushes and Pops
|
||||
in an archive. You fill in the Start/EndChildren callbacks and register
|
||||
for the rest of the tokens that you want.
|
||||
*/
|
||||
|
||||
#include "trpage_read.h"
|
||||
|
||||
/* ***************************
|
||||
Paging token callback structure
|
||||
Paging token callback structure
|
||||
***************************
|
||||
*/
|
||||
trpgr_Token::trpgr_Token()
|
||||
{
|
||||
cb = NULL;
|
||||
destroy = true;
|
||||
cb = NULL;
|
||||
destroy = true;
|
||||
}
|
||||
trpgr_Token::~trpgr_Token()
|
||||
{
|
||||
}
|
||||
trpgr_Token::trpgr_Token(int in_tok,trpgr_Callback *in_cb,bool in_dest)
|
||||
{
|
||||
init(in_tok,in_cb,in_dest);
|
||||
init(in_tok,in_cb,in_dest);
|
||||
}
|
||||
void trpgr_Token::init(int in_tok,trpgr_Callback *in_cb,bool in_dest)
|
||||
{
|
||||
Token = in_tok;
|
||||
cb = in_cb;
|
||||
destroy = in_dest;
|
||||
Token = in_tok;
|
||||
cb = in_cb;
|
||||
destroy = in_dest;
|
||||
}
|
||||
// Destruct
|
||||
// Destroy our callback if appropriate
|
||||
void trpgr_Token::Destruct()
|
||||
{
|
||||
if (cb && destroy)
|
||||
delete cb;
|
||||
cb = NULL;
|
||||
destroy = true;
|
||||
if (cb && destroy)
|
||||
delete cb;
|
||||
cb = NULL;
|
||||
destroy = true;
|
||||
}
|
||||
|
||||
/* ***************************
|
||||
Paging parser implementation.
|
||||
Paging parser implementation.
|
||||
***************************
|
||||
*/
|
||||
|
||||
// Constructor
|
||||
trpgr_Parser::trpgr_Parser()
|
||||
{
|
||||
lastObject = NULL;
|
||||
lastObject = NULL;
|
||||
}
|
||||
trpgr_Parser::~trpgr_Parser()
|
||||
{
|
||||
@@ -82,63 +82,63 @@ trpgr_Parser::~trpgr_Parser()
|
||||
// Validity check
|
||||
bool trpgr_Parser::isValid() const
|
||||
{
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Add Callback
|
||||
// Make the given callback object current for the given token.
|
||||
void trpgr_Parser::AddCallback(trpgToken tok,trpgr_Callback *cb,bool in_dest)
|
||||
{
|
||||
RemoveCallback(tok);
|
||||
RemoveCallback(tok);
|
||||
|
||||
tokenMap[tok] = trpgr_Token(tok,cb,in_dest);
|
||||
tokenMap[tok] = trpgr_Token(tok,cb,in_dest);
|
||||
}
|
||||
|
||||
// Callback used as writeable wrapper
|
||||
class WriteWrapper : public trpgr_Callback {
|
||||
public:
|
||||
WriteWrapper(trpgReadWriteable *in_wr) { wr = in_wr; };
|
||||
void *Parse(trpgToken,trpgReadBuffer &buf) {
|
||||
if (wr->Read(buf))
|
||||
return wr;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
WriteWrapper(trpgReadWriteable *in_wr) { wr = in_wr; };
|
||||
void *Parse(trpgToken,trpgReadBuffer &buf) {
|
||||
if (wr->Read(buf))
|
||||
return wr;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
protected:
|
||||
trpgReadWriteable *wr;
|
||||
trpgReadWriteable *wr;
|
||||
};
|
||||
|
||||
// Add Callback (writeable)
|
||||
// Build a wrapper around a trpgWriteable so it can read itself
|
||||
void trpgr_Parser::AddCallback(trpgToken tok,trpgReadWriteable *wr)
|
||||
{
|
||||
AddCallback(tok,new WriteWrapper(wr),true);
|
||||
AddCallback(tok,new WriteWrapper(wr),true);
|
||||
}
|
||||
|
||||
// Remove Callback
|
||||
void trpgr_Parser::RemoveCallback(trpgToken tok)
|
||||
{
|
||||
tokenMap.erase(tok);
|
||||
tokenMap.erase(tok);
|
||||
}
|
||||
|
||||
// Set Default Callback
|
||||
// This gets called for all tokens we don't understand
|
||||
void trpgr_Parser::SetDefaultCallback(trpgr_Callback *cb,bool in_dest)
|
||||
{
|
||||
defCb.Destruct();
|
||||
defCb.init(-1,cb,in_dest);
|
||||
defCb.Destruct();
|
||||
defCb.init(-1,cb,in_dest);
|
||||
}
|
||||
|
||||
/* Token Is Valid
|
||||
Checks if something *could be* a token.
|
||||
Doesn't necessarily mean that it is.
|
||||
*/
|
||||
Checks if something *could be* a token.
|
||||
Doesn't necessarily mean that it is.
|
||||
*/
|
||||
bool trpgr_Parser::TokenIsValid(trpgToken tok)
|
||||
{
|
||||
if (tok < 0)
|
||||
return false;
|
||||
if (tok < 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Parse Buffer
|
||||
@@ -148,93 +148,93 @@ bool trpgr_Parser::TokenIsValid(trpgToken tok)
|
||||
*/
|
||||
bool trpgr_Parser::Parse(trpgReadBuffer &buf)
|
||||
{
|
||||
bool ret = true;
|
||||
bool ret = true;
|
||||
|
||||
try {
|
||||
while (!buf.isEmpty()) {
|
||||
/* We're expecting the following
|
||||
Token (int32)
|
||||
Length (int32)
|
||||
Data (variable)
|
||||
*/
|
||||
trpgToken tok;
|
||||
int32 len;
|
||||
if (!buf.Get(tok)) throw 1;
|
||||
// Push and Pop are special - no data
|
||||
if (tok != TRPG_PUSH && tok != TRPG_POP) {
|
||||
if (!buf.Get(len)) throw 1;
|
||||
if (!TokenIsValid(tok)) throw 1;
|
||||
if (len < 0) throw 1;
|
||||
// Limit what we're reading to the length of this
|
||||
buf.PushLimit(len);
|
||||
}
|
||||
try {
|
||||
while (!buf.isEmpty()) {
|
||||
/* We're expecting the following
|
||||
Token (int32)
|
||||
Length (int32)
|
||||
Data (variable)
|
||||
*/
|
||||
trpgToken tok;
|
||||
int32 len;
|
||||
if (!buf.Get(tok)) throw 1;
|
||||
// Push and Pop are special - no data
|
||||
if (tok != TRPG_PUSH && tok != TRPG_POP) {
|
||||
if (!buf.Get(len)) throw 1;
|
||||
if (!TokenIsValid(tok)) throw 1;
|
||||
if (len < 0) throw 1;
|
||||
// Limit what we're reading to the length of this
|
||||
buf.PushLimit(len);
|
||||
}
|
||||
|
||||
// Call our token handler for this one
|
||||
try {
|
||||
trpgr_Token *tcb = &tokenMap[tok];
|
||||
if (!tcb)
|
||||
// No such token, call the default
|
||||
tcb = &defCb;
|
||||
// Run the callback
|
||||
if (tcb->cb) {
|
||||
void *ret = tcb->cb->Parse(tok,buf);
|
||||
// Note: Do something with the return value
|
||||
lastObject = ret;
|
||||
}
|
||||
}
|
||||
catch (...) {
|
||||
// Don't want to screw up the limit stack
|
||||
}
|
||||
// No limit to worry about with push and pop
|
||||
if (tok != TRPG_PUSH && tok != TRPG_POP) {
|
||||
buf.SkipToLimit();
|
||||
buf.PopLimit();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (...) {
|
||||
// Failed to parse.
|
||||
ret = false;
|
||||
}
|
||||
// Call our token handler for this one
|
||||
try {
|
||||
trpgr_Token *tcb = &tokenMap[tok];
|
||||
if (!tcb)
|
||||
// No such token, call the default
|
||||
tcb = &defCb;
|
||||
// Run the callback
|
||||
if (tcb->cb) {
|
||||
void *ret = tcb->cb->Parse(tok,buf);
|
||||
// Note: Do something with the return value
|
||||
lastObject = ret;
|
||||
}
|
||||
}
|
||||
catch (...) {
|
||||
// Don't want to screw up the limit stack
|
||||
}
|
||||
// No limit to worry about with push and pop
|
||||
if (tok != TRPG_PUSH && tok != TRPG_POP) {
|
||||
buf.SkipToLimit();
|
||||
buf.PopLimit();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (...) {
|
||||
// Failed to parse.
|
||||
ret = false;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* ****************
|
||||
Scene Parser
|
||||
****************
|
||||
*/
|
||||
/* ****************
|
||||
Scene Parser
|
||||
****************
|
||||
*/
|
||||
// Helper - callback for Push
|
||||
class trpgSceneHelperPush : public trpgr_Callback {
|
||||
public:
|
||||
trpgSceneHelperPush(trpgSceneParser *in_parse) { parse = in_parse; };
|
||||
void *Parse(trpgToken tok,trpgReadBuffer &buf) {
|
||||
// Call the start children callback
|
||||
parse->StartChildren(parse->lastObject);
|
||||
parse->parents.push_back(parse->lastObject);
|
||||
return (void *)1;
|
||||
}
|
||||
trpgSceneHelperPush(trpgSceneParser *in_parse) { parse = in_parse; };
|
||||
void *Parse(trpgToken tok,trpgReadBuffer &buf) {
|
||||
// Call the start children callback
|
||||
parse->StartChildren(parse->lastObject);
|
||||
parse->parents.push_back(parse->lastObject);
|
||||
return (void *)1;
|
||||
}
|
||||
protected:
|
||||
trpgSceneParser *parse;
|
||||
trpgSceneParser *parse;
|
||||
};
|
||||
|
||||
// Helper - callback for Pop
|
||||
class trpgSceneHelperPop : public trpgr_Callback {
|
||||
public:
|
||||
trpgSceneHelperPop(trpgSceneParser *in_parse) { parse = in_parse; };
|
||||
void *Parse(trpgToken tok,trpgReadBuffer &buf) {
|
||||
// Make sure we don't have an extra pop
|
||||
if (parse->parents.size() == 0)
|
||||
// Note: let someone know about the extra pop
|
||||
return NULL;
|
||||
// Call the end children callback
|
||||
int len = parse->parents.size();
|
||||
parse->EndChildren(parse->parents[len-1]);
|
||||
parse->parents.resize(len-1);
|
||||
return (void *)1;
|
||||
}
|
||||
trpgSceneHelperPop(trpgSceneParser *in_parse) { parse = in_parse; };
|
||||
void *Parse(trpgToken tok,trpgReadBuffer &buf) {
|
||||
// Make sure we don't have an extra pop
|
||||
if (parse->parents.size() == 0)
|
||||
// Note: let someone know about the extra pop
|
||||
return NULL;
|
||||
// Call the end children callback
|
||||
int len = parse->parents.size();
|
||||
parse->EndChildren(parse->parents[len-1]);
|
||||
parse->parents.resize(len-1);
|
||||
return (void *)1;
|
||||
}
|
||||
protected:
|
||||
trpgSceneParser *parse;
|
||||
trpgSceneParser *parse;
|
||||
};
|
||||
|
||||
// Helper - default callback
|
||||
@@ -242,23 +242,23 @@ protected:
|
||||
// Note: Need to use this fact above
|
||||
class trpgSceneHelperDefault : public trpgr_Callback {
|
||||
public:
|
||||
trpgSceneHelperDefault(trpgSceneParser *in_parse) { parse = in_parse; }
|
||||
void *Parse(trpgToken tok,trpgReadBuffer &buf) {
|
||||
// Absorb it quietly
|
||||
return (void *)1;
|
||||
}
|
||||
trpgSceneHelperDefault(trpgSceneParser *in_parse) { parse = in_parse; }
|
||||
void *Parse(trpgToken tok,trpgReadBuffer &buf) {
|
||||
// Absorb it quietly
|
||||
return (void *)1;
|
||||
}
|
||||
protected:
|
||||
trpgSceneParser *parse;
|
||||
trpgSceneParser *parse;
|
||||
};
|
||||
|
||||
trpgSceneParser::trpgSceneParser()
|
||||
{
|
||||
// Register for Push and Pop
|
||||
AddCallback(TRPG_PUSH,new trpgSceneHelperPush(this));
|
||||
AddCallback(TRPG_POP,new trpgSceneHelperPop(this));
|
||||
// Register for Push and Pop
|
||||
AddCallback(TRPG_PUSH,new trpgSceneHelperPush(this));
|
||||
AddCallback(TRPG_POP,new trpgSceneHelperPop(this));
|
||||
|
||||
// Register for default
|
||||
SetDefaultCallback(new trpgSceneHelperDefault(this));
|
||||
// Register for default
|
||||
SetDefaultCallback(new trpgSceneHelperDefault(this));
|
||||
};
|
||||
|
||||
trpgSceneParser::~trpgSceneParser()
|
||||
|
||||
Reference in New Issue
Block a user