Branch data Line data Source code
1 : : // ***************************************************************************** 2 : : /*! 3 : : \file src/Base/Writer.hpp 4 : : \copyright 2012-2015 J. Bakosi, 5 : : 2016-2018 Los Alamos National Security, LLC., 6 : : 2019-2021 Triad National Security, LLC. 7 : : All rights reserved. See the LICENSE file for details. 8 : : \brief Writer base class declaration 9 : : \details Writer base class declaration. Writer base serves as a base class 10 : : for various file writers. It does generic low-level I/O, e.g., opening and 11 : : closing a file, and associated error handling. 12 : : */ 13 : : // ***************************************************************************** 14 : : #ifndef Writer_h 15 : : #define Writer_h 16 : : 17 : : #include <fstream> 18 : : 19 : : namespace tk { 20 : : 21 : : //! Writer base serves as a base class for various file writers. It does generic 22 : : //! low-level I/O, e.g., opening and closing a file, and associated error 23 : : //! handling. 24 : : class Writer { 25 : : 26 : : public: 27 : : //! Constructor: Acquire file handle. Protected: designed to be base only. 28 : : explicit Writer( const std::string& filename, 29 : : std::ios_base::openmode mode = std::ios_base::out ); 30 : : 31 : : //! Destructor: Release file handle 32 : : virtual ~Writer() noexcept; 33 : : 34 : : //! Unformatted write 35 : : //! \param[in] data Buffer to write 36 : : //! \param[in] count Number of characters to write 37 : : void write( const char* data, std::streamsize count ) 38 : : { m_outFile.write( data, count ); } 39 : : 40 : : //! Write access to underlying output file stream 41 : 189 : std::ofstream& stream() { return m_outFile; } 42 : : 43 : : protected: 44 : : const std::string m_filename; //!< File name 45 : : mutable std::ofstream m_outFile; //!< File output stream 46 : : }; 47 : : 48 : : } // tk:: 49 : : 50 : : #endif // Writer_h