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 _RTFSPRM_HXX_
11 : #define _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 : namespace rtftok {
25 :
26 : typedef std::vector< std::pair<Id, RTFValue::Pointer_t> > RTFSprmsImplBase;
27 :
28 : /// The payload of RTFSprms which is only copied on write.
29 0 : class RTFSprmsImpl : public RTFSprmsImplBase
30 : {
31 : public:
32 : sal_Int32 m_nRefCount;
33 0 : RTFSprmsImpl() : RTFSprmsImplBase(), m_nRefCount(0) {}
34 : };
35 :
36 0 : inline void intrusive_ptr_add_ref(RTFSprmsImpl* p)
37 : {
38 0 : ++(p->m_nRefCount);
39 0 : }
40 0 : inline void intrusive_ptr_release(RTFSprmsImpl* p)
41 : {
42 0 : if (!--(p->m_nRefCount))
43 0 : delete p;
44 0 : }
45 :
46 : enum RTFOverwrite
47 : {
48 : OVERWRITE_YES, ///< Yes, if an existing key is found, overwrite it.
49 : OVERWRITE_NO_APPEND, ///< No, always append the value to the end of the list.
50 : OVERWRITE_NO_IGNORE ///< No, if the key is already in the list, then ignore, otherwise append.
51 : };
52 :
53 : /// A list of RTFSprm with a copy constructor that performs a deep copy.
54 : class RTFSprms
55 : {
56 : public:
57 : typedef ::boost::shared_ptr<RTFSprms> Pointer_t;
58 : typedef std::pair<Id, RTFValue::Pointer_t> Entry_t;
59 : typedef std::vector<Entry_t>::iterator Iterator_t;
60 : RTFSprms();
61 : RTFSprms(const RTFSprms& rSprms);
62 : ~RTFSprms();
63 : RTFSprms& operator=(const RTFSprms& rOther);
64 : RTFValue::Pointer_t find(Id nKeyword, bool bFirst = true);
65 : /// Does the same as ->push_back(), except that it can overwrite or ignore existing entries.
66 : void set(Id nKeyword, RTFValue::Pointer_t pValue, RTFOverwrite eOverwrite = OVERWRITE_YES);
67 : bool erase(Id nKeyword);
68 : /// Removes elements, which are already in the reference set.
69 : void deduplicate(RTFSprms& rReference);
70 0 : size_t size() const { return m_pSprms->size(); }
71 : bool empty() const { return m_pSprms->empty(); }
72 0 : Entry_t& back() { return m_pSprms->back(); }
73 0 : Iterator_t begin() { return m_pSprms->begin(); }
74 0 : Iterator_t end() { return m_pSprms->end(); }
75 : void clear();
76 : private:
77 : void ensureCopyBeforeWrite();
78 : boost::intrusive_ptr<RTFSprmsImpl> m_pSprms;
79 : };
80 :
81 : /// RTF keyword with a parameter
82 : class RTFSprm
83 : : public Sprm
84 : {
85 : public:
86 : RTFSprm(Id nKeyword, RTFValue::Pointer_t& pValue);
87 0 : virtual ~RTFSprm() {}
88 : virtual sal_uInt32 getId() const SAL_OVERRIDE;
89 : virtual Value::Pointer_t getValue() SAL_OVERRIDE;
90 : virtual writerfilter::Reference<BinaryObj>::Pointer_t getBinary() SAL_OVERRIDE;
91 : virtual writerfilter::Reference<Stream>::Pointer_t getStream() SAL_OVERRIDE;
92 : virtual writerfilter::Reference<Properties>::Pointer_t getProps() SAL_OVERRIDE;
93 : virtual Kind getKind() SAL_OVERRIDE;
94 : virtual std::string getName() const SAL_OVERRIDE;
95 : virtual std::string toString() const SAL_OVERRIDE;
96 : private:
97 : Id m_nKeyword;
98 : RTFValue::Pointer_t& m_pValue;
99 : };
100 : } // namespace rtftok
101 : } // namespace writerfilter
102 :
103 : #endif // _RTFSPRM_HXX_
104 :
105 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|