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/.
10 #ifndef INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFSPRM_HXX
11 #define INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFSPRM_HXX
18 #include <tools/ref.hxx>
19 #include "rtfvalue.hxx"
21 namespace writerfilter
25 using RTFSprmsImplBase
= std::vector
<std::pair
<Id
, RTFValue::Pointer_t
>>;
27 /// The payload of RTFSprms which is only copied on write.
28 class RTFSprmsImpl
: public RTFSprmsImplBase
, public virtual SvRefBase
32 enum class RTFOverwrite
34 YES
, ///< Yes, if an existing key is found, overwrite it.
35 NO_APPEND
, ///< No, always append the value to the end of the list.
36 NO_IGNORE
, ///< No, if the key is already in the list, then ignore, otherwise append.
37 YES_PREPEND
///< Yes, always prepend the value to the start of the list and remove existing entries.
40 /// A list of RTFSprm with a copy constructor that performs a deep copy.
41 class RTFSprms
: public virtual SvRefBase
44 using Pointer_t
= tools::SvRef
<RTFSprms
>;
45 using Entry_t
= std::pair
<Id
, RTFValue::Pointer_t
>;
46 using Iterator_t
= std::vector
<Entry_t
>::iterator
;
47 using ReverseIterator_t
= std::vector
<Entry_t
>::reverse_iterator
;
51 RTFSprms(RTFSprms
const&) = default;
52 RTFSprms(RTFSprms
&&) = default;
53 RTFSprms
& operator=(RTFSprms
const&) = default;
54 RTFSprms
& operator=(RTFSprms
&&) = default;
56 RTFValue::Pointer_t
find(Id nKeyword
, bool bFirst
= true, bool bForWrite
= false);
57 /// Does the same as ->push_back(), except that it can overwrite or ignore existing entries.
58 void set(Id nKeyword
, const RTFValue::Pointer_t
& pValue
,
59 RTFOverwrite eOverwrite
= RTFOverwrite::YES
);
60 bool erase(Id nKeyword
);
61 void eraseLast(Id nKeyword
);
62 /// Removes elements which are already in the reference set.
63 /// Also insert default values to override attributes of style
64 /// (yes, really; that's what Word does).
65 /// @param bImplicitPPr implicit dereference of top-level pPr SPRM
66 RTFSprms
cloneAndDeduplicate(RTFSprms
& rReference
, Id nStyleType
,
67 bool bImplicitPPr
= false) const;
68 /// Inserts default values to override attributes of pAbstract.
69 void duplicateList(const RTFValue::Pointer_t
& pAbstract
);
70 /// Removes duplicated values based on in-list properties.
71 void deduplicateList(const std::map
<int, int>& rInvalidListLevelFirstIndents
);
72 std::size_t size() const { return m_pSprms
->size(); }
73 bool empty() const { return m_pSprms
->empty(); }
74 Entry_t
& back() { return m_pSprms
->back(); }
75 Iterator_t
begin() { return m_pSprms
->begin(); }
76 Iterator_t
end() { return m_pSprms
->end(); }
78 bool equals(const RTFValue
& rOther
) const;
81 void ensureCopyBeforeWrite();
82 tools::SvRef
<RTFSprmsImpl
> m_pSprms
;
85 /// RTF keyword with a parameter
86 class RTFSprm
: public Sprm
89 RTFSprm(Id nKeyword
, RTFValue::Pointer_t
& pValue
);
90 sal_uInt32
getId() const override
;
91 Value::Pointer_t
getValue() override
;
92 writerfilter::Reference
<Properties
>::Pointer_t
getProps() override
;
94 std::string
getName() const override
;
95 std::string
toString() const override
;
99 RTFValue::Pointer_t
& m_pValue
;
101 } // namespace rtftok
102 } // namespace writerfilter
104 #endif // INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFSPRM_HXX
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */