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 24 #ifndef _VOS_STREAM_HXX_ 25 #define _VOS_STREAM_HXX_ 26 27 # include <vos/types.hxx> 28 # include <vos/object.hxx> 29 # include <vos/istream.hxx> 30 # include <vos/vosdllapi.h> 31 32 namespace vos 33 { 34 35 /** Adds seeking capabilities to IStream 36 */ 37 class IPositionableStream : public vos::IStream 38 { 39 40 public: 41 42 typedef sal_Int32 Offset; 43 44 public: 45 46 /// 47 virtual sal_Bool SAL_CALL seekTo(Offset position) const = 0; 48 49 /// 50 virtual sal_Bool SAL_CALL seekRelative(Offset change) const = 0; 51 52 /// 53 virtual sal_Bool SAL_CALL seekToEnd() const = 0; 54 55 /// 56 virtual sal_Bool SAL_CALL changeSize(sal_uInt32 new_size) = 0; 57 58 /// 59 virtual sal_uInt32 SAL_CALL getSize() const = 0; 60 61 62 /// 63 virtual Offset SAL_CALL getOffset() const = 0; 64 65 66 protected: 67 IPositionableStream() { } 68 virtual ~IPositionableStream() { } 69 70 }; 71 72 73 /** Implements IPositionableStream 74 */ 75 class VOS_DLLPUBLIC OStream : public vos::OObject, 76 public vos::IPositionableStream 77 { 78 VOS_DECLARE_CLASSINFO(VOS_NAMESPACE(OStream, vos)); 79 80 public: 81 82 /// 83 OStream(IPositionableStream& rStream); 84 85 /// 86 virtual ~OStream (); 87 88 // ----------------- Read operations ------------------------- 89 90 /// 91 virtual sal_Int32 SAL_CALL read(void* pbuffer, sal_uInt32 n) const; 92 93 /// 94 sal_Int32 SAL_CALL read(IPositionableStream::Offset offset, 95 void* pbuffer, 96 sal_uInt32 n) const; 97 98 /// 99 inline sal_Bool SAL_CALL read(sal_Int32& value) const; 100 101 /// 102 inline sal_Bool SAL_CALL read(sal_Int16& value) const; 103 104 /// 105 inline sal_Bool SAL_CALL read(sal_Char& value) const; 106 107 /// 108 inline sal_Bool SAL_CALL read(sal_uInt8& value) const; 109 110 // ----------------- Write operations ------------------------ 111 112 /// 113 virtual sal_Int32 SAL_CALL write(const void* pbuffer, sal_uInt32 n); 114 115 /// 116 sal_Int32 SAL_CALL write(IPositionableStream::Offset offset, 117 const void* pbuffer, 118 sal_uInt32 n); 119 /// 120 inline sal_Bool SAL_CALL write(sal_Int32 value); 121 122 /// 123 inline sal_Bool SAL_CALL write(sal_Int16 value); 124 125 /// 126 inline sal_Bool SAL_CALL write(sal_Char value); 127 128 /// 129 inline sal_Bool SAL_CALL write(sal_uInt8 value); 130 131 /// 132 sal_Bool SAL_CALL append(void* pbuffer, sal_uInt32 n); // Write at the end of the Stream. 133 134 // ------------- Positioning and sizing operations ---------- 135 136 /// 137 inline sal_Bool SAL_CALL seekToBegin() const; 138 139 // ----------------- Stream interface ------------------------ 140 141 /// 142 virtual sal_Bool SAL_CALL seekTo(IPositionableStream::Offset pos) const; 143 144 /// 145 virtual sal_Bool SAL_CALL seekToEnd() const; 146 147 /// 148 virtual sal_Bool SAL_CALL seekRelative(IPositionableStream::Offset change) const; 149 150 /// 151 virtual sal_Bool SAL_CALL changeSize(sal_uInt32 new_size); 152 153 /// 154 virtual sal_uInt32 SAL_CALL getSize() const; 155 156 /// 157 virtual sal_Bool SAL_CALL isEof() const; 158 159 /// 160 virtual IPositionableStream::Offset SAL_CALL getOffset() const; 161 162 protected: 163 IPositionableStream& m_rStream; 164 165 // ----------------- Stream operators ------------------------ 166 167 friend const OStream& operator>> (OStream& rStream, sal_Int32& value); 168 friend const OStream& operator>> (OStream& rStream, sal_Int16& value); 169 friend const OStream& operator>> (OStream& rStream, sal_uInt8& value); 170 friend const OStream& operator>> (OStream& rStream, sal_Char& value); 171 friend OStream& operator<< (OStream& rStream, sal_Int32 value); 172 friend OStream& operator<< (OStream& rStream, sal_Int16 value); 173 friend OStream& operator<< (OStream& rStream, sal_uInt8 value); 174 friend OStream& operator<< (OStream& rStream, sal_Char value); 175 }; 176 177 inline sal_Bool OStream::read(sal_Int32& value) const 178 { 179 return (read(&value, sizeof(value)) == sizeof(value)); 180 } 181 182 inline sal_Bool OStream::read(sal_Int16& value) const 183 { 184 return (read(&value, sizeof(value)) == sizeof(value)); 185 } 186 187 inline sal_Bool OStream::read(sal_Char& value) const 188 { 189 return (read(&value, sizeof(value)) == sizeof(value)); 190 } 191 192 inline sal_Bool OStream::read(sal_uInt8& value) const 193 { 194 return (read(&value, sizeof(value)) == sizeof(value)); 195 } 196 197 inline sal_Bool OStream::write(sal_Int32 value) 198 { 199 return (write(&value, sizeof(value)) == sizeof(value)); 200 } 201 202 inline sal_Bool OStream::write(sal_Int16 value) 203 { 204 return (write(&value, sizeof(value)) == sizeof(value)); 205 } 206 207 inline sal_Bool OStream::write(sal_Char value) 208 { 209 return (write(&value, sizeof(value)) == sizeof(value)); 210 } 211 212 inline sal_Bool OStream::write(sal_uInt8 value) 213 { 214 return (write((sal_uInt8*)&value, sizeof(value)) == sizeof(value)); 215 } 216 217 inline sal_Bool OStream::seekToBegin() const 218 { 219 return (seekTo(0L)); 220 } 221 222 inline const OStream& operator>> (OStream& rStream, sal_Int32& value) 223 { 224 rStream.read(value); 225 226 return (rStream); 227 } 228 229 inline const OStream& operator>> (OStream& rStream, sal_Int16& value) 230 { 231 rStream.read(value); 232 233 return (rStream); 234 } 235 236 inline const OStream& operator>> (OStream& rStream, sal_uInt8& value) 237 { 238 rStream.read(value); 239 240 return (rStream); 241 } 242 243 inline const OStream& operator>> (OStream& rStream, sal_Char& value) 244 { 245 rStream.read(value); 246 247 return (rStream); 248 } 249 250 inline OStream& operator<< (OStream& rStream, sal_Int32 value) 251 { 252 rStream.write(value); 253 254 return (rStream); 255 } 256 257 inline OStream& operator<< (OStream& rStream, sal_Int16 value) 258 { 259 rStream.write(value); 260 261 return (rStream); 262 } 263 264 inline OStream& operator<< (OStream& rStream, sal_uInt8 value) 265 { 266 rStream.write(value); 267 268 return (rStream); 269 } 270 271 inline OStream& operator<< (OStream& rStream, sal_Char value) 272 { 273 rStream.write(value); 274 275 return (rStream); 276 } 277 278 } 279 280 #endif // _VOS_STREAM_HXX_ 281