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 28 #ifndef CSV_BSTREAM_HXX 29 #define CSV_BSTREAM_HXX 30 31 #include <string.h> 32 #include <cosv/string.hxx> 33 34 35 namespace csv 36 { 37 38 39 enum seek_dir 40 { 41 beg = 0, 42 cur = 1, 43 end = 2 44 }; 45 46 47 class bistream 48 { 49 public: 50 // LIFECYCLE 51 virtual ~bistream() {} 52 53 // OPERATIONS 54 /// @return Number of actually read bytes. 55 uintt read( 56 void * out_pDest, 57 uintt i_nNrofBytes); 58 // INQUIRY 59 /** @return True, if already one try to read had failed. 60 There is no guarantee, that it returns true, if end of data 61 is just reached. 62 Though it will return false, if there is still somemething 63 to read. 64 */ 65 bool eod() const; 66 67 private: 68 virtual uintt do_read( 69 void * out_pDest, 70 uintt i_nNrofBytes) = 0; 71 virtual bool inq_eod() const = 0; 72 }; 73 74 75 class bostream 76 { 77 public: 78 // LIFECYCLE 79 virtual ~bostream() {} 80 81 // OPERATIONS 82 /// @return Number of actually written bytes. 83 uintt write( 84 const void * i_pSrc, 85 uintt i_nNrofBytes); 86 /// @return Number of actually written bytes. 87 uintt write( 88 const char * i_pSrc ); 89 /// @return Number of actually written bytes. 90 uintt write( 91 const String & i_pSrc ); 92 private: 93 virtual uintt do_write( 94 const void * i_pSrc, 95 uintt i_nNrofBytes) = 0; 96 }; 97 98 99 class bstream : public bistream, 100 public bostream 101 { 102 public: 103 uintt seek( 104 intt i_nDistanceFromBegin, 105 seek_dir i_eStartPoint = ::csv::beg ); 106 uintt position() const; 107 108 private: 109 virtual uintt do_seek( 110 intt i_nDistance, 111 seek_dir i_eStartPoint = ::csv::beg ) = 0; 112 virtual uintt inq_position() const = 0; 113 }; 114 115 116 // IMPLEMENTATION 117 inline uintt 118 bistream::read( void * o_pDest, 119 uintt i_nNrofBytes) 120 { return do_read(o_pDest, i_nNrofBytes); } 121 inline bool 122 bistream::eod() const 123 { return inq_eod(); } 124 125 inline uintt 126 bostream::write( const void * i_pSrc, 127 uintt i_nNrofBytes) 128 { return do_write( i_pSrc, i_nNrofBytes ); } 129 inline uintt 130 bostream::write( const char * i_sSrc ) 131 { return write( i_sSrc, strlen(i_sSrc) ); } 132 inline uintt 133 bostream::write( const String & i_sSrc ) 134 { return write( i_sSrc.c_str(), i_sSrc.length() ); } 135 136 inline uintt 137 bstream::seek( intt i_nDistance, 138 seek_dir i_eStartPoint ) 139 { return do_seek( i_nDistance, i_eStartPoint ); } 140 inline uintt 141 bstream::position() const 142 { return inq_position(); } 143 144 145 146 } // namespace csv 147 148 149 #endif 150 151