1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
13 #include <boost/intrusive_ptr.hpp>
14 #include <rtfcontrolwords.hxx>
15 #include <rtfvalue.hxx>
17 namespace writerfilter
{
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
26 sal_Int32 m_nRefCount
;
27 RTFSprmsImpl() : RTFSprmsImplBase(), m_nRefCount(0) {}
30 inline void intrusive_ptr_add_ref(RTFSprmsImpl
* p
)
34 inline void intrusive_ptr_release(RTFSprmsImpl
* p
)
36 if (!--(p
->m_nRefCount
))
40 /// A list of RTFSprm with a copy constructor that performs a deep copy.
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
;
48 RTFSprms(const RTFSprms
& rSprms
);
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(); }
64 void ensureCopyBeforeWrite();
65 boost::intrusive_ptr
<RTFSprmsImpl
> m_pSprms
;
68 /// RTF keyword with a parameter
73 RTFSprm(Id nKeyword
, RTFValue::Pointer_t
& pValue
);
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;
85 RTFValue::Pointer_t
& m_pValue
;
88 } // namespace writerfilter
90 #endif // _RTFSPRM_HXX_
92 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */