LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter - bencont.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 76 116 65.5 %
Date: 2012-08-25 Functions: 14 17 82.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 31 98 31.6 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  *  The Contents of this file are made available subject to the terms of
       5                 :            :  *  either of the following licenses
       6                 :            :  *
       7                 :            :  *         - GNU Lesser General Public License Version 2.1
       8                 :            :  *         - Sun Industry Standards Source License Version 1.1
       9                 :            :  *
      10                 :            :  *  Sun Microsystems Inc., October, 2000
      11                 :            :  *
      12                 :            :  *  GNU Lesser General Public License Version 2.1
      13                 :            :  *  =============================================
      14                 :            :  *  Copyright 2000 by Sun Microsystems, Inc.
      15                 :            :  *  901 San Antonio Road, Palo Alto, CA 94303, USA
      16                 :            :  *
      17                 :            :  *  This library is free software; you can redistribute it and/or
      18                 :            :  *  modify it under the terms of the GNU Lesser General Public
      19                 :            :  *  License version 2.1, as published by the Free Software Foundation.
      20                 :            :  *
      21                 :            :  *  This library is distributed in the hope that it will be useful,
      22                 :            :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      23                 :            :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      24                 :            :  *  Lesser General Public License for more details.
      25                 :            :  *
      26                 :            :  *  You should have received a copy of the GNU Lesser General Public
      27                 :            :  *  License along with this library; if not, write to the Free Software
      28                 :            :  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
      29                 :            :  *  MA  02111-1307  USA
      30                 :            :  *
      31                 :            :  *
      32                 :            :  *  Sun Industry Standards Source License Version 1.1
      33                 :            :  *  =================================================
      34                 :            :  *  The contents of this file are subject to the Sun Industry Standards
      35                 :            :  *  Source License Version 1.1 (the "License"); You may not use this file
      36                 :            :  *  except in compliance with the License. You may obtain a copy of the
      37                 :            :  *  License at http://www.openoffice.org/license.html.
      38                 :            :  *
      39                 :            :  *  Software provided under this License is provided on an "AS IS" basis,
      40                 :            :  *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
      41                 :            :  *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
      42                 :            :  *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
      43                 :            :  *  See the License for the specific provisions governing your rights and
      44                 :            :  *  obligations concerning the Software.
      45                 :            :  *
      46                 :            :  *  The Initial Developer of the Original Code is: IBM Corporation
      47                 :            :  *
      48                 :            :  *  Copyright: 2008 by IBM Corporation
      49                 :            :  *
      50                 :            :  *  All Rights Reserved.
      51                 :            :  *
      52                 :            :  *  Contributor(s): _______________________________________
      53                 :            :  *
      54                 :            :  *
      55                 :            :  ************************************************************************/
      56                 :            : #include "first.hxx"
      57                 :            : #include "assert.h"
      58                 :            : #include <stdio.h>
      59                 :            : #include <sot/storinfo.hxx>
      60                 :            : namespace OpenStormBento
      61                 :            : {
      62                 :            : 
      63                 :            : // String definitions
      64                 :            : const char gsBenMagicBytes[] = BEN_MAGIC_BYTES;
      65                 :            : 
      66                 :            : /**
      67                 :            : *   New bento container from file stream
      68                 :            : *   @param  pointer to length of bento file
      69                 :            : *   @param  pointer to pointer of Bento Container object
      70                 :            : *   @return error code
      71                 :            : */
      72                 :         12 : sal_uLong BenOpenContainer(LwpSvStream * pStream, pLtcBenContainer * ppContainer)
      73                 :            : {
      74                 :            :     BenError Err;
      75                 :            : 
      76                 :         12 :     *ppContainer = NULL;
      77                 :            : 
      78         [ -  + ]:         12 :     if (NULL == pStream)
      79                 :            :     {
      80                 :          0 :         return BenErr_ContainerWithNoObjects;
      81                 :            :     }
      82                 :            : 
      83         [ +  - ]:         12 :     pLtcBenContainer pContainer = new LtcBenContainer(pStream);
      84         [ -  + ]:         12 :     if ((Err = pContainer->Open()) != BenErr_OK) // delete two inputs
      85                 :            :     {
      86         [ #  # ]:          0 :         delete pContainer;
      87                 :          0 :         return BenErr_InvalidTOC;
      88                 :            :     }
      89                 :            : 
      90                 :         12 :     *ppContainer = pContainer;
      91                 :         12 :     return BenErr_OK;
      92                 :            : }
      93                 :            : BenError
      94                 :         12 : LtcBenContainer::Close()
      95                 :            : {
      96                 :         12 :     return BenErr_OK;
      97                 :            : }
      98                 :            : 
      99         [ +  - ]:         12 : LtcBenContainer::~LtcBenContainer()
     100                 :            : {
     101                 :         12 :     Close();
     102                 :         12 : }
     103                 :            : 
     104                 :            : BenError
     105                 :         12 : LtcBenContainer::Open() // delete two inputs
     106                 :            : {
     107                 :            :     BenError Err;
     108                 :         12 :     CBenTOCReader TOCReader(this);
     109 [ -  + ][ +  - ]:         12 :     if ((Err = TOCReader.ReadLabelAndTOC()) != BenErr_OK)
     110                 :            :     {
     111                 :          0 :         return Err;
     112                 :            :     }
     113                 :         12 :     return BenErr_OK;
     114                 :            : }
     115                 :            : 
     116                 :            : BenError
     117                 :         24 : LtcBenContainer::RegisterPropertyName(const char * sPropertyName,
     118                 :            :   pCBenPropertyName * ppPropertyName)
     119                 :            : {
     120                 :            :     pCBenNamedObjectListElmt pPrevNamedObjectListElmt;
     121                 :            :     pCBenNamedObject pNamedObject = FindNamedObject(&cNamedObjects,
     122         [ +  - ]:         24 :       sPropertyName, &pPrevNamedObjectListElmt);
     123                 :            : 
     124         [ -  + ]:         24 :     if (pNamedObject != NULL)
     125                 :            :     {
     126 [ #  # ][ #  # ]:          0 :         if (! pNamedObject->IsPropertyName())
     127                 :          0 :             return BenErr_NameConflict;
     128                 :          0 :         else *ppPropertyName = (pCBenPropertyName) pNamedObject;
     129                 :            :     }
     130                 :            :     else
     131                 :            :     {
     132                 :            :         pCBenIDListElmt pPrevObject;
     133 [ +  - ][ -  + ]:         24 :         if (FindID(&cObjects, cNextAvailObjectID, &pPrevObject) != NULL)
     134                 :          0 :             return BenErr_DuplicateObjectID;
     135                 :            : 
     136                 :            :         *ppPropertyName = new CBenPropertyName(this, cNextAvailObjectID,
     137 [ +  - ][ +  - ]:         24 :           (pCBenObject) pPrevObject, sPropertyName, pPrevNamedObjectListElmt);
     138                 :         24 :         ++cNextAvailObjectID;
     139                 :            :     }
     140                 :            : 
     141                 :         24 :     return BenErr_OK;
     142                 :            : }
     143                 :            : 
     144                 :            : pCBenObject
     145                 :       1236 : LtcBenContainer::GetNextObject(pCBenObject pCurrObject)
     146                 :            : {
     147                 :       1236 :     return (pCBenObject) cObjects.GetNextOrNULL(pCurrObject);
     148                 :            : }
     149                 :            : 
     150                 :            : pCBenObject
     151                 :         24 : LtcBenContainer::FindNextObjectWithProperty(pCBenObject pCurrObject,
     152                 :            :   BenObjectID PropertyID)
     153                 :            : {
     154         [ +  + ]:       1236 :     while ((pCurrObject = GetNextObject(pCurrObject)) != NULL)
     155         [ -  + ]:       1212 :         if (pCurrObject->UseProperty(PropertyID) != NULL)
     156                 :          0 :             return pCurrObject;
     157                 :            : 
     158                 :         24 :     return NULL;
     159                 :            : }
     160                 :            : 
     161                 :            : /**
     162                 :            : *   Construction
     163                 :            : *   @param  Bento file stream pointer
     164                 :            : *   @return
     165                 :            : */
     166         [ +  - ]:         12 : LtcBenContainer::LtcBenContainer(LwpSvStream * pStream)
     167                 :            : {
     168                 :         12 :     cpStream = pStream;
     169         [ +  - ]:         12 :     pStream->Seek(STREAM_SEEK_TO_END);
     170         [ +  - ]:         12 :     m_ulLength = pStream->Tell();
     171         [ +  - ]:         12 :     pStream->Seek(STREAM_SEEK_TO_BEGIN);
     172                 :         12 : }
     173                 :            : 
     174                 :            : /**
     175                 :            : *   Read buffer fro bento file with specified buffer
     176                 :            : *   @date   07/05/2004
     177                 :            : *   @param  buffer pointer
     178                 :            : *   @param  buffer size
     179                 :            : *   @param  number of bytes read
     180                 :            : *   @return BenError
     181                 :            : */
     182                 :          0 : BenError LtcBenContainer::Read(BenDataPtr pBuffer, unsigned long MaxSize,
     183                 :            :   unsigned long * pAmtRead)
     184                 :            : {
     185                 :          0 :     *pAmtRead = cpStream->Read(pBuffer, MaxSize);
     186                 :          0 :     return BenErr_OK;
     187                 :            : }
     188                 :            : /**
     189                 :            : *   Read buffer from bento file with specified size
     190                 :            : *   @date   07/05/2004
     191                 :            : *   @param  buffer pointer
     192                 :            : *   @param  number of bytes to be read
     193                 :            : *   @return BenError
     194                 :            : */
     195                 :        186 : BenError LtcBenContainer::ReadKnownSize(BenDataPtr pBuffer, unsigned long Amt)
     196                 :            : {
     197                 :            :     sal_uLong ulLength;
     198                 :        186 :     ulLength = cpStream->Read(pBuffer, Amt);
     199         [ +  - ]:        186 :     if(ulLength == Amt)
     200                 :            :     {
     201                 :        186 :         return BenErr_OK;
     202                 :            :     }
     203                 :        186 :     return BenErr_ReadPastEndOfContainer;
     204                 :            : }
     205                 :            : /**
     206                 :            : *   Seek to position from the beginning of the bento file
     207                 :            : *   @date   07/05/2004
     208                 :            : *   @param  position in container file from beginning
     209                 :            : *   @return BenError
     210                 :            : */
     211                 :        174 : BenError LtcBenContainer::SeekToPosition(BenContainerPos Pos)
     212                 :            : {
     213                 :        174 :     cpStream->Seek(Pos);
     214                 :        174 :     return BenErr_OK;
     215                 :            : }
     216                 :            : /**
     217                 :            : *   Seek to position compare to end of bento file
     218                 :            : *   @date   07/05/2004
     219                 :            : *   @param  position in container file from end
     220                 :            : *   @return BenError
     221                 :            : */
     222                 :         12 : BenError LtcBenContainer::SeekFromEnd(long Offset)
     223                 :            : {
     224                 :         12 :     cpStream->Seek(STREAM_SEEK_TO_END);
     225                 :         12 :     cpStream->SeekRel(Offset);
     226                 :            : 
     227                 :         12 :     return BenErr_OK;
     228                 :            : }
     229                 :            : /**
     230                 :            : *   Find the next value stream with property name
     231                 :            : *   @date   07/05/2004
     232                 :            : *   @param  string of property name
     233                 :            : *   @param  current value stream pointer with the property name
     234                 :            : *   @return next value stream pointer with the property names
     235                 :            : */
     236                 :         24 : LtcUtBenValueStream * LtcBenContainer::FindNextValueStreamWithPropertyName(const char * sPropertyName, LtcUtBenValueStream * pCurrentValueStream)
     237                 :            : {
     238                 :            :     CBenPropertyName * pPropertyName;
     239         [ +  - ]:         24 :     RegisterPropertyName(sPropertyName, &pPropertyName);        // Get property name object
     240                 :            : 
     241         [ -  + ]:         24 :     if (NULL == pPropertyName)
     242                 :          0 :         return NULL;                                            // Property not exist
     243                 :            : 
     244                 :            :     // Get current object
     245                 :         24 :     CBenObject * pObj = NULL;
     246         [ -  + ]:         24 :     if (pCurrentValueStream != NULL)
     247                 :            :     {
     248                 :          0 :         pObj = pCurrentValueStream->GetValue()->GetProperty()->GetBenObject();
     249                 :            :     }
     250                 :            : 
     251                 :            : 
     252         [ +  - ]:         24 :     pObj =FindNextObjectWithProperty(pObj, pPropertyName->GetID()); // Get next object with same property name
     253         [ +  - ]:         24 :     if (NULL == pObj)
     254                 :         24 :         return NULL;
     255                 :            : 
     256                 :            :     CBenValue * pValue;
     257                 :            :     LtcUtBenValueStream * pValueStream;
     258                 :            : 
     259         [ #  # ]:          0 :     pValue = pObj->UseValue(pPropertyName->GetID());
     260                 :            : 
     261 [ #  # ][ #  # ]:          0 :     pValueStream = new LtcUtBenValueStream(pValue);
     262                 :            : 
     263                 :         24 :     return pValueStream;
     264                 :            : }
     265                 :            : 
     266                 :            : /**
     267                 :            : *   Find the unique value stream with property name
     268                 :            : *   @date   07/05/2004
     269                 :            : *   @param  string of property name
     270                 :            : *   @return the only value stream pointer with the property names
     271                 :            : */
     272                 :         24 : LtcUtBenValueStream * LtcBenContainer::FindValueStreamWithPropertyName(const char * sPropertyName)
     273                 :            : {
     274                 :         24 :     return FindNextValueStreamWithPropertyName(sPropertyName, NULL);
     275                 :            : }
     276                 :            : /**
     277                 :            : *   <description>
     278                 :            : *   @date   07/05/2004
     279                 :            : *   @param  pointer to length of bento file
     280                 :            : *   @return BenError
     281                 :            : */
     282                 :          0 : BenError LtcBenContainer::GetSize(sal_uLong * pLength)
     283                 :            : {
     284                 :          0 :     *pLength = m_ulLength;
     285                 :          0 :     return BenErr_OK;
     286                 :            : }
     287                 :            : 
     288                 :          0 : sal_uInt32 GetSvStreamSize(SvStream * pStream)
     289                 :            : {
     290                 :          0 :     sal_uInt32 nCurPos = pStream->Tell();
     291                 :          0 :     pStream->Seek(STREAM_SEEK_TO_END);
     292                 :          0 :     sal_uInt32 ulLength = pStream->Tell();
     293                 :          0 :     pStream->Seek(nCurPos);
     294                 :            : 
     295                 :          0 :     return ulLength;
     296                 :            : }
     297                 :            : 
     298                 :            : /**
     299                 :            : *   Find hazily according to object ID
     300                 :            : *   @date   01/31/2005
     301                 :            : *   @param  pObjectname - format as "GrXX,XXXXXXXX" wherein XX is high part of object ID, and XXXXXXXX is low part
     302                 :            : *   @return the value stream pointers  with the property names
     303                 :            : */
     304                 :         12 : BenError LtcBenContainer::CreateGraphicStream(SvStream * &pStream, const char *pObjectName)
     305                 :            : {
     306         [ -  + ]:         12 :     if (!pObjectName)
     307                 :            :     {
     308                 :          0 :         pStream = NULL;
     309                 :          0 :         return BenErr_NamedObjectError;
     310                 :            :     }
     311                 :            :     // construct the string of property name
     312                 :         12 :     char sSName[64]="";
     313                 :         12 :     char sDName[64]="";
     314                 :            : 
     315                 :         12 :     sprintf(sSName, "%s-S", pObjectName);
     316                 :         12 :     sprintf(sDName, "%s-D", pObjectName);
     317                 :            : 
     318                 :            :     /* traverse the found properties and construct the stream vectors */
     319                 :         12 :     SvMemoryStream * pMemStream = NULL;
     320                 :            :     // get S&D's stream and merge them together
     321                 :         12 :     SvStream *pD = NULL, *pS = NULL;
     322                 :            : 
     323         [ +  - ]:         12 :     pS = FindValueStreamWithPropertyName(sSName);
     324         [ +  - ]:         12 :     pD = FindValueStreamWithPropertyName(sDName);
     325                 :            : 
     326                 :            : 
     327                 :         12 :     sal_uInt32 nDLen = 0;
     328         [ -  + ]:         12 :     if(pD)
     329                 :            :     {
     330         [ #  # ]:          0 :         nDLen = GetSvStreamSize(pD);
     331                 :            :     }
     332                 :         12 :     sal_uInt32 nLen = nDLen;
     333         [ -  + ]:         12 :     if(pS)
     334                 :            :     {
     335         [ #  # ]:          0 :         nLen += GetSvStreamSize(pS) ;
     336                 :            :     }
     337                 :            : 
     338                 :            :     OSL_ENSURE(nLen > 0, "expected a non-0 length");
     339                 :            :     // the 'D' stream is NULL or it has invalid length
     340         [ +  - ]:         12 :     if (nLen <= 0)
     341                 :            :     {
     342                 :         12 :         pStream = NULL;
     343                 :         12 :         return BenErr_NamedObjectError;
     344                 :            :     }
     345                 :            : 
     346         [ #  # ]:          0 :     char * pBuf = new char[nLen];
     347                 :            :     assert(pBuf != NULL);
     348                 :          0 :     char * pPointer = pBuf;
     349         [ #  # ]:          0 :     if(pD)
     350                 :            :     {
     351         [ #  # ]:          0 :         pD->Read(pPointer, nDLen);
     352 [ #  # ][ #  # ]:          0 :         delete pD;
     353                 :            :     }
     354                 :          0 :     pPointer += nDLen;
     355         [ #  # ]:          0 :     if(pS)
     356                 :            :     {
     357         [ #  # ]:          0 :         pS->Read(pPointer, nLen - nDLen);
     358 [ #  # ][ #  # ]:          0 :         delete pS;
     359                 :            :     }
     360                 :            : 
     361 [ #  # ][ #  # ]:          0 :     pMemStream = new SvMemoryStream(pBuf, nLen, STREAM_READ);
     362                 :            :     assert(pMemStream != NULL);
     363                 :            : 
     364                 :          0 :     pStream = pMemStream;
     365                 :         12 :     return BenErr_OK;
     366                 :            : }
     367                 :            : 
     368                 :            : }// end namespace OpenStormBento
     369                 :            : 
     370                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10