LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter - bencont.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 74 114 64.9 %
Date: 2015-06-13 12:38:46 Functions: 14 16 87.5 %
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             :  *
       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 <osl/diagnose.h>
      60             : #include <sot/storinfo.hxx>
      61             : namespace OpenStormBento
      62             : {
      63             : 
      64             : // String definitions
      65             : const char gsBenMagicBytes[] = BEN_MAGIC_BYTES;
      66             : 
      67             : /**
      68             : *   New bento container from file stream
      69             : *   @param  pointer to length of bento file
      70             : *   @param  pointer to pointer of Bento Container object
      71             : *   @return error code
      72             : */
      73           4 : sal_uLong BenOpenContainer(LwpSvStream * pStream, pLtcBenContainer * ppContainer)
      74             : {
      75             :     BenError Err;
      76             : 
      77           4 :     *ppContainer = NULL;
      78             : 
      79           4 :     if (NULL == pStream)
      80             :     {
      81           0 :         return BenErr_ContainerWithNoObjects;
      82             :     }
      83             : 
      84           4 :     pLtcBenContainer pContainer = new LtcBenContainer(pStream);
      85           4 :     if ((Err = pContainer->Open()) != BenErr_OK) // delete two inputs
      86             :     {
      87           0 :         delete pContainer;
      88           0 :         return BenErr_InvalidTOC;
      89             :     }
      90             : 
      91           4 :     *ppContainer = pContainer;
      92           4 :     return BenErr_OK;
      93             : }
      94             : 
      95           4 : LtcBenContainer::~LtcBenContainer()
      96             : {
      97           4 : }
      98             : 
      99             : BenError
     100           4 : LtcBenContainer::Open() // delete two inputs
     101             : {
     102             :     BenError Err;
     103           4 :     CBenTOCReader TOCReader(this);
     104           4 :     if ((Err = TOCReader.ReadLabelAndTOC()) != BenErr_OK)
     105             :     {
     106           0 :         return Err;
     107             :     }
     108           4 :     return BenErr_OK;
     109             : }
     110             : 
     111             : BenError
     112           8 : LtcBenContainer::RegisterPropertyName(const char * sPropertyName,
     113             :   pCBenPropertyName * ppPropertyName)
     114             : {
     115             :     pCUtListElmt pPrevNamedObjectListElmt;
     116             :     pCBenNamedObject pNamedObject = FindNamedObject(&cNamedObjects,
     117           8 :       sPropertyName, &pPrevNamedObjectListElmt);
     118             : 
     119           8 :     if (pNamedObject != NULL)
     120             :     {
     121           0 :         if (! pNamedObject->IsPropertyName())
     122           0 :             return BenErr_NameConflict;
     123           0 :         else *ppPropertyName = static_cast<pCBenPropertyName>(pNamedObject);
     124             :     }
     125             :     else
     126             :     {
     127             :         pCUtListElmt pPrevObject;
     128           8 :         if (FindID(&cObjects, cNextAvailObjectID, &pPrevObject) != NULL)
     129           0 :             return BenErr_DuplicateObjectID;
     130             : 
     131             :         *ppPropertyName = new CBenPropertyName(this, cNextAvailObjectID,
     132           8 :           static_cast<pCBenObject>(pPrevObject), sPropertyName, pPrevNamedObjectListElmt);
     133           8 :         ++cNextAvailObjectID;
     134             :     }
     135             : 
     136           8 :     return BenErr_OK;
     137             : }
     138             : 
     139             : pCBenObject
     140         412 : LtcBenContainer::GetNextObject(pCBenObject pCurrObject)
     141             : {
     142         412 :     return static_cast<pCBenObject>(cObjects.GetNextOrNULL(pCurrObject));
     143             : }
     144             : 
     145             : pCBenObject
     146           8 : LtcBenContainer::FindNextObjectWithProperty(pCBenObject pCurrObject,
     147             :   BenObjectID PropertyID)
     148             : {
     149         420 :     while ((pCurrObject = GetNextObject(pCurrObject)) != NULL)
     150         404 :         if (pCurrObject->UseProperty(PropertyID) != NULL)
     151           0 :             return pCurrObject;
     152             : 
     153           8 :     return NULL;
     154             : }
     155             : 
     156             : /**
     157             : *   Construction
     158             : *   @param  Bento file stream pointer
     159             : *   @return
     160             : */
     161           4 : LtcBenContainer::LtcBenContainer(LwpSvStream * pStream)
     162           4 :     : cNextAvailObjectID(0)
     163             : {
     164           4 :     cpStream = pStream;
     165           4 :     pStream->Seek(STREAM_SEEK_TO_END);
     166           4 :     m_ulLength = pStream->Tell();
     167           4 :     pStream->Seek(STREAM_SEEK_TO_BEGIN);
     168           4 : }
     169             : 
     170             : /**
     171             : *   Read buffer fro bento file with specified buffer
     172             : *   @date   07/05/2004
     173             : *   @param  buffer pointer
     174             : *   @param  buffer size
     175             : *   @param  number of bytes read
     176             : *   @return BenError
     177             : */
     178           0 : BenError LtcBenContainer::Read(BenDataPtr pBuffer, unsigned long MaxSize,
     179             :   unsigned long * pAmtRead)
     180             : {
     181           0 :     *pAmtRead = cpStream->Read(pBuffer, MaxSize);
     182           0 :     return BenErr_OK;
     183             : }
     184             : /**
     185             : *   Read buffer from bento file with specified size
     186             : *   @date   07/05/2004
     187             : *   @param  buffer pointer
     188             : *   @param  number of bytes to be read
     189             : *   @return BenError
     190             : */
     191          62 : BenError LtcBenContainer::ReadKnownSize(BenDataPtr pBuffer, unsigned long Amt)
     192             : {
     193             :     sal_uLong ulLength;
     194          62 :     ulLength = cpStream->Read(pBuffer, Amt);
     195          62 :     if(ulLength == Amt)
     196             :     {
     197          62 :         return BenErr_OK;
     198             :     }
     199           0 :     return BenErr_ReadPastEndOfContainer;
     200             : }
     201             : /**
     202             : *   Seek to position from the beginning of the bento file
     203             : *   @date   07/05/2004
     204             : *   @param  position in container file from beginning
     205             : *   @return BenError
     206             : */
     207          58 : BenError LtcBenContainer::SeekToPosition(BenContainerPos Pos)
     208             : {
     209          58 :     cpStream->Seek(Pos);
     210          58 :     return BenErr_OK;
     211             : }
     212             : /**
     213             : *   Seek to position compare to end of bento file
     214             : *   @date   07/05/2004
     215             : *   @param  position in container file from end
     216             : *   @return BenError
     217             : */
     218           4 : BenError LtcBenContainer::SeekFromEnd(long Offset)
     219             : {
     220           4 :     cpStream->Seek(STREAM_SEEK_TO_END);
     221           4 :     cpStream->SeekRel(Offset);
     222             : 
     223           4 :     return BenErr_OK;
     224             : }
     225             : /**
     226             : *   Find the next value stream with property name
     227             : *   @date   07/05/2004
     228             : *   @param  string of property name
     229             : *   @param  current value stream pointer with the property name
     230             : *   @return next value stream pointer with the property names
     231             : */
     232           8 : LtcUtBenValueStream * LtcBenContainer::FindNextValueStreamWithPropertyName(const char * sPropertyName, LtcUtBenValueStream * pCurrentValueStream)
     233             : {
     234             :     CBenPropertyName * pPropertyName;
     235           8 :     RegisterPropertyName(sPropertyName, &pPropertyName);        // Get property name object
     236             : 
     237           8 :     if (NULL == pPropertyName)
     238           0 :         return NULL;                                            // Property not exist
     239             : 
     240             :     // Get current object
     241           8 :     CBenObject * pObj = NULL;
     242           8 :     if (pCurrentValueStream != NULL)
     243             :     {
     244           0 :         pObj = pCurrentValueStream->GetValue()->GetProperty()->GetBenObject();
     245             :     }
     246             : 
     247           8 :     pObj =FindNextObjectWithProperty(pObj, pPropertyName->GetID()); // Get next object with same property name
     248           8 :     if (NULL == pObj)
     249           8 :         return NULL;
     250             : 
     251             :     CBenValue * pValue;
     252             :     LtcUtBenValueStream * pValueStream;
     253             : 
     254           0 :     pValue = pObj->UseValue(pPropertyName->GetID());
     255             : 
     256           0 :     pValueStream = new LtcUtBenValueStream(pValue);
     257             : 
     258           0 :     return pValueStream;
     259             : }
     260             : 
     261             : /**
     262             : *   Find the unique value stream with property name
     263             : *   @date   07/05/2004
     264             : *   @param  string of property name
     265             : *   @return the only value stream pointer with the property names
     266             : */
     267           8 : LtcUtBenValueStream * LtcBenContainer::FindValueStreamWithPropertyName(const char * sPropertyName)
     268             : {
     269           8 :     return FindNextValueStreamWithPropertyName(sPropertyName, NULL);
     270             : }
     271             : /**
     272             : *   <description>
     273             : *   @date   07/05/2004
     274             : *   @param  pointer to length of bento file
     275             : *   @return BenError
     276             : */
     277           4 : BenError LtcBenContainer::GetSize(sal_uLong * pLength)
     278             : {
     279           4 :     *pLength = m_ulLength;
     280           4 :     return BenErr_OK;
     281             : }
     282             : 
     283           0 : sal_uInt32 GetSvStreamSize(SvStream * pStream)
     284             : {
     285           0 :     sal_uInt32 nCurPos = pStream->Tell();
     286           0 :     pStream->Seek(STREAM_SEEK_TO_END);
     287           0 :     sal_uInt32 ulLength = pStream->Tell();
     288           0 :     pStream->Seek(nCurPos);
     289             : 
     290           0 :     return ulLength;
     291             : }
     292             : 
     293             : /**
     294             : *   Find hazily according to object ID
     295             : *   @date   01/31/2005
     296             : *   @param  pObjectname - format as "GrXX,XXXXXXXX" wherein XX is high part of object ID, and XXXXXXXX is low part
     297             : *   @return the value stream pointers  with the property names
     298             : */
     299           4 : BenError LtcBenContainer::CreateGraphicStream(SvStream * &pStream, const char *pObjectName)
     300             : {
     301           4 :     if (!pObjectName)
     302             :     {
     303           0 :         pStream = NULL;
     304           0 :         return BenErr_NamedObjectError;
     305             :     }
     306             :     // construct the string of property name
     307           4 :     char sSName[64]="";
     308           4 :     char sDName[64]="";
     309             : 
     310           4 :     sprintf(sSName, "%s-S", pObjectName);
     311           4 :     sprintf(sDName, "%s-D", pObjectName);
     312             : 
     313             :     /* traverse the found properties and construct the stream vectors */
     314           4 :     SvMemoryStream * pMemStream = NULL;
     315             :     // get S&D's stream and merge them together
     316           4 :     SvStream *pD = NULL, *pS = NULL;
     317             : 
     318           4 :     pS = FindValueStreamWithPropertyName(sSName);
     319           4 :     pD = FindValueStreamWithPropertyName(sDName);
     320             : 
     321           4 :     sal_uInt32 nDLen = 0;
     322           4 :     if(pD)
     323             :     {
     324           0 :         nDLen = GetSvStreamSize(pD);
     325             :     }
     326           4 :     sal_uInt32 nLen = nDLen;
     327           4 :     if(pS)
     328             :     {
     329           0 :         nLen += GetSvStreamSize(pS) ;
     330             :     }
     331             : 
     332             :     OSL_ENSURE(nLen > 0, "expected a non-0 length");
     333             :     // the 'D' stream is NULL or it has invalid length
     334           4 :     if (nLen <= 0)
     335             :     {
     336           4 :         pStream = NULL;
     337           4 :         return BenErr_NamedObjectError;
     338             :     }
     339             : 
     340           0 :     char * pBuf = new char[nLen];
     341             :     assert(pBuf != NULL);
     342           0 :     char * pPointer = pBuf;
     343           0 :     if(pD)
     344             :     {
     345           0 :         pD->Read(pPointer, nDLen);
     346           0 :         delete pD;
     347             :     }
     348           0 :     pPointer += nDLen;
     349           0 :     if(pS)
     350             :     {
     351           0 :         pS->Read(pPointer, nLen - nDLen);
     352           0 :         delete pS;
     353             :     }
     354             : 
     355           0 :     pMemStream = new SvMemoryStream(pBuf, nLen, StreamMode::READ);
     356             :     assert(pMemStream != NULL);
     357             : 
     358           0 :     pStream = pMemStream;
     359           0 :     return BenErr_OK;
     360             : }
     361             : 
     362             : }// end namespace OpenStormBento
     363             : 
     364             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11