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
49
50
51
52
53
54
55
56
// *****************************************************************************
/*!
  \file      src/Base/Reader.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     Reader base class declaration
  \details   Reader base class declaration. Reader base serves as a base class
    for various file readers. It does generic low-level I/O, e.g., opening and
    closing a file, and associated error handling.
*/
// *****************************************************************************
#ifndef Reader_h
#define Reader_h

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

namespace tk {

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

  public:
    //! Constructor: Acquire file handle
    explicit Reader( const std::string& filename,
                     std::ios_base::openmode mode = std::ifstream::in );

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

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

    //! Return first line (for detection of file type based on header)
    std::string firstline();

    //! Read a given line from file
    std::string line( std::size_t lineNum );

  protected:
    const std::string m_filename;            //!< File name
    std::ifstream m_inFile;                  //!< File input stream
};

} // tk::

#endif // Reader_h