LibreOffice Module writerfilter (master) 1
rtfsprm.hxx
Go to the documentation of this file.
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#pragma once
11
12#include <string>
13#include <utility>
14#include <vector>
15#include <map>
16
17#include <tools/ref.hxx>
18#include "rtfvalue.hxx"
19
21{
22using RTFSprmsImplBase = std::vector<std::pair<Id, RTFValue::Pointer_t>>;
23
25class RTFSprmsImpl : public RTFSprmsImplBase, public virtual SvRefBase
26{
27};
28
29enum class RTFOverwrite
30{
31 YES,
32 NO_APPEND,
33 NO_IGNORE,
35};
36
38class RTFSprms : public virtual SvRefBase
39{
40public:
42 using Entry_t = std::pair<Id, RTFValue::Pointer_t>;
43 using Iterator_t = std::vector<Entry_t>::iterator;
44 using ReverseIterator_t = std::vector<Entry_t>::reverse_iterator;
45 RTFSprms();
46 ~RTFSprms() override;
47
48 RTFSprms(RTFSprms const&) = default;
49 RTFSprms(RTFSprms&&) = default;
50 RTFSprms& operator=(RTFSprms const&) = default;
52
53 RTFValue::Pointer_t find(Id nKeyword, bool bFirst = true, bool bForWrite = false);
55 void set(Id nKeyword, const RTFValue::Pointer_t& pValue,
56 RTFOverwrite eOverwrite = RTFOverwrite::YES);
57 bool erase(Id nKeyword);
58 void eraseLast(Id nKeyword);
64 RTFSprms cloneAndDeduplicate(RTFSprms& rReference, Id nStyleType, bool bImplicitPPr = false,
65 RTFSprms* pDirect = nullptr) const;
67 void duplicateList(const RTFValue::Pointer_t& pAbstract);
69 void deduplicateList(const std::map<int, int>& rInvalidListLevelFirstIndents);
70 std::size_t size() const { return m_pSprms->size(); }
71 bool empty() const { return m_pSprms->empty(); }
72 Entry_t& back() { return m_pSprms->back(); }
73 Iterator_t begin() { return m_pSprms->begin(); }
74 Iterator_t end() { return m_pSprms->end(); }
75 void clear();
76 bool equals(const RTFValue& rOther) const;
77
78private:
81};
82
84class RTFSprm : public Sprm
85{
86public:
87 RTFSprm(Id nKeyword, RTFValue::Pointer_t& pValue);
88 sal_uInt32 getId() const override;
89 Value::Pointer_t getValue() override;
91#ifdef DBG_UTIL
92 std::string getName() const override;
93 std::string toString() const override;
94#endif
95private:
98};
99} // namespace writerfilter::rtftok
100
101/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
An SPRM: Section, Paragraph and Run Modifier.
RTF keyword with a parameter.
Definition: rtfsprm.hxx:85
RTFValue::Pointer_t & m_pValue
Definition: rtfsprm.hxx:97
writerfilter::Reference< Properties >::Pointer_t getProps() override
Returns reference to properties contained in the SPRM.
Definition: rtfsprm.cxx:29
std::string getName() const override
Returns name of sprm.
Definition: rtfsprm.cxx:35
Value::Pointer_t getValue() override
Returns value of the SPRM.
Definition: rtfsprm.cxx:27
sal_uInt32 getId() const override
Returns id of the SPRM.
Definition: rtfsprm.cxx:25
std::string toString() const override
Returns string representation of sprm.
Definition: rtfsprm.cxx:39
RTFSprm(Id nKeyword, RTFValue::Pointer_t &pValue)
Definition: rtfsprm.cxx:19
The payload of RTFSprms which is only copied on write.
Definition: rtfsprm.hxx:26
A list of RTFSprm with a copy constructor that performs a deep copy.
Definition: rtfsprm.hxx:39
RTFValue::Pointer_t find(Id nKeyword, bool bFirst=true, bool bForWrite=false)
Definition: rtfsprm.cxx:74
bool equals(const RTFValue &rOther) const
Definition: rtfsprm.cxx:437
RTFSprms & operator=(RTFSprms const &)=default
std::size_t size() const
Definition: rtfsprm.hxx:70
RTFSprms & operator=(RTFSprms &&)=default
RTFSprms(RTFSprms const &)=default
RTFSprms(RTFSprms &&)=default
void deduplicateList(const std::map< int, int > &rInvalidListLevelFirstIndents)
Removes duplicated values based on in-list properties.
Definition: rtfsprm.cxx:353
std::pair< Id, RTFValue::Pointer_t > Entry_t
Definition: rtfsprm.hxx:42
void set(Id nKeyword, const RTFValue::Pointer_t &pValue, RTFOverwrite eOverwrite=RTFOverwrite::YES)
Does the same as ->push_back(), except that it can overwrite or ignore existing entries.
Definition: rtfsprm.cxx:98
tools::SvRef< RTFSprmsImpl > m_pSprms
Definition: rtfsprm.hxx:80
bool erase(Id nKeyword)
Definition: rtfsprm.cxx:136
void eraseLast(Id nKeyword)
Definition: rtfsprm.cxx:149
RTFSprms cloneAndDeduplicate(RTFSprms &rReference, Id nStyleType, bool bImplicitPPr=false, RTFSprms *pDirect=nullptr) const
Removes elements which are already in the reference set.
Definition: rtfsprm.cxx:412
std::vector< Entry_t >::iterator Iterator_t
Definition: rtfsprm.hxx:43
std::vector< Entry_t >::reverse_iterator ReverseIterator_t
Definition: rtfsprm.hxx:44
void duplicateList(const RTFValue::Pointer_t &pAbstract)
Inserts default values to override attributes of pAbstract.
Definition: rtfsprm.cxx:378
Value of an RTF keyword.
Definition: rtfvalue.hxx:33
@ NO_IGNORE
No, if the key is already in the list, then ignore, otherwise append.
@ NO_APPEND
No, always append the value to the end of the list.
@ YES_PREPEND
Yes, always prepend the value to the start of the list and remove existing entries.
@ YES
Yes, if an existing key is found, overwrite it.
std::vector< std::pair< Id, RTFValue::Pointer_t > > RTFSprmsImplBase
Definition: rtfsprm.hxx:22
sal_uInt32 Id