namespace Assimp {
+// ---------------------------------------------------------------------------
+/**
+ * Implementation of a cached stream buffer.
+ */
template<class T>
class IOStreamBuffer {
public:
+ /// @brief The class constructor.
IOStreamBuffer( size_t cache = 4096 * 4096 );
+
+ /// @brief The class destructor.
~IOStreamBuffer();
+
+ /// @brief Will open the cached access for a given stream.
+ /// @param stream The stream to cache.
+ /// @return true if successful.
bool open( IOStream *stream );
+
+ /// @brief Will close the cached access.
+ /// @return true if successful.
bool close();
+
+ /// @brief Returns the filesize.
+ /// @return The filesize.
size_t size() const;
+
+ /// @brief Returns the cache size.
+ /// @return The cache size.
+ size_t cacheSize() const;
+
+ /// @brief Will read the next block.
+ /// @return true if successful.
bool readNextBlock();
+
+ /// @brief Will read the next line.
+ /// @param buffer The buffer for the next line.
+ /// @return true if successful.
bool getNextLine( std::vector<T> &buffer );
private:
template<class T>
inline
-IOStreamBuffer<T>::IOStreamBuffer( size_t cache = 4096 * 4096 )
- : m_stream( nullptr )
- , m_filesize( 0 )
- , m_cacheSize( cache )
- , m_cachePos( 0 )
- , m_filePos( 0 ) {
+IOStreamBuffer<T>::IOStreamBuffer( size_t cache )
+: m_stream( nullptr )
+, m_filesize( 0 )
+, m_cacheSize( cache )
+, m_cachePos( 0 )
+, m_filePos( 0 ) {
m_cache.resize( cache );
- std::fill( m_cache.begin(), m_cache.end(), '\0' );
+ std::fill( m_cache.begin(), m_cache.end(), '\n' );
}
template<class T>
template<class T>
inline
bool IOStreamBuffer<T>::open( IOStream *stream ) {
+ if ( nullptr != m_stream ) {
+ return false;
+ }
+
if ( nullptr == stream ) {
return false;
}
template<class T>
inline
+size_t IOStreamBuffer<T>::cacheSize() const {
+ return m_cacheSize;
+}
+
+template<class T>
+inline
bool IOStreamBuffer<T>::readNextBlock() {
m_stream->Seek( m_filePos, aiOrigin_SET );
size_t readLen = m_stream->Read( &m_cache[ 0 ], sizeof( T ), m_cacheSize );
unit/utImporter.cpp
unit/utImproveCacheLocality.cpp
unit/utIOSystem.cpp
+ unit/utIOStreamBuffer.cpp
unit/utIssues.cpp
unit/utJoinVertices.cpp
unit/utLimitBoneWeights.cpp
--- /dev/null
+#pragma once
+
+#include "DefaultIOStream.h"
+
+using namespace ::Assimp;
+
+class TestDefaultIOStream : public DefaultIOStream {
+public:
+ TestDefaultIOStream()
+ : DefaultIOStream() {
+ // empty
+ }
+
+ TestDefaultIOStream( FILE* pFile, const std::string &strFilename )
+ : DefaultIOStream( pFile, strFilename ) {
+ // empty
+ }
+
+ virtual ~TestDefaultIOStream() {
+ // empty
+ }
+};
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-------------------------------------------------------------------------*/
#include <gtest/gtest.h>
-#include "DefaultIOStream.h"
+#include "TestIOStream.h"
using namespace ::Assimp;
// empty
};
-class TestDefaultIOStream : public DefaultIOStream {
-public:
- TestDefaultIOStream()
- : DefaultIOStream() {
- // empty
- }
-
- TestDefaultIOStream( FILE* pFile, const std::string &strFilename )
- : DefaultIOStream( pFile, strFilename ) {
- // empty
- }
-
- virtual ~TestDefaultIOStream() {
- // empty
- }
-};
-
TEST_F( utDefaultIOStream, FileSizeTest ) {
char buffer[ L_tmpnam ];
tmpnam( buffer );
#include "UnitTestPCH.h"
#include "IOStreamBuffer.h"
+#include "TestIOStream.h"
class IOStreamBufferTest : public ::testing::Test {
// empty
EXPECT_TRUE( ok );
}
+TEST_F( IOStreamBufferTest, accessCacheSizeTest ) {
+ IOStreamBuffer<char> myBuffer1;
+ EXPECT_NE( 0, myBuffer1.cacheSize() );
+
+ IOStreamBuffer<char> myBuffer2( 100 );
+ EXPECT_EQ( 100, myBuffer2.cacheSize() );
+}
+
+TEST_F( IOStreamBufferTest, open_close_Test ) {
+ IOStreamBuffer<char> myBuffer;
+
+ EXPECT_FALSE( myBuffer.open( nullptr ) );
+ EXPECT_FALSE( myBuffer.close() );
+
+ 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 );
+
+ TestDefaultIOStream myStream( fs, buffer );
+
+ EXPECT_TRUE( myBuffer.open( &myStream ) );
+ EXPECT_FALSE( myBuffer.open( &myStream ) );
+ EXPECT_TRUE( myBuffer.close() );
+}
+
TEST_F( IOStreamBufferTest, readlineTest ) {
}
\ No newline at end of file