update credits
[LibreOffice.git] / include / cosv / bstream.hxx
blob2d943bc02ce6e1bc37654ef4382baabdc05e1dd6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef CSV_BSTREAM_HXX
21 #define CSV_BSTREAM_HXX
23 #include <string.h>
24 #include <cosv/string.hxx>
27 namespace csv
31 enum seek_dir
33 beg = 0,
34 cur = 1,
35 end = 2
39 class bistream
41 public:
42 // LIFECYCLE
43 virtual ~bistream() {}
45 // OPERATIONS
46 /// @return Number of actually read bytes.
47 uintt read(
48 void * out_pDest,
49 uintt i_nNrofBytes);
50 // INQUIRY
51 /** @return True, if already one try to read had failed.
52 There is no guarantee, that it returns true, if end of data
53 is just reached.
54 Though it will return false, if there is still somemething
55 to read.
57 bool eod() const;
59 private:
60 virtual uintt do_read(
61 void * out_pDest,
62 uintt i_nNrofBytes) = 0;
63 virtual bool inq_eod() const = 0;
67 class bostream
69 public:
70 // LIFECYCLE
71 virtual ~bostream() {}
73 // OPERATIONS
74 /// @return Number of actually written bytes.
75 uintt write(
76 const void * i_pSrc,
77 uintt i_nNrofBytes);
78 /// @return Number of actually written bytes.
79 uintt write(
80 const char * i_pSrc );
81 /// @return Number of actually written bytes.
82 uintt write(
83 const String & i_pSrc );
84 private:
85 virtual uintt do_write(
86 const void * i_pSrc,
87 uintt i_nNrofBytes) = 0;
91 class bstream : public bistream,
92 public bostream
94 public:
95 uintt seek(
96 intt i_nDistanceFromBegin,
97 seek_dir i_eStartPoint = ::csv::beg );
98 uintt position() const;
100 private:
101 virtual uintt do_seek(
102 intt i_nDistance,
103 seek_dir i_eStartPoint = ::csv::beg ) = 0;
104 virtual uintt inq_position() const = 0;
108 // IMPLEMENTATION
109 inline uintt
110 bistream::read( void * o_pDest,
111 uintt i_nNrofBytes)
112 { return do_read(o_pDest, i_nNrofBytes); }
113 inline bool
114 bistream::eod() const
115 { return inq_eod(); }
117 inline uintt
118 bostream::write( const void * i_pSrc,
119 uintt i_nNrofBytes)
120 { return do_write( i_pSrc, i_nNrofBytes ); }
121 inline uintt
122 bostream::write( const char * i_sSrc )
123 { return write( i_sSrc, strlen(i_sSrc) ); }
124 inline uintt
125 bostream::write( const String & i_sSrc )
126 { return write( i_sSrc.c_str(), i_sSrc.length() ); }
128 inline uintt
129 bstream::seek( intt i_nDistance,
130 seek_dir i_eStartPoint )
131 { return do_seek( i_nDistance, i_eStartPoint ); }
132 inline uintt
133 bstream::position() const
134 { return inq_position(); }
138 } // namespace csv
141 #endif
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */