xref: /aoo41x/main/sw/inc/io.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 // eigene Klasse fuer IO, die die systemunabhaengige Darstellung
28 // uebernimmt (bytes dreht, Character konvertiert)
29 // das Schreiben erfolgt aus Effizienzgruenden binaer
30 #ifndef _IO_HXX
31 #define _IO_HXX
32 
33 #ifdef UNX
34 #include <unistd.h>
35 #else
36 #include <io.h>
37 #endif
38 
39 #include <fcntl.h>
40 
41 #include <sys/types.h>
42 #include <sys/stat.h>
43 
44 
45 #ifndef _KEYCOD_HXX //autogen
46 #include <vcl/keycod.hxx>
47 #endif
48 #include <tools/stream.hxx>
49 
50 /*$
51 class BinaryFile {
52 	int fd;
53 public:
54 	enum IO_OpenMode {
55 		BF_READ = O_RDONLY,
56 		BF_WRITE = O_RDWR,
57 		BF_CREATE = O_CREAT,
58 		BF_TRUNC = O_TRUNC
59 	};
60 		// ctor oeffnet File im BinearMode, dtor schliesst es
61 	BinaryFile(const String &, int eOpenMode);
62 	~BinaryFile();
63 	sal_Bool Ok() const {
64 		return -1 != fd;
65 	}
66 	operator int() const { return fd; }
67 };
68 */
69 
70 class SwIOin {
71 private:
72 		SvFileStream aStr; //$ ifstream
73 public:
74 	// Stream wird im entsprechenden Mode erzeugt.
75 	SwIOin(const String &rFilename, StreamMode nMode =
76 									STREAM_READ | STREAM_NOCREATE );
77 
78 	SwIOin& operator>>(char& val);
79 	SwIOin& operator>>(unsigned char& val);
80 	SwIOin& operator>>(char* val);
81 	SwIOin& operator>>(unsigned char* val);
82 	SwIOin& operator>>(short& val);
83 	SwIOin& operator>>(unsigned short& val);
84 	SwIOin& operator>>(long& val);
85 	SwIOin& operator>>(unsigned long& val);
86 	String ReadString();
87 	KeyCode ReadKeyCode();
88 	// kann erweitert werden fuer weitere Arrays von
89 	// Basistypen; nLen ist die Anzahl der Elemente
90 	SwIOin& Read(char *buf, unsigned nLen);
91 
92 	int operator!() { return aStr.GetError() != SVSTREAM_OK; }
93 		SvFileStream &operator()() {
94 		return aStr;
95 	}
96 };
97 
98 class SwIOout {
99 private:
100 	void _write(const char *buf, unsigned size);
101 	SvFileStream aStr; //$ ofstream
102 public:
103 	// Stream wird im entsprechenden Mode erzeugt.
104 	SwIOout( const String &rFilename, StreamMode nMode =
105 									  STREAM_WRITE | STREAM_NOCREATE );
106 	SwIOout& operator<<(char val);
107 	SwIOout& operator<<(unsigned char val);
108 	SwIOout& operator<<(char* val);
109 	SwIOout& operator<<(unsigned char* val);
110 	SwIOout& operator<<(short val);
111 	SwIOout& operator<<(unsigned short val);
112 	SwIOout& operator<<(long val);
113 	SwIOout& operator<<(unsigned long val);
114 	SwIOout& operator<<(const String &);
115 	SwIOout& operator<<(const KeyCode &);
116 	// kann erweitert werden fuer weitere Arrays von
117 	// Basistypen; nLen ist die Anzahl der Elemente
118 	SwIOout& Write(const char *buf, unsigned nLen);
119 
120 	int operator!() { return aStr.GetError() != SVSTREAM_OK; }
121 	SvFileStream &operator()() {
122 		return aStr;
123 	}
124 };
125 
126 
127 class SwIOinout {
128 private:
129 	SvFileStream aStr; //$ fstream
130 
131 public:
132 	// Stream wird im entsprechenden Mode erzeugt.
133 	SwIOinout(const String &rFilename, StreamMode nMode =
134 									   STREAM_READWRITE  | STREAM_NOCREATE );
135 
136 	SwIOinout& operator>>(char& val);
137 	SwIOinout& operator>>(unsigned char& val);
138 	SwIOinout& operator>>(char* val);
139 	SwIOinout& operator>>(unsigned char* val);
140 	SwIOinout& operator>>(short& val);
141 	SwIOinout& operator>>(unsigned short& val);
142 	SwIOinout& operator>>(long& val);
143 	SwIOinout& operator>>(unsigned long& val);
144 	String ReadString();
145 	KeyCode ReadKeyCode();
146 	// kann erweitert werden fuer weitere Arrays von
147 	// Basistypen; nLen ist die Anzahl der Elemente
148 	SwIOinout& Read(char *buf, unsigned nLen);
149 	SwIOinout& Read(unsigned short *buf, unsigned nLen );
150 
151 	SwIOinout& operator<<(char val);
152 	SwIOinout& operator<<(unsigned char val);
153 	SwIOinout& operator<<(char* val);
154 	SwIOinout& operator<<(unsigned char* val);
155 	SwIOinout& operator<<(short val);
156 	SwIOinout& operator<<(unsigned short val);
157 	SwIOinout& operator<<(long val);
158 	SwIOinout& operator<<(unsigned long val);
159 	SwIOinout& operator<<(const String &);
160 	SwIOinout& operator<<(const KeyCode &);
161 	// kann erweitert werden fuer weitere Arrays von
162 	// Basistypen; nLen ist die Anzahl der Elemente
163 	SwIOinout& Write(const char *buf, unsigned nLen);
164 
165 	int operator!() { return aStr.GetError() != SVSTREAM_OK; }
166 		SvFileStream &operator()() {
167 		return aStr;
168 	}
169 
170 	sal_Bool Ok();
171 };
172 
173 
174 
175 #endif
176 
177