Merge branch 'obj_with_linebreaks' of https://github.com/assimp/assimp into obj_with_linebreaks
commit
e501cc17c2
|
@ -56,8 +56,6 @@ namespace Assimp {
|
|||
template<class T>
|
||||
class IOStreamBuffer {
|
||||
public:
|
||||
typedef typename std::vector<T>::iterator CacheIter;
|
||||
|
||||
/// @brief The class constructor.
|
||||
IOStreamBuffer( size_t cache = 4096 * 4096 );
|
||||
|
||||
|
@ -100,7 +98,7 @@ public:
|
|||
/// @brief Will read the next line.
|
||||
/// @param buffer The buffer for the next line.
|
||||
/// @return true if successful.
|
||||
bool getNextLine( CacheIter &begin, CacheIter &end );
|
||||
bool getNextDataLine( std::vector<T> &buffer, T continuationToken );
|
||||
|
||||
private:
|
||||
IOStream *m_stream;
|
||||
|
@ -110,7 +108,6 @@ private:
|
|||
size_t m_blockIdx;
|
||||
std::vector<T> m_cache;
|
||||
size_t m_cachePos;
|
||||
CacheIter m_it;
|
||||
size_t m_filePos;
|
||||
};
|
||||
|
||||
|
@ -123,7 +120,6 @@ IOStreamBuffer<T>::IOStreamBuffer( size_t cache )
|
|||
, m_numBlocks( 0 )
|
||||
, m_blockIdx( 0 )
|
||||
, m_cachePos( 0 )
|
||||
, m_it()
|
||||
, m_filePos( 0 ) {
|
||||
m_cache.resize( cache );
|
||||
std::fill( m_cache.begin(), m_cache.end(), '\n' );
|
||||
|
@ -209,7 +205,6 @@ bool IOStreamBuffer<T>::readNextBlock() {
|
|||
m_filePos += m_cacheSize;
|
||||
m_cachePos = 0;
|
||||
m_blockIdx++;
|
||||
m_it = m_cache.begin();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -234,32 +229,47 @@ size_t IOStreamBuffer<T>::getFilePos() const {
|
|||
|
||||
template<class T>
|
||||
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 ( !readNextBlock() ) {
|
||||
begin = m_it;
|
||||
end = m_it;
|
||||
return false;
|
||||
}
|
||||
m_it = m_cache.begin();
|
||||
}
|
||||
|
||||
//size_t i = 0;
|
||||
begin = m_it;
|
||||
while ( !IsLineEnd( m_cache[ m_cachePos ] ) ) {
|
||||
bool continuationFound( false ), endOfDataLine( false );
|
||||
size_t i = 0;
|
||||
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_it;
|
||||
//i++;
|
||||
i++;
|
||||
if ( m_cachePos >= m_cacheSize ) {
|
||||
if ( !readNextBlock() ) {
|
||||
begin = m_it;
|
||||
end = m_it;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
++m_it;
|
||||
end = m_it;
|
||||
|
||||
buffer[ i ] = '\n';
|
||||
m_cachePos++;
|
||||
|
||||
return true;
|
||||
|
|
|
@ -123,7 +123,7 @@ ObjFile::Model *ObjFileParser::GetModel() const {
|
|||
std::vector<char> tempBuf;
|
||||
do
|
||||
{
|
||||
streamBuffer.getNextLine(tempBuf);
|
||||
streamBuffer.getNextDataLine(tempBuf, '\\' );
|
||||
} while (tempBuf[0]=='\n');
|
||||
*curPosition = ' ';
|
||||
std::copy(tempBuf.cbegin(), tempBuf.cend(), ++curPosition);
|
||||
|
@ -141,7 +141,11 @@ void ObjFileParser::parseFile( IOStreamBuffer<char> &streamBuffer ) {
|
|||
unsigned int processed = 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
|
||||
const size_t filePos( streamBuffer.getFilePos() );
|
||||
if ( lastFilePos < filePos ) {
|
||||
|
|
|
@ -115,12 +115,9 @@ template<class char_t>
|
|||
inline char_t skipLine( char_t it, char_t end, unsigned int &uiLine ) {
|
||||
while( !isEndOfBuffer( it, end ) && !IsLineEnd( *it ) ) {
|
||||
++it;
|
||||
if ( *it == '\n' ) {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
if ( it != end )
|
||||
{
|
||||
|
||||
if ( it != end ) {
|
||||
++it;
|
||||
++uiLine;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue