summaryrefslogtreecommitdiffstats
path: root/private/utils/ulib/inc/filestrm.hxx
blob: 581571670f37f4ee416f12c277cadde54dafd766 (plain) (blame)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*++

Copyright (c) 1991  Microsoft Corporation

Module Name:

    filestrm.hxx

Abstract:

    This module contains the declaration for the FILE_STREAM class.
    The FILE_STREAM is an abstract class derived from BUFFER_STREAM,
    that models a file as a stream of data.
    A FILE_STREAM class has the concept of a pointer (file poiter),
    and it provides some methods that allow operations on this pointer,
    such as:

        .move file pointer to a particular position;
        .read/write byte in a particular position;
        .query the position of the file pointer;

    The only way that a client has to create a FILE_STREAM is through
    QueryStream() (a method in FSN_FILE).
    FILE_STREAM can be has a method for initialization with two different
    signatures. In one case, a PFSN_FILE is passed as parameter. This
    initialization is used by QueryStream().
    The other signature allows that a HANDLE is passed as parameter.
    This initialization is used by GetStandardStream() during the
    initialization of ulib.



Author:

    Jaime Sasson (jaimes) 21-Mar-1991

Environment:

    ULIB, User Mode


--*/


#if !defined( _FILE_STREAM_ )

#define _FILE_STREAM_

#include "bufstrm.hxx"


enum SEEKORIGIN {
        STREAM_BEGINNING,
        STREAM_CURRENT,
        STREAM_END
        };

//
//  Forward references
//

DECLARE_CLASS( FILE_STREAM );
DECLARE_CLASS( FSN_FILE );


class FILE_STREAM : public BUFFER_STREAM {

    friend class FSN_FILE;
    friend class COMM_DEVICE;
    friend  PSTREAM GetStandardStream( HANDLE, STREAMACCESS );

    public:

        ULIB_EXPORT
        DECLARE_CAST_MEMBER_FUNCTION( FILE_STREAM );

        VIRTUAL
        ~FILE_STREAM(
            );

        VIRTUAL
        BOOLEAN
        MovePointerPosition(
            IN LONG     Position,
            IN SEEKORIGIN   Origin
            );

        VIRTUAL
        STREAMACCESS
        QueryAccess(
            ) CONST;

        VIRTUAL
        BOOLEAN
        QueryPointerPosition(
            OUT PULONG      Position
            );

        NONVIRTUAL
        BOOLEAN
        Read(
            OUT PBYTE   Buffer,
            IN  ULONG   NumberOfBytesToRead,
            OUT PULONG  NumberOfBytesRead
            );

        NONVIRTUAL
        ULIB_EXPORT
        BOOLEAN
        ReadAt(
            OUT PBYTE       Buffer,
            IN  ULONG       BytesToRead,
            IN  LONG        Position,
            IN  SEEKORIGIN  Origin,
            OUT PULONG      BytesRead
            );

        NONVIRTUAL
        BOOLEAN
        Write(
            IN  PCBYTE      Buffer,
            IN  ULONG       BytesToWrite,
            OUT PULONG      BytesWritten
            );

        NONVIRTUAL
        BOOLEAN
        WriteAt(
            OUT PBYTE       Buffer,
            IN  ULONG       BytesToWrite,
            IN  LONG        Position,
            IN  SEEKORIGIN  Origin,
            OUT PULONG      BytesWritten
            );


    protected:

        DECLARE_CONSTRUCTOR( FILE_STREAM );

        NONVIRTUAL
        BOOLEAN
        Initialize(
            PCFSN_FILE      File,
            STREAMACCESS    Access
            );

        NONVIRTUAL
        BOOLEAN
        Initialize(
            HANDLE          Handle,
            STREAMACCESS    Access
            );

        VIRTUAL
        BOOLEAN
        AdvanceBufferPointer(
            IN ULONG    NumberOfBytes
            );

        VIRTUAL
        BOOLEAN
        EndOfFile(
            ) CONST;

        NONVIRTUAL
        BOOLEAN
        FillBuffer(
            IN  PBYTE   Buffer,
            IN  ULONG   BufferSize,
            OUT PULONG  BytesRead
            );

        NONVIRTUAL
        PCBYTE
        GetBuffer(
            PULONG  BytesInBuffer
            );

        VIRTUAL
        HANDLE
        QueryHandle(
            ) CONST;


    private:

        NONVIRTUAL
        VOID
        Construct(
            );


        HANDLE          _FileHandle;
        HANDLE          _FileMappingHandle;
        STREAMACCESS    _Access;
        BOOLEAN         _EndOfFile;
        BOOLEAN         _ShouldCloseHandle;
        PBYTE           _FileBaseAddress;
        ULONG           _FileSize;
        PBYTE           _CurrentByte;
        BOOLEAN         _EmptyFile;
        BOOLEAN         _MemoryMappedFile;
};



#endif // _FILE_STREAM_