LCOV - code coverage report
Current view: top level - writerfilter/source/rtftok - rtfsprm.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 20 20 100.0 %
Date: 2015-06-13 12:38:46 Functions: 10 11 90.9 %
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             : #ifndef INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFSPRM_HXX
      11             : #define INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFSPRM_HXX
      12             : 
      13             : #include <sal/config.h>
      14             : 
      15             : #include <string>
      16             : #include <utility>
      17             : #include <vector>
      18             : 
      19             : #include <boost/intrusive_ptr.hpp>
      20             : #include <rtfcontrolwords.hxx>
      21             : #include <rtfvalue.hxx>
      22             : 
      23             : namespace writerfilter
      24             : {
      25             : namespace rtftok
      26             : {
      27             : 
      28             : typedef std::vector< std::pair<Id, RTFValue::Pointer_t> > RTFSprmsImplBase;
      29             : 
      30             : /// The payload of RTFSprms which is only copied on write.
      31      767302 : class RTFSprmsImpl : public RTFSprmsImplBase
      32             : {
      33             : public:
      34             :     sal_Int32 m_nRefCount;
      35      767302 :     RTFSprmsImpl() : RTFSprmsImplBase(), m_nRefCount(0) {}
      36             : };
      37             : 
      38     3238916 : inline void intrusive_ptr_add_ref(RTFSprmsImpl* p)
      39             : {
      40     3238916 :     ++(p->m_nRefCount);
      41     3238916 : }
      42     3238916 : inline void intrusive_ptr_release(RTFSprmsImpl* p)
      43             : {
      44     3238916 :     if (!--(p->m_nRefCount))
      45      767302 :         delete p;
      46     3238916 : }
      47             : 
      48             : enum class RTFOverwrite
      49             : {
      50             :     YES, ///< Yes, if an existing key is found, overwrite it.
      51             :     NO_APPEND, ///< No, always append the value to the end of the list.
      52             :     NO_IGNORE ///< No, if the key is already in the list, then ignore, otherwise append.
      53             : };
      54             : 
      55             : /// A list of RTFSprm with a copy constructor that performs a deep copy.
      56             : class RTFSprms
      57             : {
      58             : public:
      59             :     typedef ::std::shared_ptr<RTFSprms> Pointer_t;
      60             :     typedef std::pair<Id, RTFValue::Pointer_t> Entry_t;
      61             :     typedef std::vector<Entry_t>::iterator Iterator_t;
      62             :     RTFSprms();
      63             :     RTFSprms(const RTFSprms& rSprms);
      64             :     ~RTFSprms();
      65             :     RTFSprms& operator=(const RTFSprms& rOther);
      66             :     RTFValue::Pointer_t find(Id nKeyword, bool bFirst = true, bool bForWrite = false);
      67             :     /// Does the same as ->push_back(), except that it can overwrite or ignore existing entries.
      68             :     void set(Id nKeyword, RTFValue::Pointer_t pValue, RTFOverwrite eOverwrite = RTFOverwrite::YES);
      69             :     bool erase(Id nKeyword);
      70             :     /// Removes elements which are already in the reference set.
      71             :     /// Also insert default values to override attributes of style
      72             :     /// (yes, really; that's what Word does).
      73             :     RTFSprms cloneAndDeduplicate(RTFSprms& rReference) const;
      74       63458 :     size_t size() const
      75             :     {
      76       63458 :         return m_pSprms->size();
      77             :     }
      78      170324 :     bool empty() const
      79             :     {
      80      170324 :         return m_pSprms->empty();
      81             :     }
      82        1599 :     Entry_t& back()
      83             :     {
      84        1599 :         return m_pSprms->back();
      85             :     }
      86      141443 :     Iterator_t begin()
      87             :     {
      88      141443 :         return m_pSprms->begin();
      89             :     }
      90      355868 :     Iterator_t end()
      91             :     {
      92      355868 :         return m_pSprms->end();
      93             :     }
      94             :     void clear();
      95             :     bool equals(RTFValue& rOther);
      96             : private:
      97             :     void ensureCopyBeforeWrite();
      98             :     boost::intrusive_ptr<RTFSprmsImpl> m_pSprms;
      99             : };
     100             : 
     101             : /// RTF keyword with a parameter
     102             : class RTFSprm
     103             :     : public Sprm
     104             : {
     105             : public:
     106             :     RTFSprm(Id nKeyword, RTFValue::Pointer_t& pValue);
     107       56919 :     virtual ~RTFSprm() {}
     108             :     virtual sal_uInt32 getId() const SAL_OVERRIDE;
     109             :     virtual Value::Pointer_t getValue() SAL_OVERRIDE;
     110             :     virtual writerfilter::Reference<BinaryObj>::Pointer_t getBinary() SAL_OVERRIDE;
     111             :     virtual writerfilter::Reference<Stream>::Pointer_t getStream() SAL_OVERRIDE;
     112             :     virtual writerfilter::Reference<Properties>::Pointer_t getProps() SAL_OVERRIDE;
     113             : #ifdef DEBUG_WRITERFILTER
     114             :     virtual std::string getName() const SAL_OVERRIDE;
     115             :     virtual std::string toString() const SAL_OVERRIDE;
     116             : #endif
     117             : private:
     118             :     Id m_nKeyword;
     119             :     RTFValue::Pointer_t& m_pValue;
     120             : };
     121             : } // namespace rtftok
     122             : } // namespace writerfilter
     123             : 
     124             : #endif // INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFSPRM_HXX
     125             : 
     126             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11