FileLogStream.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #ifndef ASSIMP_FILELOGSTREAM_H_INC
  2. #define ASSIMP_FILELOGSTREAM_H_INC
  3. #include "../include/LogStream.h"
  4. #include "../include/IOStream.h"
  5. namespace Assimp {
  6. // ----------------------------------------------------------------------------------
  7. /** @class FileLogStream
  8. * @brief Logstream to write into a file.
  9. */
  10. class FileLogStream :
  11. public LogStream
  12. {
  13. public:
  14. FileLogStream( const std::string &strFileName, IOSystem* io = NULL );
  15. ~FileLogStream();
  16. void write( const std::string &message );
  17. private:
  18. IOStream *m_pStream;
  19. };
  20. // ----------------------------------------------------------------------------------
  21. // Constructor
  22. inline FileLogStream::FileLogStream( const std::string &strFileName, IOSystem* io ) :
  23. m_pStream(NULL)
  24. {
  25. if ( strFileName.empty() )
  26. return;
  27. const static std::string mode = "wt";
  28. // If no IOSystem is specified: take a default one
  29. if (!io)
  30. {
  31. DefaultIOSystem FileSystem;
  32. m_pStream = FileSystem.Open( strFileName, mode );
  33. }
  34. else m_pStream = io->Open( strFileName, mode );
  35. }
  36. // ----------------------------------------------------------------------------------
  37. // Destructor
  38. inline FileLogStream::~FileLogStream()
  39. {
  40. // The virtual d'tor should destroy the underlying file
  41. delete m_pStream;
  42. }
  43. // ----------------------------------------------------------------------------------
  44. // Write method
  45. inline void FileLogStream::write( const std::string &message )
  46. {
  47. if (m_pStream != NULL)
  48. {
  49. m_pStream->Write(message.c_str(), sizeof(char), message.size());
  50. m_pStream->Flush();
  51. }
  52. }
  53. // ----------------------------------------------------------------------------------
  54. } // !Namespace Assimp
  55. #endif // !! ASSIMP_FILELOGSTREAM_H_INC