LCOV - code coverage report
Current view: top level - svl/source/items - lckbitem.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 63 1.6 %
Date: 2014-11-03 Functions: 1 16 6.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include <svl/lckbitem.hxx>
      21             : #include <svl/poolitem.hxx>
      22             : #include <com/sun/star/uno/Any.hxx>
      23             : #include <com/sun/star/uno/Sequence.hxx>
      24             : 
      25             : 
      26             : 
      27          38 : TYPEINIT1_AUTOFACTORY(SfxLockBytesItem, SfxPoolItem);
      28             : 
      29             : 
      30             : 
      31           0 : SfxLockBytesItem::SfxLockBytesItem()
      32             : {
      33           0 : }
      34             : 
      35             : 
      36             : 
      37           0 : SfxLockBytesItem::SfxLockBytesItem( sal_uInt16 nW, SvStream &rStream )
      38           0 : :   SfxPoolItem( nW )
      39             : {
      40           0 :     rStream.Seek( 0L );
      41           0 :     _xVal = new SvLockBytes( new SvMemoryStream(), true );
      42             : 
      43           0 :     SvStream aLockBytesStream( _xVal );
      44           0 :     rStream.ReadStream( aLockBytesStream );
      45           0 : }
      46             : 
      47             : 
      48             : 
      49           0 : SfxLockBytesItem::SfxLockBytesItem( const SfxLockBytesItem& rItem )
      50             : :   SfxPoolItem( rItem ),
      51           0 :     _xVal( rItem._xVal )
      52             : {
      53           0 : }
      54             : 
      55             : 
      56             : 
      57           0 : SfxLockBytesItem::~SfxLockBytesItem()
      58             : {
      59           0 : }
      60             : 
      61             : 
      62             : 
      63           0 : bool SfxLockBytesItem::operator==( const SfxPoolItem& rItem ) const
      64             : {
      65           0 :     return static_cast<const SfxLockBytesItem&>(rItem)._xVal == _xVal;
      66             : }
      67             : 
      68             : 
      69             : 
      70           0 : SfxPoolItem* SfxLockBytesItem::Clone(SfxItemPool *) const
      71             : {
      72           0 :     return new SfxLockBytesItem( *this );
      73             : }
      74             : 
      75             : 
      76             : 
      77             : #define MAX_BUF 32000
      78             : 
      79           0 : SfxPoolItem* SfxLockBytesItem::Create( SvStream &rStream, sal_uInt16 ) const
      80             : {
      81           0 :     sal_uInt32 nSize = 0;
      82           0 :     sal_uLong nActRead = 0;
      83             :     sal_Char cTmpBuf[MAX_BUF];
      84           0 :     SvMemoryStream aNewStream;
      85           0 :     rStream.ReadUInt32( nSize );
      86             : 
      87           0 :     do {
      88             :         sal_uLong nToRead;
      89           0 :         if( (nSize - nActRead) > MAX_BUF )
      90           0 :             nToRead = MAX_BUF;
      91             :         else
      92           0 :             nToRead = nSize - nActRead;
      93           0 :         nActRead += rStream.Read( cTmpBuf, nToRead );
      94           0 :         aNewStream.Write( cTmpBuf, nToRead );
      95           0 :     } while( nSize > nActRead );
      96             : 
      97           0 :     return new SfxLockBytesItem( Which(), aNewStream );
      98             : }
      99             : 
     100             : 
     101             : 
     102           0 : SvStream& SfxLockBytesItem::Store(SvStream &rStream, sal_uInt16 ) const
     103             : {
     104           0 :     SvStream aLockBytesStream( _xVal );
     105           0 :     sal_uInt32 nSize = aLockBytesStream.Seek( STREAM_SEEK_TO_END );
     106           0 :     aLockBytesStream.Seek( 0L );
     107             : 
     108           0 :     rStream.WriteUInt32( nSize );
     109           0 :     rStream.WriteStream( aLockBytesStream );
     110             : 
     111           0 :     return rStream;
     112             : }
     113             : 
     114             : // virtual
     115           0 : bool SfxLockBytesItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 )
     116             : {
     117           0 :     com::sun::star::uno::Sequence< sal_Int8 > aSeq;
     118           0 :     if ( rVal >>= aSeq )
     119             :     {
     120           0 :         if ( aSeq.getLength() )
     121             :         {
     122           0 :             SvMemoryStream* pStream = new SvMemoryStream();
     123           0 :             pStream->Write( (void*)aSeq.getConstArray(), aSeq.getLength() );
     124           0 :             pStream->Seek(0);
     125             : 
     126           0 :             _xVal = new SvLockBytes( pStream, true );
     127             :         }
     128             :         else
     129           0 :             _xVal = NULL;
     130             : 
     131           0 :         return true;
     132             :     }
     133             : 
     134             :     OSL_FAIL( "SfxLockBytesItem::PutValue - Wrong type!" );
     135           0 :     return true;
     136             : }
     137             : 
     138             : // virtual
     139           0 : bool SfxLockBytesItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 ) const
     140             : {
     141           0 :     if ( _xVal.Is() )
     142             :     {
     143             :         sal_uInt32 nLen;
     144           0 :         SvLockBytesStat aStat;
     145             : 
     146           0 :         if ( _xVal->Stat( &aStat, SVSTATFLAG_DEFAULT ) == ERRCODE_NONE )
     147           0 :             nLen = aStat.nSize;
     148             :         else
     149           0 :             return false;
     150             : 
     151           0 :         sal_uLong nRead = 0;
     152           0 :         com::sun::star::uno::Sequence< sal_Int8 > aSeq( nLen );
     153             : 
     154           0 :         _xVal->ReadAt( 0, aSeq.getArray(), nLen, &nRead );
     155           0 :         rVal <<= aSeq;
     156             :     }
     157             :     else
     158             :     {
     159           0 :         com::sun::star::uno::Sequence< sal_Int8 > aSeq( 0 );
     160           0 :         rVal <<= aSeq;
     161             :     }
     162             : 
     163           0 :     return true;
     164             : }
     165             : 
     166             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10