summaryrefslogtreecommitdiff
path: root/reference/C/CONTRIB/SNIP/mystream.h
blob: 2c2a909d39b89afaa5f89b0d27a9b8ce0a152760 (plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Mystream.h
// iostream interface for class Myio
// Defines the following classes:
//  Mystreambuf     derived from streambuf - buffer management & I/O interface
//  Mystreambase    base class used for initialisation & object reference
//  Myiostream      customised iostream, derived from iostream/Mystreambase
//
// Written by David L Nugent, June 1993
//

# if !defined(_Mystream_h)
# define _Mystream_h 1
# include <iostream.h>
# include "Myio.h"

    //
    // Mystreambuf
    // This is the class which does all the actual I/O
    // handling and (optional) buffer management
    //

class Mystreambuf : public streambuf
{

  public:

    Mystreambuf (Myio * mPtr);

  protected:

    virtual int overflow (int = EOF);
    virtual int underflow ();
    virtual int sync ();

  private:

    Myio * mptr;    // Points to the Myio instance to
                    // which this stream is attached
    char _back[2];  // Holder for putback

};


class Mystreambase : public virtual ios
{

  public:

    Mystreambase (Myio * mPtr);
    Mystreambuf * rdbuf (void);

  protected:

    Mystreambuf mystreambuf;

};

inline
Mystreambase::Mystreambase (Myio * mPtr)
    : mystreambuf (mPtr)
{}

inline Mystreambuf *
Mystreambase::rdbuf (void)
    {   return &mystreambuf;    }


class Mystream : public Mystreambase, public iostream
{

  public:

    Mystream (Myio * mPtr);
    ~Mystream (void);
};

    //
    // class Mystream constructor
    // This uses Mystreambase to set up the Mystreambuf
    // which can then be used to initialise iostream.
    //

inline
Mystream::Mystream (Myio * m)
    : Mystreambase (m), iostream (rdbuf())
{}

inline
Mystream::~Mystream (void)
    {}

# endif     // _Mystream_h