xref: /aoo42x/main/sw/inc/io.hxx (revision 1d2dbeb0)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 // eigene Klasse fuer IO, die die systemunabhaengige Darstellung
24 // uebernimmt (bytes dreht, Character konvertiert)
25 // das Schreiben erfolgt aus Effizienzgruenden binaer
26 #ifndef _IO_HXX
27 #define _IO_HXX
28 
29 #ifdef UNX
30 #include <unistd.h>
31 #else
32 #include <io.h>
33 #endif
34 
35 #include <fcntl.h>
36 
37 #include <sys/types.h>
38 #include <sys/stat.h>
39 
40 
41 #ifndef _KEYCOD_HXX //autogen
42 #include <vcl/keycod.hxx>
43 #endif
44 #include <tools/stream.hxx>
45 
46 /*$
47 class BinaryFile {
48 	int fd;
49 public:
50 	enum IO_OpenMode {
51 		BF_READ = O_RDONLY,
52 		BF_WRITE = O_RDWR,
53 		BF_CREATE = O_CREAT,
54 		BF_TRUNC = O_TRUNC
55 	};
56 		// ctor oeffnet File im BinearMode, dtor schliesst es
57 	BinaryFile(const String &, int eOpenMode);
58 	~BinaryFile();
59 	sal_Bool Ok() const {
60 		return -1 != fd;
61 	}
62 	operator int() const { return fd; }
63 };
64 */
65 
66 class SwIOin {
67 private:
68 		SvFileStream aStr; //$ ifstream
69 public:
70 	// Stream wird im entsprechenden Mode erzeugt.
71 	SwIOin(const String &rFilename, StreamMode nMode =
72 									STREAM_READ | STREAM_NOCREATE );
73 
74 	SwIOin& operator>>(char& val);
75 	SwIOin& operator>>(unsigned char& val);
76 	SwIOin& operator>>(char* val);
77 	SwIOin& operator>>(unsigned char* val);
78 	SwIOin& operator>>(short& val);
79 	SwIOin& operator>>(unsigned short& val);
80 	SwIOin& operator>>(long& val);
81 	SwIOin& operator>>(unsigned long& val);
82 	String ReadString();
83 	KeyCode ReadKeyCode();
84 	// kann erweitert werden fuer weitere Arrays von
85 	// Basistypen; nLen ist die Anzahl der Elemente
86 	SwIOin& Read(char *buf, unsigned nLen);
87 
operator !()88 	int operator!() { return aStr.GetError() != SVSTREAM_OK; }
operator ()()89 		SvFileStream &operator()() {
90 		return aStr;
91 	}
92 };
93 
94 class SwIOout {
95 private:
96 	void _write(const char *buf, unsigned size);
97 	SvFileStream aStr; //$ ofstream
98 public:
99 	// Stream wird im entsprechenden Mode erzeugt.
100 	SwIOout( const String &rFilename, StreamMode nMode =
101 									  STREAM_WRITE | STREAM_NOCREATE );
102 	SwIOout& operator<<(char val);
103 	SwIOout& operator<<(unsigned char val);
104 	SwIOout& operator<<(char* val);
105 	SwIOout& operator<<(unsigned char* val);
106 	SwIOout& operator<<(short val);
107 	SwIOout& operator<<(unsigned short val);
108 	SwIOout& operator<<(long val);
109 	SwIOout& operator<<(unsigned long val);
110 	SwIOout& operator<<(const String &);
111 	SwIOout& operator<<(const KeyCode &);
112 	// kann erweitert werden fuer weitere Arrays von
113 	// Basistypen; nLen ist die Anzahl der Elemente
114 	SwIOout& Write(const char *buf, unsigned nLen);
115 
operator !()116 	int operator!() { return aStr.GetError() != SVSTREAM_OK; }
operator ()()117 	SvFileStream &operator()() {
118 		return aStr;
119 	}
120 };
121 
122 
123 class SwIOinout {
124 private:
125 	SvFileStream aStr; //$ fstream
126 
127 public:
128 	// Stream wird im entsprechenden Mode erzeugt.
129 	SwIOinout(const String &rFilename, StreamMode nMode =
130 									   STREAM_READWRITE  | STREAM_NOCREATE );
131 
132 	SwIOinout& operator>>(char& val);
133 	SwIOinout& operator>>(unsigned char& val);
134 	SwIOinout& operator>>(char* val);
135 	SwIOinout& operator>>(unsigned char* val);
136 	SwIOinout& operator>>(short& val);
137 	SwIOinout& operator>>(unsigned short& val);
138 	SwIOinout& operator>>(long& val);
139 	SwIOinout& operator>>(unsigned long& val);
140 	String ReadString();
141 	KeyCode ReadKeyCode();
142 	// kann erweitert werden fuer weitere Arrays von
143 	// Basistypen; nLen ist die Anzahl der Elemente
144 	SwIOinout& Read(char *buf, unsigned nLen);
145 	SwIOinout& Read(unsigned short *buf, unsigned nLen );
146 
147 	SwIOinout& operator<<(char val);
148 	SwIOinout& operator<<(unsigned char val);
149 	SwIOinout& operator<<(char* val);
150 	SwIOinout& operator<<(unsigned char* val);
151 	SwIOinout& operator<<(short val);
152 	SwIOinout& operator<<(unsigned short val);
153 	SwIOinout& operator<<(long val);
154 	SwIOinout& operator<<(unsigned long val);
155 	SwIOinout& operator<<(const String &);
156 	SwIOinout& operator<<(const KeyCode &);
157 	// kann erweitert werden fuer weitere Arrays von
158 	// Basistypen; nLen ist die Anzahl der Elemente
159 	SwIOinout& Write(const char *buf, unsigned nLen);
160 
operator !()161 	int operator!() { return aStr.GetError() != SVSTREAM_OK; }
operator ()()162 		SvFileStream &operator()() {
163 		return aStr;
164 	}
165 
166 	sal_Bool Ok();
167 };
168 
169 
170 
171 #endif
172 
173