GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / oox / source / helper / binarystreambase.cxx
blobf85a811477fc8094ca20e1924bdc4a07f1c3eba4
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 #include "oox/helper/binarystreambase.hxx"
22 #include <com/sun/star/io/XSeekable.hpp>
23 #include <osl/diagnose.h>
25 namespace oox {
27 // ============================================================================
29 using namespace ::com::sun::star::io;
30 using namespace ::com::sun::star::uno;
32 // ============================================================================
34 BinaryStreamBase::~BinaryStreamBase()
38 sal_Int64 BinaryStreamBase::getRemaining() const
40 // do not use isSeekable(), implementations may provide stream position and size even if not seekable
41 sal_Int64 nPos = tell();
42 sal_Int64 nLen = size();
43 return ((nPos >= 0) && (nLen >= 0)) ? ::std::max< sal_Int64 >( nLen - nPos, 0 ) : -1;
46 void BinaryStreamBase::alignToBlock( sal_Int32 nBlockSize, sal_Int64 nAnchorPos )
48 sal_Int64 nStrmPos = tell();
49 // nothing to do, if stream is at anchor position
50 if( mbSeekable && (0 <= nAnchorPos) && (nAnchorPos != nStrmPos) && (nBlockSize > 1) )
52 // prevent modulo with negative arguments...
53 sal_Int64 nSkipSize = (nAnchorPos < nStrmPos) ?
54 (nBlockSize - ((nStrmPos - nAnchorPos - 1) % nBlockSize) - 1) :
55 ((nAnchorPos - nStrmPos) % nBlockSize);
56 seek( nStrmPos + nSkipSize );
60 // ============================================================================
62 BinaryXSeekableStream::BinaryXSeekableStream( const Reference< XSeekable >& rxSeekable ) :
63 BinaryStreamBase( mxSeekable.is() ),
64 mxSeekable( rxSeekable )
68 BinaryXSeekableStream::~BinaryXSeekableStream()
72 sal_Int64 BinaryXSeekableStream::size() const
74 if( mxSeekable.is() ) try
76 return mxSeekable->getLength();
78 catch( Exception& )
80 OSL_FAIL( "BinaryXSeekableStream::size - exception caught" );
82 return -1;
85 sal_Int64 BinaryXSeekableStream::tell() const
87 if( mxSeekable.is() ) try
89 return mxSeekable->getPosition();
91 catch( Exception& )
93 OSL_FAIL( "BinaryXSeekableStream::tell - exception caught" );
95 return -1;
98 void BinaryXSeekableStream::seek( sal_Int64 nPos )
100 if( mxSeekable.is() ) try
102 mbEof = false;
103 mxSeekable->seek( nPos );
105 catch( Exception& )
107 mbEof = true;
111 void BinaryXSeekableStream::close()
113 mxSeekable.clear();
114 mbEof = true;
117 // ============================================================================
119 SequenceSeekableStream::SequenceSeekableStream( const StreamDataSequence& rData ) :
120 BinaryStreamBase( true ),
121 mpData( &rData ),
122 mnPos( 0 )
126 sal_Int64 SequenceSeekableStream::size() const
128 return mpData ? mpData->getLength() : -1;
131 sal_Int64 SequenceSeekableStream::tell() const
133 return mpData ? mnPos : -1;
136 void SequenceSeekableStream::seek( sal_Int64 nPos )
138 if( mpData )
140 mnPos = getLimitedValue< sal_Int32, sal_Int64 >( nPos, 0, mpData->getLength() );
141 mbEof = mnPos != nPos;
145 void SequenceSeekableStream::close()
147 mpData = 0;
148 mbEof = true;
151 // ============================================================================
153 } // namespace oox
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */