Merge branch 'obj_with_linebreaks' of https://github.com/assimp/assimp into obj_with_linebreaks

pull/1289/head
Kim Kulling 2017-05-31 20:18:39 +02:00
commit e501cc17c2
3 changed files with 37 additions and 26 deletions

View File

@ -56,8 +56,6 @@ namespace Assimp {
template<class T> template<class T>
class IOStreamBuffer { class IOStreamBuffer {
public: public:
typedef typename std::vector<T>::iterator CacheIter;
/// @brief The class constructor. /// @brief The class constructor.
IOStreamBuffer( size_t cache = 4096 * 4096 ); IOStreamBuffer( size_t cache = 4096 * 4096 );
@ -100,7 +98,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( CacheIter &begin, CacheIter &end ); bool getNextDataLine( std::vector<T> &buffer, T continuationToken );
private: private:
IOStream *m_stream; IOStream *m_stream;
@ -110,7 +108,6 @@ private:
size_t m_blockIdx; size_t m_blockIdx;
std::vector<T> m_cache; std::vector<T> m_cache;
size_t m_cachePos; size_t m_cachePos;
CacheIter m_it;
size_t m_filePos; size_t m_filePos;
}; };
@ -123,7 +120,6 @@ IOStreamBuffer<T>::IOStreamBuffer( size_t cache )
, m_numBlocks( 0 ) , m_numBlocks( 0 )
, m_blockIdx( 0 ) , m_blockIdx( 0 )
, m_cachePos( 0 ) , m_cachePos( 0 )
, m_it()
, m_filePos( 0 ) { , m_filePos( 0 ) {
m_cache.resize( cache ); m_cache.resize( cache );
std::fill( m_cache.begin(), m_cache.end(), '\n' ); std::fill( m_cache.begin(), m_cache.end(), '\n' );
@ -209,7 +205,6 @@ bool IOStreamBuffer<T>::readNextBlock() {
m_filePos += m_cacheSize; m_filePos += m_cacheSize;
m_cachePos = 0; m_cachePos = 0;
m_blockIdx++; m_blockIdx++;
m_it = m_cache.begin();
return true; return true;
} }
@ -234,32 +229,47 @@ size_t IOStreamBuffer<T>::getFilePos() const {
template<class T> template<class T>
inline inline
bool IOStreamBuffer<T>::getNextLine( CacheIter &begin, CacheIter &end ) { bool IOStreamBuffer<T>::getNextDataLine( std::vector<T> &buffer, T continuationToken ) {
buffer.resize( m_cacheSize );
//std::fill( buffer.begin(), buffer.end(), ' ' );
if ( m_cachePos == m_cacheSize || 0 == m_filePos ) { if ( m_cachePos == m_cacheSize || 0 == m_filePos ) {
if ( !readNextBlock() ) { if ( !readNextBlock() ) {
begin = m_it;
end = m_it;
return false; return false;
} }
m_it = m_cache.begin();
} }
//size_t i = 0; bool continuationFound( false ), endOfDataLine( false );
begin = m_it; size_t i = 0;
while ( !IsLineEnd( m_cache[ m_cachePos ] ) ) { while ( !endOfDataLine ) {
if ( continuationToken == m_cache[ m_cachePos ] ) {
continuationFound = true;
++m_cachePos;
}
if ( IsLineEnd( m_cache[ m_cachePos ] ) ) {
if ( !continuationFound ) {
// the end of the data line
break;
} else {
// skip line end
while ( m_cache[m_cachePos] != '\n') {
++m_cachePos;
}
++m_cachePos;
continuationFound = false;
}
}
buffer[ i ] = m_cache[ m_cachePos ];
m_cachePos++; m_cachePos++;
++m_it; i++;
//i++;
if ( m_cachePos >= m_cacheSize ) { if ( m_cachePos >= m_cacheSize ) {
if ( !readNextBlock() ) { if ( !readNextBlock() ) {
begin = m_it;
end = m_it;
return false; return false;
} }
} }
} }
++m_it;
end = m_it; buffer[ i ] = '\n';
m_cachePos++; m_cachePos++;
return true; return true;

View File

@ -123,7 +123,7 @@ ObjFile::Model *ObjFileParser::GetModel() const {
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);
@ -141,7 +141,11 @@ void ObjFileParser::parseFile( IOStreamBuffer<char> &streamBuffer ) {
unsigned int processed = 0; unsigned int processed = 0;
size_t lastFilePos( 0 ); size_t lastFilePos( 0 );
while ( streamBuffer.getNextLine( m_DataIt, m_DataItEnd ) ) { std::vector<char> buffer;
while ( streamBuffer.getNextDataLine( buffer, '\\' ) ) {
m_DataIt = buffer.begin();
m_DataItEnd = buffer.end();
// Handle progress reporting // Handle progress reporting
const size_t filePos( streamBuffer.getFilePos() ); const size_t filePos( streamBuffer.getFilePos() );
if ( lastFilePos < filePos ) { if ( lastFilePos < filePos ) {

View File

@ -115,12 +115,9 @@ template<class char_t>
inline char_t skipLine( char_t it, char_t end, unsigned int &uiLine ) { inline char_t skipLine( char_t it, char_t end, unsigned int &uiLine ) {
while( !isEndOfBuffer( it, end ) && !IsLineEnd( *it ) ) { while( !isEndOfBuffer( it, end ) && !IsLineEnd( *it ) ) {
++it; ++it;
if ( *it == '\n' ) {
++it;
}
} }
if ( it != end )
{ if ( it != end ) {
++it; ++it;
++uiLine; ++uiLine;
} }