LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/writerfilter/source/rtftok - rtfsprm.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 67 89 75.3 %
Date: 2013-07-09 Functions: 16 21 76.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             : 
      10             : #include <rtfsprm.hxx>
      11             : #include <rtl/strbuf.hxx>
      12             : 
      13             : #include <resourcemodel/QNameToString.hxx>
      14             : #include <doctok/resourceids.hxx> // NS_rtf namespace
      15             : 
      16             : 
      17             : namespace writerfilter {
      18             : namespace rtftok {
      19             : 
      20       22050 : RTFSprm::RTFSprm(Id nKeyword, RTFValue::Pointer_t& pValue)
      21             :     : m_nKeyword(nKeyword),
      22       22050 :     m_pValue(pValue)
      23             : {
      24       22050 : }
      25             : 
      26       79386 : sal_uInt32 RTFSprm::getId() const
      27             : {
      28       79386 :     return m_nKeyword;
      29             : }
      30             : 
      31       60069 : Value::Pointer_t RTFSprm::getValue()
      32             : {
      33       60069 :     return Value::Pointer_t(m_pValue->Clone());
      34             : }
      35             : 
      36           0 : writerfilter::Reference<BinaryObj>::Pointer_t RTFSprm::getBinary()
      37             : {
      38           0 :     return m_pValue->getBinary();
      39             : }
      40             : 
      41           0 : writerfilter::Reference<Stream>::Pointer_t RTFSprm::getStream()
      42             : {
      43           0 :     return m_pValue->getStream();
      44             : }
      45             : 
      46        2074 : writerfilter::Reference<Properties>::Pointer_t RTFSprm::getProps()
      47             : {
      48        2074 :     return m_pValue->getProperties();
      49             : }
      50             : 
      51           0 : Sprm::Kind RTFSprm::getKind()
      52             : {
      53           0 :     return Sprm::UNKNOWN;
      54             : }
      55             : 
      56           0 : std::string RTFSprm::getName() const
      57             : {
      58           0 :     return "RTFSprm";
      59             : }
      60             : 
      61           0 : std::string RTFSprm::toString() const
      62             : {
      63           0 :     OStringBuffer aBuf("RTFSprm");
      64             : 
      65           0 :     std::string sResult = (*QNameToString::Instance())(m_nKeyword);
      66           0 :     if (sResult.length() == 0)
      67           0 :         sResult = (*SprmIdToString::Instance())(m_nKeyword);
      68             : 
      69           0 :     aBuf.append(" ('");
      70           0 :     if (sResult.length() == 0)
      71           0 :         aBuf.append(sal_Int32(m_nKeyword));
      72             :     else
      73           0 :         aBuf.append(sResult.c_str());
      74           0 :     aBuf.append("', '");
      75           0 :     aBuf.append(m_pValue->toString().c_str());
      76           0 :     aBuf.append("')");
      77             : 
      78           0 :     return aBuf.makeStringAndClear().getStr();
      79             : }
      80             : 
      81       19314 : RTFValue::Pointer_t RTFSprms::find(Id nKeyword, bool bFirst)
      82             : {
      83       19314 :     RTFValue::Pointer_t pValue;
      84       57676 :     for (RTFSprms::Iterator_t i = m_pSprms->begin(); i != m_pSprms->end(); ++i)
      85       43507 :         if (i->first == nKeyword)
      86             :         {
      87        5145 :             if (bFirst)
      88        5145 :                 return i->second;
      89             :             else
      90           0 :                 pValue = i->second;
      91             :         }
      92       14169 :     return pValue;
      93             : }
      94             : 
      95       24880 : void RTFSprms::set(Id nKeyword, RTFValue::Pointer_t pValue, bool bOverwrite)
      96             : {
      97       24880 :     ensureCopyBeforeWrite();
      98       24880 :     if (bOverwrite)
      99             :     {
     100       72542 :         for (RTFSprms::Iterator_t i = m_pSprms->begin(); i != m_pSprms->end(); ++i)
     101       53436 :             if (i->first == nKeyword)
     102             :             {
     103        3942 :                 i->second = pValue;
     104       28822 :                 return;
     105             :             }
     106             :     }
     107       20938 :     m_pSprms->push_back(std::make_pair(nKeyword, pValue));
     108             : }
     109             : 
     110         885 : bool RTFSprms::erase(Id nKeyword)
     111             : {
     112         885 :     ensureCopyBeforeWrite();
     113        7038 :     for (RTFSprms::Iterator_t i = m_pSprms->begin(); i != m_pSprms->end(); ++i)
     114             :     {
     115        6676 :         if (i->first == nKeyword)
     116             :         {
     117         523 :             m_pSprms->erase(i);
     118         523 :             return true;
     119             :         }
     120             :     }
     121         362 :     return false;
     122             : }
     123             : 
     124         556 : void RTFSprms::deduplicate(RTFSprms& rReference)
     125             : {
     126         556 :     ensureCopyBeforeWrite();
     127             : 
     128         556 :     RTFSprms::Iterator_t i = m_pSprms->begin();
     129        3148 :     while (i != m_pSprms->end())
     130             :     {
     131        2036 :         bool bIgnore = false;
     132        2036 :         if (i->first != NS_rtf::LN_ISTD)
     133             :         {
     134        1905 :             RTFValue::Pointer_t pValue(rReference.find(i->first));
     135        1905 :             if (pValue.get() && i->second->equals(*pValue))
     136        1324 :                 bIgnore = true;
     137             :         }
     138        2036 :         if (bIgnore)
     139        1324 :             i = m_pSprms->erase(i);
     140             :         else
     141         712 :             ++i;
     142             :     }
     143         556 : }
     144             : 
     145       26321 : void RTFSprms::ensureCopyBeforeWrite()
     146             : {
     147       26321 :     if (m_pSprms->m_nRefCount > 1) {
     148        5890 :         boost::intrusive_ptr<RTFSprmsImpl> pClone(new RTFSprmsImpl());
     149       11759 :         for (std::vector< std::pair<Id, RTFValue::Pointer_t> >::const_iterator i = m_pSprms->begin(); i != m_pSprms->end(); ++i)
     150        5869 :             pClone->push_back(std::make_pair(i->first, RTFValue::Pointer_t(i->second->Clone())));
     151        5890 :         m_pSprms = pClone;
     152             :     }
     153       26321 : }
     154             : 
     155       72723 : RTFSprms::RTFSprms()
     156       72723 :     : m_pSprms(new RTFSprmsImpl())
     157             : {
     158       72723 : }
     159             : 
     160      590781 : RTFSprms::~RTFSprms()
     161             : {
     162      590781 : }
     163             : 
     164      518058 : RTFSprms::RTFSprms(const RTFSprms& rSprms)
     165             : {
     166      518058 :     *this = rSprms;
     167      518058 : }
     168             : 
     169      522904 : RTFSprms& RTFSprms::operator=(const RTFSprms& rOther)
     170             : {
     171      522904 :     m_pSprms = rOther.m_pSprms;
     172      522904 :     return *this;
     173             : }
     174             : 
     175        6897 : void RTFSprms::clear()
     176             : {
     177        6897 :     if (m_pSprms->m_nRefCount == 1)
     178        7994 :         return m_pSprms->clear();
     179             :     else
     180        5800 :         m_pSprms.reset(new RTFSprmsImpl());
     181             : }
     182             : 
     183             : } // namespace rtftok
     184          24 : } // namespace writerfilter
     185             : 
     186             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10