LCOV - code coverage report
Current view: top level - tools/source/rc - resary.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 33 37 89.2 %
Date: 2015-06-13 12:38:46 Functions: 11 13 84.6 %
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 <tools/resary.hxx>
      21             : #include <tools/resmgr.hxx>
      22             : #include <tools/rcid.h>
      23             : 
      24             : #include <vector>
      25             : 
      26             : namespace {
      27             : 
      28       43070 : struct ImplResStringItem
      29             : {
      30             :     OUString m_aStr;
      31             :     sal_IntPtr m_nValue;
      32             : 
      33       14818 :     ImplResStringItem( const OUString& rStr, long nValue = 0 ) :
      34             :         m_aStr(rStr),
      35       14818 :         m_nValue(nValue)
      36       14818 :     { }
      37             : };
      38             : 
      39             : }
      40             : 
      41        4224 : struct ResStringArray::Impl
      42             : {
      43             :     std::vector<ImplResStringItem> m_aStrings;
      44             : };
      45             : 
      46        2133 : ResStringArray::ResStringArray( const ResId& rResId ) :
      47        2133 :     mpImpl(new Impl)
      48             : {
      49        2133 :     rResId.SetRT( RSC_STRINGARRAY );
      50        2133 :     ResMgr* pMgr = rResId.GetResMgr();
      51        2133 :     if( pMgr && pMgr->GetResource( rResId ) )
      52             :     {
      53        2133 :         pMgr->GetClass();
      54        2133 :         pMgr->Increment( sizeof( RSHEADER_TYPE ) );
      55        2133 :         const sal_uInt32 nItems = pMgr->ReadLong();
      56        2133 :         if ( nItems )
      57             :         {
      58        2133 :             mpImpl->m_aStrings.reserve( nItems );
      59       16951 :             for ( sal_uInt32 i = 0; i < nItems; i++ )
      60             :             {
      61             :                 // load string
      62       14818 :                 mpImpl->m_aStrings.push_back(ImplResStringItem(pMgr->ReadString()));
      63             : 
      64             :                 // load value
      65       14818 :                 mpImpl->m_aStrings[i].m_nValue = pMgr->ReadLong();
      66             :             }
      67             :         }
      68             :     }
      69        2133 : }
      70             : 
      71        2091 : ResStringArray::~ResStringArray()
      72             : {
      73        2091 :     delete mpImpl;
      74        2091 : }
      75             : 
      76       30558 : OUString ResStringArray::GetString( sal_uInt32 nIndex ) const
      77             : {
      78       30558 :     return (nIndex < mpImpl->m_aStrings.size()) ? mpImpl->m_aStrings[nIndex].m_aStr : OUString();
      79             : }
      80             : 
      81         944 : sal_IntPtr ResStringArray::GetValue( sal_uInt32 nIndex ) const
      82             : {
      83         944 :     return (nIndex < mpImpl->m_aStrings.size()) ? mpImpl->m_aStrings[nIndex].m_nValue : -1;
      84             : }
      85             : 
      86        4565 : sal_uInt32 ResStringArray::Count() const
      87             : {
      88        4565 :     return sal_uInt32(mpImpl->m_aStrings.size());
      89             : }
      90             : 
      91         547 : sal_uInt32 ResStringArray::FindIndex( sal_IntPtr nValue ) const
      92             : {
      93         547 :     const sal_uInt32 nItems = mpImpl->m_aStrings.size();
      94       29695 :     for ( sal_uInt32 i = 0; i < nItems; i++ )
      95             :     {
      96       29695 :         if (mpImpl->m_aStrings[i].m_nValue == nValue)
      97         547 :             return i;
      98             :     }
      99           0 :     return RESARRAY_INDEX_NOTFOUND;
     100             : }
     101             : 
     102           0 : sal_uInt32 ResStringArray::AddItem( const OUString& rString, sal_IntPtr nValue )
     103             : {
     104           0 :     mpImpl->m_aStrings.push_back(ImplResStringItem(rString, nValue));
     105           0 :     return mpImpl->m_aStrings.size();
     106             : }
     107             : 
     108             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11