1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// *****************************************************************************
/*!
  \file      src/Base/Writer.hpp
  \copyright 2012-2015 J. Bakosi,
             2016-2018 Los Alamos National Security, LLC.,
             2019-2021 Triad National Security, LLC.,
             2022-2025 J. Bakosi
             All rights reserved. See the LICENSE file for details.
  \brief     Writer base class declaration
  \details   Writer base class declaration. Writer base serves as a base class
    for various file writers. It does generic low-level I/O, e.g., opening and
    closing a file, and associated error handling.
*/
// *****************************************************************************
#pragma once

#include <fstream><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

namespace tk {

//! Writer base serves as a base class for various file writers. It does generic
//! low-level I/O, e.g., opening and closing a file, and associated error
//! handling.
class Writer {

  public:
    //! Constructor: Acquire file handle. Protected: designed to be base only.
    explicit Writer( const std::string& filename,
                     std::ios_base::openmode mode = std::ios_base::out );

    //! Destructor: Release file handle
    virtual ~Writer() noexcept;

    //! Unformatted write
    //! \param[in] data Buffer to write
    //! \param[in] count Number of characters to write
    void write( const char* data, std::streamsize count )
    { m_outFile.write( data, count ); }

    //! Write access to underlying output file stream
    std::ofstream& stream() { return m_outFile; }

  protected:
    const std::string m_filename;          //!< File name
    mutable std::ofstream m_outFile;       //!< File output stream
};

} // tk::