assimp/code/FileLogStream.h

66 lines
1.7 KiB
C
Raw Normal View History

#ifndef ASSIMP_FILELOGSTREAM_H_INC
#define ASSIMP_FILELOGSTREAM_H_INC
#include "../include/assimp/LogStream.hpp"
#include "../include/assimp/IOStream.hpp"
#include "DefaultIOSystem.h"
2015-05-19 03:57:13 +00:00
namespace Assimp {
// ----------------------------------------------------------------------------------
2015-05-19 03:57:13 +00:00
/** @class FileLogStream
* @brief Logstream to write into a file.
*/
class FileLogStream :
2015-05-19 03:57:13 +00:00
public LogStream
{
public:
2015-05-19 03:57:13 +00:00
FileLogStream( const char* file, IOSystem* io = NULL );
~FileLogStream();
void write( const char* message );
private:
2015-05-19 03:57:13 +00:00
IOStream *m_pStream;
};
// ----------------------------------------------------------------------------------
2015-05-19 03:57:13 +00:00
// Constructor
inline FileLogStream::FileLogStream( const char* file, IOSystem* io ) :
2015-05-19 03:57:13 +00:00
m_pStream(NULL)
{
2015-05-19 03:57:13 +00:00
if ( !file || 0 == *file )
return;
2015-05-19 03:57:13 +00:00
// If no IOSystem is specified: take a default one
if (!io)
{
DefaultIOSystem FileSystem;
m_pStream = FileSystem.Open( file, "wt");
}
else m_pStream = io->Open( file, "wt" );
}
// ----------------------------------------------------------------------------------
2015-05-19 03:57:13 +00:00
// Destructor
inline FileLogStream::~FileLogStream()
{
2015-05-19 03:57:13 +00:00
// The virtual d'tor should destroy the underlying file
delete m_pStream;
}
// ----------------------------------------------------------------------------------
2015-05-19 03:57:13 +00:00
// Write method
inline void FileLogStream::write( const char* message )
{
2015-05-19 03:57:13 +00:00
if (m_pStream != NULL)
{
m_pStream->Write(message, sizeof(char), ::strlen(message));
m_pStream->Flush();
}
}
// ----------------------------------------------------------------------------------
} // !Namespace Assimp
#endif // !! ASSIMP_FILELOGSTREAM_H_INC