#include <assimp/types.h>
#include <assimp/IOStream.hpp>
+#include "ParsingUtils.h"
#include <iostream>
/// @return true if successful.
bool readNextBlock();
+ /// @brief Returns the number of blocks to read.
+ /// @return The number of blocks.
+ size_t getNumBlocks() const;
+
+ /// @brief Returns the current block index.
+ /// @return The current block index.
+ size_t getCurrentBlockIndex() const;
+
+ /// @brief Returns the current file pos.
+ /// @return The current file pos.
+ size_t getFilePos() const;
+
/// @brief Will read the next line.
/// @param buffer The buffer for the next line.
/// @return true if successful.
IOStream *m_stream;
size_t m_filesize;
size_t m_cacheSize;
+ size_t m_numBlocks;
+ size_t m_blockIdx;
std::vector<T> m_cache;
size_t m_cachePos;
size_t m_filePos;
: m_stream( nullptr )
, m_filesize( 0 )
, m_cacheSize( cache )
+, m_numBlocks( 0 )
+, m_blockIdx( 0 )
, m_cachePos( 0 )
, m_filePos( 0 ) {
m_cache.resize( cache );
template<class T>
inline
bool IOStreamBuffer<T>::open( IOStream *stream ) {
+ // file still opened!
if ( nullptr != m_stream ) {
return false;
}
+ // Invalid stream pointer
if ( nullptr == stream ) {
return false;
}
m_cacheSize = m_filesize;
}
+ m_numBlocks = m_filesize / m_cacheSize;
+ if ( ( m_filesize % m_cacheSize ) > 0 ) {
+ m_numBlocks++;
+ }
+
return true;
}
return false;
}
- m_stream = nullptr;
- m_filesize = 0;
+ // init counters and state vars
+ m_stream = nullptr;
+ m_filesize = 0;
+ m_numBlocks = 0;
+ m_blockIdx = 0;
+ m_cachePos = 0;
+ m_filePos = 0;
return true;
}
}
m_filePos += m_cacheSize;
m_cachePos = 0;
+ m_blockIdx++;
return true;
}
template<class T>
inline
+size_t IOStreamBuffer<T>::getNumBlocks() const {
+ return m_numBlocks;
+}
+
+template<class T>
+inline
+size_t IOStreamBuffer<T>::getCurrentBlockIndex() const {
+ return m_blockIdx;
+}
+
+template<class T>
+inline
+size_t IOStreamBuffer<T>::getFilePos() const {
+ return m_filePos;
+}
+
+template<class T>
+inline
bool IOStreamBuffer<T>::getNextLine( std::vector<T> &buffer ) {
buffer.resize( m_cacheSize );
::memset( &buffer[ 0 ], '\n', m_cacheSize );
const unsigned int progressTotal = 3 * bytesToProcess;
const unsigned int progressOffset = bytesToProcess;
unsigned int processed = 0;
-
- //DataArrayIt lastDataIt = m_DataIt;
+ size_t lastFilePos( 0 );
bool endOfFile( false );
std::vector<char> buffer;
m_DataIt = buffer.begin();
m_DataItEnd = buffer.end();
- // Handle progress reporting
- /*processed += std::distance(lastDataIt, m_DataIt);
- lastDataIt = m_DataIt;
- if (processed > (progressCounter * updateProgressEveryBytes))
- {
+ // Handle progress reporting
+ const size_t filePos( streamBuffer.getFilePos() );
+ if ( lastFilePos < filePos ) {
+ processed += filePos;
+ lastFilePos = filePos;
progressCounter++;
- m_progress->UpdateFileRead(progressOffset + processed*2, progressTotal);
- }*/
+ m_progress->UpdateFileRead( progressOffset + processed * 2, progressTotal );
+ }
// parse line
switch (*m_DataIt)
}
TEST_F( IOStreamBufferTest, readlineTest ) {
+ char buffer[ L_tmpnam ];
+ tmpnam( buffer );
+ std::FILE *fs( std::fopen( buffer, "w+" ) );
+ size_t written( std::fwrite( buffer, 1, sizeof( char ) * L_tmpnam, fs ) );
+ std::fflush( fs );
+
+ IOStreamBuffer<char> myBuffer( 26 );
+ EXPECT_EQ( 26, myBuffer.cacheSize() );
+
+ TestDefaultIOStream myStream( fs, buffer );
-}
\ No newline at end of file
+ EXPECT_TRUE( myBuffer.open( &myStream ) );
+
+ EXPECT_EQ( 10, myBuffer.getNumBlocks() );
+ EXPECT_TRUE( myBuffer.close() );
+}
+
+TEST_F( IOStreamBufferTest, accessBlockIndexTest ) {
+
+}