From 88b669136922097ea5069ecc178d61777cac30fb Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 9 Feb 2002 19:46:44 +0000 Subject: [PATCH] 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. --- src/osgPlugins/txp/Makefile | 30 +- src/osgPlugins/txp/ReaderWriterTXP.cpp | 6 +- src/osgPlugins/txp/TrPageArchive.cpp | 2 +- src/osgPlugins/txp/trpage_geom.cpp | 956 ++++++++++++------------- src/osgPlugins/txp/trpage_parse.cpp | 254 +++---- 5 files changed, 624 insertions(+), 624 deletions(-) diff --git a/src/osgPlugins/txp/Makefile b/src/osgPlugins/txp/Makefile index bfac62de5..2b23b8602 100644 --- a/src/osgPlugins/txp/Makefile +++ b/src/osgPlugins/txp/Makefile @@ -2,21 +2,21 @@ include $(OSGHOME)/Make/makedefs C++FILES = \ - ReaderWriterTXP.cpp\ - TrPageArchive.cpp\ - TrPageParser.cpp\ - trpage_basic.cpp\ - trpage_geom.cpp\ - trpage_header.cpp\ - trpage_tile.cpp\ - trpage_readbuf.cpp\ - trpage_rarchive.cpp\ - trpage_writebuf.cpp\ - trpage_warchive.cpp\ - trpage_parse.cpp\ - trpage_nodes.cpp\ - trpage_model.cpp\ - trpage_material.cpp\ + ReaderWriterTXP.cpp\ + TrPageArchive.cpp\ + TrPageParser.cpp\ + trpage_basic.cpp\ + trpage_geom.cpp\ + trpage_header.cpp\ + trpage_tile.cpp\ + trpage_readbuf.cpp\ + trpage_rarchive.cpp\ + trpage_writebuf.cpp\ + trpage_warchive.cpp\ + trpage_parse.cpp\ + trpage_nodes.cpp\ + trpage_model.cpp\ + trpage_material.cpp\ TARGET_BASENAME = osgdb_txp diff --git a/src/osgPlugins/txp/ReaderWriterTXP.cpp b/src/osgPlugins/txp/ReaderWriterTXP.cpp index 04a9c99e2..b8557afe1 100644 --- a/src/osgPlugins/txp/ReaderWriterTXP.cpp +++ b/src/osgPlugins/txp/ReaderWriterTXP.cpp @@ -28,11 +28,11 @@ public: { }; - Node* readNode(const string &filename) + Node* readNode(const std::string &filename) { Group* ret = 0; // search the SGL data path - string foundname = osgDB::findFile(filename.c_str()); + std::string foundname = osgDB::findFile(filename.c_str()); if( !foundname.empty()) { if (archive.OpenFile(foundname)) @@ -65,7 +65,7 @@ public: return ret; }; - Object* readObject(const string &filename) + Object* readObject(const std::string &filename) { return readNode(filename); }; diff --git a/src/osgPlugins/txp/TrPageArchive.cpp b/src/osgPlugins/txp/TrPageArchive.cpp index 891edb242..d2506a6e1 100644 --- a/src/osgPlugins/txp/TrPageArchive.cpp +++ b/src/osgPlugins/txp/TrPageArchive.cpp @@ -39,7 +39,7 @@ TrPageArchive::~TrPageArchive() { } -bool TrPageArchive::OpenFile(const string &file) +bool TrPageArchive::OpenFile(const std::string &file) { m_alternate_path = osgDB::getFilePath(file); std::string name = osgDB::getSimpleFileName(file); diff --git a/src/osgPlugins/txp/trpage_geom.cpp b/src/osgPlugins/txp/trpage_geom.cpp index d6e1f06b1..3cb484869 100644 --- a/src/osgPlugins/txp/trpage_geom.cpp +++ b/src/osgPlugins/txp/trpage_geom.cpp @@ -15,11 +15,11 @@ */ /* trpage_geom.cpp - Methods for the trpgGeometry class. - This includes read and write methods. - You should only need to change something in here if you want to modify - what trpgGeometry contains. - */ + Methods for the trpgGeometry class. + This includes read and write methods. + You should only need to change something in here if you want to modify + what trpgGeometry contains. + */ #include #include @@ -37,9 +37,9 @@ // Constructor trpgGeometry::trpgGeometry() { - primType = Polygons; - normBind = Overall; - numPrim = 0; + primType = Polygons; + normBind = Overall; + numPrim = 0; } trpgGeometry::~trpgGeometry() { @@ -48,143 +48,143 @@ trpgGeometry::~trpgGeometry() // Reset function void trpgGeometry::Reset() { - primType = Polygons; - numPrim = 0; - primLength.resize(0); - materials.resize(0); - vertDataFloat.resize(0); - vertDataDouble.resize(0); - normBind = Overall; - normDataFloat.resize(0); - normDataDouble.resize(0); - colors.resize(0); - texData.resize(0); - edgeFlags.resize(0); + primType = Polygons; + numPrim = 0; + primLength.resize(0); + materials.resize(0); + vertDataFloat.resize(0); + vertDataDouble.resize(0); + normBind = Overall; + normDataFloat.resize(0); + normDataDouble.resize(0); + colors.resize(0); + texData.resize(0); + edgeFlags.resize(0); } // Set functions void trpgGeometry::SetPrimType(PrimType type) { - primType = type; + primType = type; } void trpgGeometry::SetPrimLengths(int num,const int *len) { - if (num < 0) - return; + if (num < 0) + return; - numPrim = num; - for (int i=0;i= (int)materials.size()) - return; + if (which < 0 || which >= (int)materials.size()) + return; - materials[which] = mat; + materials[which] = mat; } void trpgGeometry::SetMaterials(int32 num,const int32 *mat) { - materials.resize(num); - for (int i=0;ifloatData.push_back(pt.x); - td->floatData.push_back(pt.y); - } else { - td->doubleData.push_back(pt.x); - td->doubleData.push_back(pt.y); - } + if (type == FloatData) { + td->floatData.push_back(pt.x); + td->floatData.push_back(pt.y); + } else { + td->doubleData.push_back(pt.x); + td->doubleData.push_back(pt.y); + } } void trpgGeometry::AddTexCoords(BindType bind) { - trpgTexData td; - td.bind = bind; - texData.push_back(td); + trpgTexData td; + td.bind = bind; + texData.push_back(td); } void trpgGeometry::SetEdgeFlags(int num,const char *flags) { - if (num < 0) - return; + if (num < 0) + return; - edgeFlags.resize(0); - for (int i=0;i= (int)materials.size()) return false; - m = materials[id]; - return true; + if (!isValid() || id < 0 || id >= (int)materials.size()) return false; + m = materials[id]; + return true; } bool trpgGeometry::GetNumVertex(int &v) const { - if (!isValid()) return false; - int nvf = vertDataFloat.size(); - int nvd = vertDataDouble.size(); - v = MAX(nvf,nvd); - return true; + if (!isValid()) return false; + int nvf = vertDataFloat.size(); + int nvd = vertDataDouble.size(); + v = MAX(nvf,nvd); + return true; } bool trpgGeometry::GetVertices(float32 *v) const { - unsigned int i; + unsigned int i; - if (!isValid()) return false; - if (vertDataFloat.size() != 0) - for (i=0;i= (int)vertDataFloat.size() && idMax >= (int)vertDataDouble.size())) - return false; - if (vertDataFloat.size() > vertDataDouble.size()) { - pt.x = vertDataFloat[id]; - pt.y = vertDataFloat[id+1]; - pt.z = vertDataFloat[id+2]; - } else { - pt.x = vertDataDouble[id]; - pt.y = vertDataDouble[id+1]; - pt.z = vertDataDouble[id+2]; - } - return true; + int id = 3*n; + int idMax = 3*n+2; + if (id < 0 || (idMax >= (int)vertDataFloat.size() && idMax >= (int)vertDataDouble.size())) + return false; + if (vertDataFloat.size() > vertDataDouble.size()) { + pt.x = vertDataFloat[id]; + pt.y = vertDataFloat[id+1]; + pt.z = vertDataFloat[id+2]; + } else { + pt.x = vertDataDouble[id]; + pt.y = vertDataDouble[id+1]; + pt.z = vertDataDouble[id+2]; + } + return true; } bool trpgGeometry::GetNumNormal(int32 &n) const { - if (!isValid()) return false; - if (normDataFloat.size() != 0) - n = normDataFloat.size(); - if (normDataDouble.size() != 0) - n = normDataDouble.size(); - return true; + if (!isValid()) return false; + if (normDataFloat.size() != 0) + n = normDataFloat.size(); + if (normDataDouble.size() != 0) + n = normDataDouble.size(); + return true; } bool trpgGeometry::GetNormals(float32 *v) const { - unsigned int i; + unsigned int i; - if (!isValid()) return false; - if (normDataFloat.size() != 0) - for (i=0;i= (int)colors.size()) return false; - *ci = colors[id]; - return true; + if (!isValid() || id < 0 || id >= (int)colors.size()) return false; + *ci = colors[id]; + return true; } bool trpgGeometry::GetNumTexCoordSets(int &n) const { - if (!isValid()) return false; - n = (int)texData.size(); - return true; + if (!isValid()) return false; + n = (int)texData.size(); + return true; } bool trpgGeometry::GetTexCoordSet(int id,trpgTexData *tx) const { - if (!isValid() || id < 0 || id >= (int)texData.size()) return false; - *tx = texData[id]; - return true; + if (!isValid() || id < 0 || id >= (int)texData.size()) return false; + *tx = texData[id]; + return true; } bool trpgGeometry::GetNumEdgeFlag(int &n) const { - if (!isValid()) return false; - n = (int)edgeFlags.size(); - return true; + if (!isValid()) return false; + n = (int)edgeFlags.size(); + return true; } bool trpgGeometry::GetEdgeFlags(char *e) const { - if (!isValid()) return false; - for (unsigned int i=0;i 0) { - buf.Begin(TRPG_GEOM_MATERIAL); - buf.Add((int32)materials.size()); - for (i=0;i 0) { + buf.Begin(TRPG_GEOM_MATERIAL); + buf.Add((int32)materials.size()); + for (i=0;i 0) { - buf.Begin(TRPG_GEOM_VERT32); - int32 num = vertDataFloat.size()/3; - buf.Add(num); - for (i=0;i<(unsigned int)3*num;i++) - buf.Add(vertDataFloat[i]); - buf.End(); - } - if (vertDataDouble.size() > 0) { - buf.Begin(TRPG_GEOM_VERT64); - int32 num = vertDataDouble.size()/3; - buf.Add(num); - for (i=0;i<(unsigned int)3*num;i++) - buf.Add(vertDataDouble[i]); - buf.End(); - } + /* Vertices + Float and Double should never both be here + Num vertex + Vertex data + */ + if (vertDataFloat.size() > 0) { + buf.Begin(TRPG_GEOM_VERT32); + int32 num = vertDataFloat.size()/3; + buf.Add(num); + for (i=0;i<(unsigned int)3*num;i++) + buf.Add(vertDataFloat[i]); + buf.End(); + } + if (vertDataDouble.size() > 0) { + buf.Begin(TRPG_GEOM_VERT64); + int32 num = vertDataDouble.size()/3; + buf.Add(num); + for (i=0;i<(unsigned int)3*num;i++) + buf.Add(vertDataDouble[i]); + buf.End(); + } - /* Normals - Normal binding - Num normals - Normal data - */ - if (normDataFloat.size() > 0) { - buf.Begin(TRPG_GEOM_NORM32); - buf.Add((int32)normBind); - int32 num = normDataFloat.size()/3; - buf.Add(num); - for (i=0;i<(unsigned int)3*num;i++) - buf.Add(normDataFloat[i]); - buf.End(); - } - if (normDataDouble.size() > 0) { - buf.Begin(TRPG_GEOM_NORM64); - buf.Add((int32)normBind); - int32 num = normDataDouble.size()/3; - buf.Add(num); - for (i=0;i<(unsigned int)3*num;i++) - buf.Add(normDataDouble[i]); - buf.End(); - } + /* Normals + Normal binding + Num normals + Normal data + */ + if (normDataFloat.size() > 0) { + buf.Begin(TRPG_GEOM_NORM32); + buf.Add((int32)normBind); + int32 num = normDataFloat.size()/3; + buf.Add(num); + for (i=0;i<(unsigned int)3*num;i++) + buf.Add(normDataFloat[i]); + buf.End(); + } + if (normDataDouble.size() > 0) { + buf.Begin(TRPG_GEOM_NORM64); + buf.Add((int32)normBind); + int32 num = normDataDouble.size()/3; + buf.Add(num); + for (i=0;i<(unsigned int)3*num;i++) + buf.Add(normDataDouble[i]); + buf.End(); + } - /* Colors - Color binding - Num colors - Colors - */ - if (colors.size() > 0) { - for (i=0;i 0) { + for (i=0;i 0) { - buf.Begin(TRPG_GEOM_EFLAG); - buf.Add((int32)edgeFlags.size()); - for (i=0;i 0) { + buf.Begin(TRPG_GEOM_EFLAG); + buf.Add((int32)edgeFlags.size()); + for (i=0;iSetPrimType((trpgGeometry::PrimType)primType); - buf.Get(num); - if (num < 0) throw 1; - geom->SetNumPrims(num); - buf.Get(hasPrimLen); - if (hasPrimLen) { - buf.GetArray(num,&iData); + try { + switch (tok) { + case TRPG_GEOM_PRIM: + buf.Get(primType); + geom->SetPrimType((trpgGeometry::PrimType)primType); + buf.Get(num); + if (num < 0) throw 1; + geom->SetNumPrims(num); + buf.Get(hasPrimLen); + if (hasPrimLen) { + buf.GetArray(num,&iData); if (ALIGNMENT_WORKAROUND) { int32 *aligned; @@ -643,13 +643,13 @@ void *geomCB::Parse(trpgToken tok,trpgReadBuffer &buf) free (aligned); } else - geom->SetPrimLengths(num,iData); - } - break; - case TRPG_GEOM_MATERIAL: - buf.Get(num); - if (num < 0) throw 1; - buf.GetArray(num,&iData); + geom->SetPrimLengths(num,iData); + } + break; + case TRPG_GEOM_MATERIAL: + buf.Get(num); + if (num < 0) throw 1; + buf.GetArray(num,&iData); if (ALIGNMENT_WORKAROUND) { int32 *aligned; @@ -659,12 +659,12 @@ void *geomCB::Parse(trpgToken tok,trpgReadBuffer &buf) free (aligned); } else - geom->SetMaterials(num,iData); - break; - case TRPG_GEOM_VERT32: - buf.Get(num); - if (num < 0) throw 1; - buf.GetArray(3*num,&fData); + geom->SetMaterials(num,iData); + break; + case TRPG_GEOM_VERT32: + buf.Get(num); + if (num < 0) throw 1; + buf.GetArray(3*num,&fData); if (ALIGNMENT_WORKAROUND) { float32 *aligned; @@ -674,12 +674,12 @@ void *geomCB::Parse(trpgToken tok,trpgReadBuffer &buf) free (aligned); } else - geom->SetVertices(num,fData); - break; - case TRPG_GEOM_VERT64: - buf.Get(num); - if (num < 0) throw 1; - buf.GetArray(3*num,&dData); + geom->SetVertices(num,fData); + break; + case TRPG_GEOM_VERT64: + buf.Get(num); + if (num < 0) throw 1; + buf.GetArray(3*num,&dData); if (ALIGNMENT_WORKAROUND) { float64 *aligned; @@ -689,14 +689,14 @@ void *geomCB::Parse(trpgToken tok,trpgReadBuffer &buf) free (aligned); } else - geom->SetVertices(num,dData); - break; - case TRPG_GEOM_NORM32: - buf.Get(bind); - buf.Get(num); - if (num < 0) throw 1; - buf.GetArray(3*num,&fData); - if (ALIGNMENT_WORKAROUND) + geom->SetVertices(num,dData); + break; + case TRPG_GEOM_NORM32: + buf.Get(bind); + buf.Get(num); + if (num < 0) throw 1; + buf.GetArray(3*num,&fData); + if (ALIGNMENT_WORKAROUND) { float32 *aligned; aligned = (float32 *)calloc (3*num, sizeof(float32)); @@ -705,13 +705,13 @@ void *geomCB::Parse(trpgToken tok,trpgReadBuffer &buf) free (aligned); } else - geom->SetNormals(num,(trpgGeometry::BindType)bind,fData); - break; - case TRPG_GEOM_NORM64: - buf.Get(bind); - buf.Get(num); - if (num < 0) throw 1; - buf.GetArray(3*num,&dData); + geom->SetNormals(num,(trpgGeometry::BindType)bind,fData); + break; + case TRPG_GEOM_NORM64: + buf.Get(bind); + buf.Get(num); + if (num < 0) throw 1; + buf.GetArray(3*num,&dData); if (ALIGNMENT_WORKAROUND) { float64 *aligned; @@ -721,14 +721,14 @@ void *geomCB::Parse(trpgToken tok,trpgReadBuffer &buf) free (aligned); } else - geom->SetNormals(num,(trpgGeometry::BindType)bind,dData); - break; - case TRPG_GEOM_COLOR: - buf.Get(num); - if (num < 0) throw 1; - buf.Get(type); - buf.Get(bind); - buf.GetArray(num,&cData); + geom->SetNormals(num,(trpgGeometry::BindType)bind,dData); + break; + case TRPG_GEOM_COLOR: + buf.Get(num); + if (num < 0) throw 1; + buf.Get(type); + buf.Get(bind); + buf.GetArray(num,&cData); if (ALIGNMENT_WORKAROUND) { trpgColor *aligned; @@ -738,13 +738,13 @@ void *geomCB::Parse(trpgToken tok,trpgReadBuffer &buf) free (aligned); } else - geom->SetColors(num,(trpgGeometry::ColorType)type,(trpgGeometry::BindType)bind,cData); - break; - case TRPG_GEOM_TEX32: - buf.Get(bind); - buf.Get(num); - if (num < 0) throw 1; - buf.GetArray(2*num,&fData); + geom->SetColors(num,(trpgGeometry::ColorType)type,(trpgGeometry::BindType)bind,cData); + break; + case TRPG_GEOM_TEX32: + buf.Get(bind); + buf.Get(num); + if (num < 0) throw 1; + buf.GetArray(2*num,&fData); if (ALIGNMENT_WORKAROUND) { float32 *aligned; @@ -754,13 +754,13 @@ void *geomCB::Parse(trpgToken tok,trpgReadBuffer &buf) free (aligned); } else - geom->SetTexCoords(num,(trpgGeometry::BindType)bind,fData); - break; - case TRPG_GEOM_TEX64: - buf.Get(bind); - buf.Get(num); - if (num < 0) throw 1; - buf.GetArray(2*num,&dData); + geom->SetTexCoords(num,(trpgGeometry::BindType)bind,fData); + break; + case TRPG_GEOM_TEX64: + buf.Get(bind); + buf.Get(num); + if (num < 0) throw 1; + buf.GetArray(2*num,&dData); if (ALIGNMENT_WORKAROUND) { float64 *aligned; @@ -770,44 +770,44 @@ void *geomCB::Parse(trpgToken tok,trpgReadBuffer &buf) free (aligned); } else - geom->SetTexCoords(num,(trpgGeometry::BindType)bind,dData); - break; - case TRPG_GEOM_EFLAG: - buf.Get(num); - if (num < 0) throw 1; - buf.GetArray(num,&charData); - geom->SetEdgeFlags(num,charData); - break; - default: - // Skip - break; - } - } - catch (...) { - return NULL; - } + geom->SetTexCoords(num,(trpgGeometry::BindType)bind,dData); + break; + case TRPG_GEOM_EFLAG: + buf.Get(num); + if (num < 0) throw 1; + buf.GetArray(num,&charData); + geom->SetEdgeFlags(num,charData); + break; + default: + // Skip + break; + } + } + catch (...) { + return NULL; + } - return geom; + return geom; } // Read Geometry bool trpgGeometry::Read(trpgReadBuffer &buf) { - trpgr_Parser parse; - geomCB gcb; + trpgr_Parser parse; + geomCB gcb; - gcb.geom = this; - parse.AddCallback(TRPG_GEOM_PRIM,&gcb,false); - parse.AddCallback(TRPG_GEOM_MATERIAL,&gcb,false); - parse.AddCallback(TRPG_GEOM_VERT32,&gcb,false); - parse.AddCallback(TRPG_GEOM_VERT64,&gcb,false); - parse.AddCallback(TRPG_GEOM_NORM32,&gcb,false); - parse.AddCallback(TRPG_GEOM_NORM64,&gcb,false); - parse.AddCallback(TRPG_GEOM_COLOR,&gcb,false); - parse.AddCallback(TRPG_GEOM_TEX32,&gcb,false); - parse.AddCallback(TRPG_GEOM_TEX64,&gcb,false); - parse.AddCallback(TRPG_GEOM_EFLAG,&gcb,false); - parse.Parse(buf); + gcb.geom = this; + parse.AddCallback(TRPG_GEOM_PRIM,&gcb,false); + parse.AddCallback(TRPG_GEOM_MATERIAL,&gcb,false); + parse.AddCallback(TRPG_GEOM_VERT32,&gcb,false); + parse.AddCallback(TRPG_GEOM_VERT64,&gcb,false); + parse.AddCallback(TRPG_GEOM_NORM32,&gcb,false); + parse.AddCallback(TRPG_GEOM_NORM64,&gcb,false); + parse.AddCallback(TRPG_GEOM_COLOR,&gcb,false); + parse.AddCallback(TRPG_GEOM_TEX32,&gcb,false); + parse.AddCallback(TRPG_GEOM_TEX64,&gcb,false); + parse.AddCallback(TRPG_GEOM_EFLAG,&gcb,false); + parse.Parse(buf); - return isValid(); + return isValid(); } diff --git a/src/osgPlugins/txp/trpage_parse.cpp b/src/osgPlugins/txp/trpage_parse.cpp index ac7d96984..28e67b991 100644 --- a/src/osgPlugins/txp/trpage_parse.cpp +++ b/src/osgPlugins/txp/trpage_parse.cpp @@ -18,62 +18,62 @@ #include /* 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()