update emoji autocorrect entries from po-files
[LibreOffice.git] / include / oox / helper / binarystreambase.hxx
blob03ec5ff6a65d8f4bff61960839e57e2905992576
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 INCLUDED_OOX_HELPER_BINARYSTREAMBASE_HXX
21 #define INCLUDED_OOX_HELPER_BINARYSTREAMBASE_HXX
23 #include <com/sun/star/uno/Sequence.hxx>
24 #include <oox/helper/helper.hxx>
25 #include <oox/dllapi.h>
26 #include <memory>
28 namespace com { namespace sun { namespace star {
29 namespace io { class XSeekable; }
30 } } }
32 namespace oox {
34 typedef ::com::sun::star::uno::Sequence< sal_Int8 > StreamDataSequence;
38 /** Base class for binary stream classes.
40 class OOX_DLLPUBLIC BinaryStreamBase
42 public:
43 virtual ~BinaryStreamBase();
45 /** Implementations return the size of the stream, if possible.
47 This function may be implemented for some types of unseekable streams,
48 and MUST be implemented for all seekable streams.
50 @return
51 The size of the stream in bytes, or -1, if not implemented.
53 virtual sal_Int64 size() const = 0;
55 /** Implementations return the current stream position, if possible.
57 This function may be implemented for some types of unseekable streams,
58 and MUST be implemented for all seekable streams.
60 @return
61 The current position in the stream, or -1, if not implemented.
63 virtual sal_Int64 tell() const = 0;
65 /** Implementations seek the stream to the passed position, if
66 the stream is seekable.
68 virtual void seek( sal_Int64 nPos ) = 0;
70 /** Implementations close the stream.
72 virtual void close() = 0;
74 /** Returns true, if the implementation supports the seek() operation.
76 Implementations may still implement size() and tell() even if the
77 stream is not seekable.
79 bool isSeekable() const { return mbSeekable; }
81 /** Returns true, if the stream position is invalid (EOF). This flag turns
82 true *after* the first attempt to seek/read beyond the stream end.
84 bool isEof() const { return mbEof; }
86 /** Returns the size of the remaining data available in the stream, if
87 stream supports size() and tell(), otherwise -1.
89 sal_Int64 getRemaining() const;
91 /** Seeks the stream to the beginning, if stream is seekable.
93 void seekToStart() { seek( 0 ); }
95 /** Seeks the stream to the end, if stream is seekable.
97 void seekToEnd() { seek( size() ); }
99 /** Seeks the stream forward to a position that is a multiple of the passed
100 block size, if stream is seekable.
102 @param nBlockSize
103 The size of the data blocks the streams needs to be aligned to.
105 @param nAnchorPos
106 Position in the stream the data blocks are aligned to.
108 void alignToBlock( sal_Int32 nBlockSize, sal_Int64 nAnchorPos = 0 );
110 protected:
111 explicit BinaryStreamBase( bool bSeekable ) : mbEof( false ), mbSeekable( bSeekable ) {}
113 private:
114 BinaryStreamBase( const BinaryStreamBase& ) SAL_DELETED_FUNCTION;
115 BinaryStreamBase& operator=( const BinaryStreamBase& ) SAL_DELETED_FUNCTION;
117 protected:
118 bool mbEof; ///< End of stream flag.
120 private:
121 const bool mbSeekable; ///< True = implementation supports seeking.
126 /** Base class for binary input and output streams wrapping a UNO stream,
127 seekable via the com.sun.star.io.XSeekable interface.
129 class OOX_DLLPUBLIC BinaryXSeekableStream : public virtual BinaryStreamBase
131 public:
132 virtual ~BinaryXSeekableStream();
134 /** Returns the size of the stream, if wrapped stream is seekable, otherwise -1. */
135 virtual sal_Int64 size() const SAL_OVERRIDE;
136 /** Returns the current stream position, if wrapped stream is seekable, otherwise -1. */
137 virtual sal_Int64 tell() const SAL_OVERRIDE;
138 /** Seeks the stream to the passed position, if wrapped stream is seekable. */
139 virtual void seek( sal_Int64 nPos ) SAL_OVERRIDE;
140 /** Releases the reference to the UNO XSeekable interface. */
141 virtual void close() SAL_OVERRIDE;
143 protected:
144 explicit BinaryXSeekableStream(
145 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XSeekable >& rxSeekable );
147 private:
148 ::com::sun::star::uno::Reference< ::com::sun::star::io::XSeekable >
149 mxSeekable; ///< Stream seeking interface.
154 /** Base class for binary input and output streams wrapping a
155 StreamDataSequence, which is always seekable.
157 The wrapped data sequence MUST live at least as long as this stream
158 wrapper. The data sequence MUST NOT be changed from outside as long as this
159 stream wrapper is used to modify it.
161 class OOX_DLLPUBLIC SequenceSeekableStream : public virtual BinaryStreamBase
163 public:
164 /** Returns the size of the wrapped data sequence. */
165 virtual sal_Int64 size() const SAL_OVERRIDE;
166 /** Returns the current stream position. */
167 virtual sal_Int64 tell() const SAL_OVERRIDE;
168 /** Seeks the stream to the passed position. */
169 virtual void seek( sal_Int64 nPos ) SAL_OVERRIDE;
170 /** Releases the reference to the data sequence. */
171 virtual void close() SAL_OVERRIDE;
173 protected:
174 explicit SequenceSeekableStream( const StreamDataSequence& rData );
176 protected:
177 const StreamDataSequence* mpData; ///< Wrapped data sequence.
178 sal_Int32 mnPos; ///< Current position in the sequence.
183 } // namespace oox
185 #endif
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */