From Joakim Simmonson,

"Opcodes.h:
* Added INVALID_OP as -1 in the Opcodes enum. Note that INVALID_OP is not an actual opcode defined in the OpenFlight format. The purpose of INVALID_OP is to mark an opcode variable as invalid or uninitialized.

ReaderWriterFLT.cpp:
* The header node is returned if it exists, even if the file does not contain a node hierarchy. The old behaviour returned a ERROR_IN_READING_FILE error.
* Changed opcodes initialized to -1 to the new enum value INVALID_OP."
This commit is contained in:
Robert Osfield 2008-07-11 17:46:30 +00:00
parent 1489eeb228
commit ef1ee63f03
2 changed files with 21 additions and 4 deletions

View File

@ -22,8 +22,12 @@
namespace flt { namespace flt {
// Note that INVALID_OP = -1 is not an actual opcode defined in the OpenFlight format.
// The purpose of INVALID_OP is to mark an opcode variable as invalid or uninitialized.
enum Opcodes enum Opcodes
{ {
INVALID_OP = -1,
UNKNOWN_OP = 0, UNKNOWN_OP = 0,
HEADER_OP = 1, HEADER_OP = 1,
GROUP_OP = 2, GROUP_OP = 2,

View File

@ -86,7 +86,7 @@ public:
/*! /*!
FLTReaderWriter supports importing and exporting OSG scene grqphs FLTReaderWriter supports importing and exporting OSG scene graphs
from/to OpenFlight files. from/to OpenFlight files.
<table> <table>
@ -284,7 +284,7 @@ class FLTReaderWriter : public ReaderWriter
} }
const int RECORD_HEADER_SIZE = 4; const int RECORD_HEADER_SIZE = 4;
opcode_type continuationOpcode = -1; opcode_type continuationOpcode = INVALID_OP;
std::string continuationBuffer; std::string continuationBuffer;
while (fin.good() && !document.done()) while (fin.good() && !document.done())
@ -299,8 +299,21 @@ class FLTReaderWriter : public ReaderWriter
opcode_type opcode = (opcode_type)dataStream.readUInt16(); opcode_type opcode = (opcode_type)dataStream.readUInt16();
size_type size = (size_type)dataStream.readUInt16(); size_type size = (size_type)dataStream.readUInt16();
// If size == 0, an EOF has probably been reached, i.e. there is nothing
// more to read so we must return.
if (size==0) if (size==0)
{
// If a header was read, we return it.
// This allows us handle files with empty hierarchies.
if (document.getHeaderNode())
{
return document.getHeaderNode();
}
else // (no valid header)
{
return ReadResult::ERROR_IN_READING_FILE; return ReadResult::ERROR_IN_READING_FILE;
}
}
// variable length record complete? // variable length record complete?
if (!continuationBuffer.empty() && opcode!=CONTINUATION_OP) if (!continuationBuffer.empty() && opcode!=CONTINUATION_OP)
@ -310,7 +323,7 @@ class FLTReaderWriter : public ReaderWriter
flt::RecordInputStream recordStream(&sb); flt::RecordInputStream recordStream(&sb);
recordStream.readRecordBody(continuationOpcode, continuationBuffer.length(), document); recordStream.readRecordBody(continuationOpcode, continuationBuffer.length(), document);
continuationOpcode = -1; continuationOpcode = INVALID_OP;
continuationBuffer.clear(); continuationBuffer.clear();
} }