1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                CHARSTRM.H                                 */
4 /*                                                                           */
5 /* (C) 1996     Ullrich von Bassewitz                                        */
6 /*              Wacholderweg 14                                              */
7 /*              D-70597 Stuttgart                                            */
8 /* EMail:       uz@musoftware.com                                            */
9 /*                                                                           */
10 /*****************************************************************************/
11 
12 
13 
14 // $Id$
15 //
16 // $Log$
17 //
18 //
19 
20 
21 
22 // This module defines a special family of streams. A CharacterStream is
23 // different from a Stream in that it is not possible to do things like
24 // Seek and Truncate. Instead, they have timeouts for read and write.
25 // Usually a CharacterStream works on something like a serial device, a
26 // network connection and such.
27 
28 
29 
30 #ifndef _CHARSTRM_H
31 #define _CHARSTRM_H
32 
33 
34 
35 #include <stdlib.h>
36 
37 #include "stream.h"
38 
39 
40 
41 /*****************************************************************************/
42 /*                           class CharacterStream                           */
43 /*****************************************************************************/
44 
45 
46 
47 class CharacterStream: public Stream {
48 
49 protected:
50     double      ReadTimeout, WriteTimeout;
51     // The timeouts - see the functions SetReadTimeout/SetWriteTimeout for an
52     // explanation.
53 
54 public:
55     virtual u32 GetPos ();
56     // Get the current value of the stream pointer
57 
58     virtual u32 GetSize ();
59     // Return the size of the stream in bytes
60 
61     virtual void Seek (unsigned long Pos);
62     // Set the stream pointer to the specified position
63 
64     virtual void SeekToEnd ();
65     // Set the stream pointer to the end of the stream
66 
67     virtual void Truncate ();
68     // Truncate the stream at the current position
69 
70     virtual void SetReadTimeout (double T);
71     // Set the read timeout for the stream.
72     // A value of zero means no timeout (error if data not immidiately
73     // available) a value less than zero means "indefinite wait".
74     // Beware: The implementation of the timeout is device dependent! As an
75     // example, there may be devices that cannot do timeouts less than one
76     // second.
77 
78     virtual void SetWriteTimeout (double T);
79     // Set the write timeout for the stream.
80     // A value of zero means no timeout (error if data cannot be written
81     // immidiately) a value less than zero means "indefinite wait".
82     // Beware: The implementation of the timeouts is device dependent! As an
83     // example, there may be devices that cannot do timeouts less than one
84     // second.
85 
86     double GetReadTimeout () const;
87     // Return the read timeout
88 
89     double GetWriteTimeout () const;
90     // Return the write timeout
91 
92     virtual size_t ReadCount () const;
93     // Return the amount of bytes that can be read without waiting. On many
94     // devices it is impossible to tell the exact number, in these cases the
95     // function returns a value of 1 if at least one byte can be read without
96     // blocking and 0 otherwise.
97 
98     virtual size_t WriteCount () const;
99     // Return the amount of bytes that can be written without waiting. On many
100     // devices it is impossible to tell the exact number, in these cases the
101     // function returns a value of 1 if at least one byte can be written without
102     // blocking and 0 otherwise.
103 
104 };
105 
106 
107 
GetReadTimeout()108 inline double CharacterStream::GetReadTimeout () const
109 // Return the read timeout
110 {
111     return ReadTimeout;
112 }
113 
114 
115 
GetWriteTimeout()116 inline double CharacterStream::GetWriteTimeout () const
117 // Return the write timeout
118 {
119     return WriteTimeout;
120 }
121 
122 
123 
124 // End of CHARSTRM.H
125 
126 #endif
127 
128 
129 
130