Coverage Report

Created: 2025-08-28 06:20

/src/aspell/common/fstream.hpp
Line
Count
Source (jump to first uncovered line)
1
// This file is part of The New Aspell
2
// Copyright (C) 2001 by Kevin Atkinson under the GNU LGPL license
3
// version 2.0 or 2.1.  You should have received a copy of the LGPL
4
// license along with this library if you did not you can find
5
// it at http://www.gnu.org/.
6
7
#ifndef ASPELL_FSTREAM__HPP
8
#define ASPELL_FSTREAM__HPP
9
10
#include <stdio.h>
11
12
#include "string.hpp"
13
#include "istream.hpp"
14
#include "ostream.hpp"
15
#include "posib_err.hpp"
16
17
// NOTE: See iostream.hpp for the standard stream (ie standard input,
18
//       output, error)
19
20
namespace acommon {
21
  class String;
22
23
  class FStream : public IStream, public OStream
24
  {
25
  private:
26
    FILE * file_;
27
    bool   own_;
28
29
  public:
30
    FStream(char d = '\n') 
31
23.1k
      : IStream(d), file_(0), own_(true) {}
32
    FStream(FILE * f, bool own = true) 
33
6
      : IStream('\n'), file_(f), own_(own) {}
34
23.1k
    ~FStream() {close();}
35
36
    PosibErr<void> open(ParmStr, const char *);
37
    void close();
38
 
39
24.2k
    operator bool() {return file_ != 0 && !feof(file_) && !ferror(file_);}
40
41
0
    int get() {return getc(file_);}
42
0
    void ignore() {getc(file_);}
43
0
    int peek() {int c = getc(file_); ungetc(c, file_); return c;}
44
45
    FILE * c_stream();
46
    int file_no();
47
    
48
    int vprintf(const char * format, va_list ap)
49
0
    {
50
0
      return vfprintf(file_, format, ap);
51
0
    }
52
53
3.12k
    void flush() {fflush(file_);}
54
55
    // flushes the stream and goes to the beginning of the file
56
    void restart();
57
58
    void skipws();
59
60
    // Will return false if there is no more data
61
    bool append_line(String &, char d);
62
63
    // These perform raw io with any sort of formatting
64
    bool read(void *, unsigned int i);
65
    void write(ParmStr);
66
    void write(char c);
67
    void write(const void *, unsigned int i);
68
69
0
    long int tell() {return ftell(file_);}
70
0
    bool seek(long int offset, int whence = SEEK_SET) {
71
0
      return fseek(file_, offset, whence) == 0;
72
0
    }
73
    
74
75
    // The << >> operators are designed to work about they same
76
    // as they would with A C++ stream.
77
    FStream & operator>> (char & c)
78
0
    {
79
0
      skipws();
80
0
      c = getc(file_);
81
0
      return *this;
82
0
    }
83
    
84
    FStream & operator<< (char c)
85
0
    {
86
0
      putc(c, file_);
87
0
      return *this;
88
0
    }
89
90
    FStream & operator>> (String &);
91
    FStream & operator>> (unsigned int &);
92
    FStream & operator>> (int &);
93
    FStream & operator<< (ParmStr);
94
    FStream & operator<< (unsigned long);
95
    FStream & operator<< (unsigned int);
96
    FStream & operator<< (int);
97
    FStream & operator<< (double);
98
99
  };
100
}
101
102
#endif