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 582458 : class RTFSprmsImpl : public RTFSprmsImplBase
32 : {
33 : public:
34 : sal_Int32 m_nRefCount;
35 582458 : RTFSprmsImpl() : RTFSprmsImplBase(), m_nRefCount(0) {}
36 : };
37 :
38 3117578 : inline void intrusive_ptr_add_ref(RTFSprmsImpl* p)
39 : {
40 3117578 : ++(p->m_nRefCount);
41 3117578 : }
42 3117578 : inline void intrusive_ptr_release(RTFSprmsImpl* p)
43 : {
44 3117578 : if (!--(p->m_nRefCount))
45 582458 : delete p;
46 3117578 : }
47 :
48 : enum RTFOverwrite
49 : {
50 : OVERWRITE_YES, ///< Yes, if an existing key is found, overwrite it.
51 : OVERWRITE_NO_APPEND, ///< No, always append the value to the end of the list.
52 : OVERWRITE_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 ::boost::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 = OVERWRITE_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 2488 : size_t size() const
75 : {
76 2488 : return m_pSprms->size();
77 : }
78 150900 : bool empty() const
79 : {
80 150900 : return m_pSprms->empty();
81 : }
82 2246 : Entry_t& back()
83 : {
84 2246 : return m_pSprms->back();
85 : }
86 157596 : Iterator_t begin()
87 : {
88 157596 : return m_pSprms->begin();
89 : }
90 343630 : Iterator_t end()
91 : {
92 343630 : 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 72014 : 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: */
|