Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Initial Developer of the Original Code is
16 : * Miklos Vajna <vmiklos@frugalware.org>
17 : * Portions created by the Initial Developer are Copyright (C) 2011 the
18 : * Initial Developer. All Rights Reserved.
19 : *
20 : * Contributor(s):
21 : *
22 : * Alternatively, the contents of this file may be used under the terms of
23 : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 : * instead of those above.
27 : */
28 :
29 : #ifndef _RTFSPRM_HXX_
30 : #define _RTFSPRM_HXX_
31 :
32 : #include <boost/intrusive_ptr.hpp>
33 : #include <rtfcontrolwords.hxx>
34 : #include <rtfvalue.hxx>
35 :
36 : namespace writerfilter {
37 : namespace rtftok {
38 :
39 : typedef std::vector< std::pair<Id, RTFValue::Pointer_t> > RTFSprmsImplBase;
40 54536 : class RTFSprmsImpl : public RTFSprmsImplBase
41 : {
42 : public:
43 : sal_Int32 m_nRefCount;
44 54536 : RTFSprmsImpl() : RTFSprmsImplBase(), m_nRefCount(0) {}
45 : };
46 :
47 473256 : inline void intrusive_ptr_add_ref(RTFSprmsImpl* p)
48 : {
49 473256 : ++(p->m_nRefCount);
50 473256 : }
51 473256 : inline void intrusive_ptr_release(RTFSprmsImpl* p)
52 : {
53 473256 : if (!--(p->m_nRefCount))
54 54536 : delete p;
55 473256 : }
56 :
57 : /// A list of RTFSprm with a copy constructor that performs a deep copy.
58 : class RTFSprms
59 : {
60 : public:
61 : typedef ::boost::shared_ptr<RTFSprms> Pointer_t;
62 : typedef std::pair<Id, RTFValue::Pointer_t> Entry_t;
63 : typedef std::vector<Entry_t>::iterator Iterator_t;
64 : RTFSprms();
65 : RTFSprms(const RTFSprms& rSprms);
66 : ~RTFSprms();
67 : RTFSprms& operator=(const RTFSprms& rOther);
68 : RTFValue::Pointer_t find(Id nKeyword);
69 : /// Does the same as ->push_back(), except that it can overwrite existing entries.
70 : void set(Id nKeyword, RTFValue::Pointer_t pValue, bool bOverwrite = true);
71 : bool erase(Id nKeyword);
72 : /// Removes elements, which are already in the reference set.
73 : void deduplicate(RTFSprms& rReference);
74 : void swap(RTFSprms& rOther);
75 297 : size_t size() const { return m_pSprms->size(); }
76 : bool empty() const { return m_pSprms->empty(); }
77 295 : Entry_t& back() { return m_pSprms->back(); }
78 16373 : Iterator_t begin() { return m_pSprms->begin(); }
79 40973 : Iterator_t end() { return m_pSprms->end(); }
80 : void clear();
81 : private:
82 : void ensureCopyBeforeWrite();
83 : boost::intrusive_ptr<RTFSprmsImpl> m_pSprms;
84 : };
85 :
86 : /// RTF keyword with a parameter
87 : class RTFSprm
88 : : public Sprm
89 : {
90 : public:
91 : RTFSprm(Id nKeyword, RTFValue::Pointer_t& pValue);
92 18650 : virtual ~RTFSprm() {}
93 : virtual sal_uInt32 getId() const;
94 : virtual Value::Pointer_t getValue();
95 : virtual writerfilter::Reference<BinaryObj>::Pointer_t getBinary();
96 : virtual writerfilter::Reference<Stream>::Pointer_t getStream();
97 : virtual writerfilter::Reference<Properties>::Pointer_t getProps();
98 : virtual Kind getKind();
99 : virtual std::string getName() const;
100 : virtual std::string toString() const;
101 : private:
102 : Id m_nKeyword;
103 : RTFValue::Pointer_t& m_pValue;
104 : };
105 : } // namespace rtftok
106 : } // namespace writerfilter
107 :
108 : #endif // _RTFSPRM_HXX_
109 :
110 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|