#include <assimp/IOStream.hpp>
#include "ParsingUtils.h"
+#include <vector>
+
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 );
/// @return true if successful.
bool close();
- /// @brief Returns the filesize.
- /// @return The filesize.
+ /// @brief Returns the file-size.
+ /// @return The file-size.
size_t size() const;
/// @brief Returns the cache size.
/// @brief Will read the next line.
/// @param buffer The buffer for the next line.
/// @return true if successful.
- bool getNextLine( std::vector<T> &buffer );
+ bool getNextLine( CacheIter &begin, CacheIter &end );
private:
IOStream *m_stream;
size_t m_blockIdx;
std::vector<T> m_cache;
size_t m_cachePos;
+ CacheIter m_it;
size_t m_filePos;
};
, 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' );
m_filePos += m_cacheSize;
m_cachePos = 0;
m_blockIdx++;
+ m_it = m_cache.begin();
return true;
}
template<class T>
inline
-bool IOStreamBuffer<T>::getNextLine( std::vector<T> &buffer ) {
- buffer.resize( m_cacheSize );
+bool IOStreamBuffer<T>::getNextLine( CacheIter &begin, CacheIter &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;
+
+ //size_t i = 0;
+ begin = m_it;
while ( !IsLineEnd( m_cache[ m_cachePos ] ) ) {
- buffer[ i ] = m_cache[ m_cachePos ];
m_cachePos++;
- i++;
+ ++m_it;
+ //i++;
if ( m_cachePos >= m_cacheSize ) {
if ( !readNextBlock() ) {
+ begin = m_it;
+ end = m_it;
return false;
}
}
}
- buffer[ i ] = '\n';
+ ++m_it;
+ end = m_it;
m_cachePos++;
return true;
return m_pModel;
}
-void ignoreNewLines(IOStreamBuffer<char> &streamBuffer, std::vector<char> &buffer)
+/*void ignoreNewLines(IOStreamBuffer<char> &streamBuffer, std::vector<char> &buffer)
{
auto curPosition = buffer.begin();
do
std::copy(tempBuf.cbegin(), tempBuf.cend(), ++curPosition);
}
} while (*curPosition!='\n');
-}
+}*/
void ObjFileParser::parseFile( IOStreamBuffer<char> &streamBuffer ) {
// only update every 100KB or it'll be too slow
unsigned int processed = 0;
size_t lastFilePos( 0 );
- std::vector<char> buffer;
- while ( streamBuffer.getNextLine( buffer ) ) {
- m_DataIt = buffer.begin();
- m_DataItEnd = buffer.end();
-
+ while ( streamBuffer.getNextLine( m_DataIt, m_DataItEnd ) ) {
// Handle progress reporting
const size_t filePos( streamBuffer.getFilePos() );
if ( lastFilePos < filePos ) {
default:
{
pf_skip_line:
-
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
}
break;
// -------------------------------------------------------------------
// Get a comment, values will be skipped
void ObjFileParser::getComment() {
- while (m_DataIt != m_DataItEnd) {
+ m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
+
+/* while (m_DataIt != m_DataItEnd) {
if ( '\n' == (*m_DataIt)) {
++m_DataIt;
break;
} else {
++m_DataIt;
}
- }
+ }*/
}
// -------------------------------------------------------------------
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 )
{
++uiLine;
}
// fix .. from time to time there are spaces at the beginning of a material line
- while ( it != end && (*it == '\t' || *it == ' ') )
+ while ( it != end && ( *it == '\t' || *it == ' ' ) ) {
++it;
+ }
+
return it;
}