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