ObjImporter: next try for multiple line stuff.

pull/1289/head
Kim Kulling 2017-05-31 16:36:08 +02:00
parent c121cec68a
commit 82380084c5
2 changed files with 26 additions and 5 deletions

View File

@ -96,7 +96,7 @@ public:
/// @brief Will read the next line. /// @brief Will read the next line.
/// @param buffer The buffer for the next line. /// @param buffer The buffer for the next line.
/// @return true if successful. /// @return true if successful.
bool getNextLine( std::vector<T> &buffer ); bool getNextDataLine( std::vector<T> &buffer, T continuationToken );
private: private:
IOStream *m_stream; IOStream *m_stream;
@ -227,15 +227,35 @@ size_t IOStreamBuffer<T>::getFilePos() const {
template<class T> template<class T>
inline inline
bool IOStreamBuffer<T>::getNextLine( std::vector<T> &buffer ) { bool IOStreamBuffer<T>::getNextDataLine( std::vector<T> &buffer, T continuationToken ) {
buffer.resize( m_cacheSize ); buffer.resize( m_cacheSize );
if ( m_cachePos == m_cacheSize || 0 == m_filePos ) { if ( m_cachePos == m_cacheSize || 0 == m_filePos ) {
if ( !readNextBlock() ) { if ( !readNextBlock() ) {
return false; return false;
} }
} }
bool continuationFound( false ), endOfDataLine( false );
size_t i = 0; size_t i = 0;
while ( !IsLineEnd( m_cache[ m_cachePos ] ) ) { while ( !endOfDataLine ) {
if ( continuationToken == m_cache[ m_cachePos ] ) {
continuationFound = true;
}
if ( IsLineEnd( m_cache[ m_cachePos ] ) ) {
if ( !continuationFound ) {
// the end of the data line
i++;
break;
} else {
// skip line end
while ( m_cache[m_cachePos] != '\n') {
++m_cachePos;
}
++m_cachePos;
break;
}
}
buffer[ i ] = m_cache[ m_cachePos ]; buffer[ i ] = m_cache[ m_cachePos ];
m_cachePos++; m_cachePos++;
i++; i++;
@ -245,6 +265,7 @@ bool IOStreamBuffer<T>::getNextLine( std::vector<T> &buffer ) {
} }
} }
} }
buffer[ i ] = '\n'; buffer[ i ] = '\n';
m_cachePos++; m_cachePos++;

View File

@ -123,7 +123,7 @@ void ignoreNewLines(IOStreamBuffer<char> &streamBuffer, std::vector<char> &buffe
std::vector<char> tempBuf; std::vector<char> tempBuf;
do do
{ {
streamBuffer.getNextLine(tempBuf); streamBuffer.getNextDataLine(tempBuf, '\\' );
} while (tempBuf[0]=='\n'); } while (tempBuf[0]=='\n');
*curPosition = ' '; *curPosition = ' ';
std::copy(tempBuf.cbegin(), tempBuf.cend(), ++curPosition); std::copy(tempBuf.cbegin(), tempBuf.cend(), ++curPosition);
@ -142,7 +142,7 @@ void ObjFileParser::parseFile( IOStreamBuffer<char> &streamBuffer ) {
size_t lastFilePos( 0 ); size_t lastFilePos( 0 );
std::vector<char> buffer; std::vector<char> buffer;
while ( streamBuffer.getNextLine( buffer ) ) { while ( streamBuffer.getNextDataLine( buffer, '\\' ) ) {
m_DataIt = buffer.begin(); m_DataIt = buffer.begin();
m_DataItEnd = buffer.end(); m_DataItEnd = buffer.end();