bump product version to 4.1.6.2
[LibreOffice.git] / writerfilter / source / rtftok / rtfsprm.hxx
blobdc82256092c37a6404cde94d4dbdb4bbfac43464
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #ifndef _RTFSPRM_HXX_
11 #define _RTFSPRM_HXX_
13 #include <boost/intrusive_ptr.hpp>
14 #include <rtfcontrolwords.hxx>
15 #include <rtfvalue.hxx>
17 namespace writerfilter {
18 namespace rtftok {
20 typedef std::vector< std::pair<Id, RTFValue::Pointer_t> > RTFSprmsImplBase;
22 /// The payload of RTFSprms which is only copied on write.
23 class RTFSprmsImpl : public RTFSprmsImplBase
25 public:
26 sal_Int32 m_nRefCount;
27 RTFSprmsImpl() : RTFSprmsImplBase(), m_nRefCount(0) {}
30 inline void intrusive_ptr_add_ref(RTFSprmsImpl* p)
32 ++(p->m_nRefCount);
34 inline void intrusive_ptr_release(RTFSprmsImpl* p)
36 if (!--(p->m_nRefCount))
37 delete p;
40 /// A list of RTFSprm with a copy constructor that performs a deep copy.
41 class RTFSprms
43 public:
44 typedef ::boost::shared_ptr<RTFSprms> Pointer_t;
45 typedef std::pair<Id, RTFValue::Pointer_t> Entry_t;
46 typedef std::vector<Entry_t>::iterator Iterator_t;
47 RTFSprms();
48 RTFSprms(const RTFSprms& rSprms);
49 ~RTFSprms();
50 RTFSprms& operator=(const RTFSprms& rOther);
51 RTFValue::Pointer_t find(Id nKeyword, bool bFirst = true);
52 /// Does the same as ->push_back(), except that it can overwrite existing entries.
53 void set(Id nKeyword, RTFValue::Pointer_t pValue, bool bOverwrite = true);
54 bool erase(Id nKeyword);
55 /// Removes elements, which are already in the reference set.
56 void deduplicate(RTFSprms& rReference);
57 size_t size() const { return m_pSprms->size(); }
58 bool empty() const { return m_pSprms->empty(); }
59 Entry_t& back() { return m_pSprms->back(); }
60 Iterator_t begin() { return m_pSprms->begin(); }
61 Iterator_t end() { return m_pSprms->end(); }
62 void clear();
63 private:
64 void ensureCopyBeforeWrite();
65 boost::intrusive_ptr<RTFSprmsImpl> m_pSprms;
68 /// RTF keyword with a parameter
69 class RTFSprm
70 : public Sprm
72 public:
73 RTFSprm(Id nKeyword, RTFValue::Pointer_t& pValue);
74 virtual ~RTFSprm() {}
75 virtual sal_uInt32 getId() const;
76 virtual Value::Pointer_t getValue();
77 virtual writerfilter::Reference<BinaryObj>::Pointer_t getBinary();
78 virtual writerfilter::Reference<Stream>::Pointer_t getStream();
79 virtual writerfilter::Reference<Properties>::Pointer_t getProps();
80 virtual Kind getKind();
81 virtual std::string getName() const;
82 virtual std::string toString() const;
83 private:
84 Id m_nKeyword;
85 RTFValue::Pointer_t& m_pValue;
87 } // namespace rtftok
88 } // namespace writerfilter
90 #endif // _RTFSPRM_HXX_
92 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */