LibreOffice Module sw (master) 1
charformats.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 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19#pragma once
20
21#include "docary.hxx"
22#include <boost/multi_index_container.hpp>
23#include <boost/multi_index/composite_key.hpp>
24#include <boost/multi_index/identity.hpp>
25#include <boost/multi_index/mem_fun.hpp>
26#include <boost/multi_index/ordered_index.hpp>
27#include <boost/multi_index/random_access_index.hpp>
28
29// Like o3tl::find_partialorder_ptrequals
30// We don't allow duplicated object entries!
32 : boost::multi_index::composite_key<
33 SwCharFormat*,
34 boost::multi_index::const_mem_fun<SwFormat, const OUString&, &SwFormat::GetName>,
35 boost::multi_index::identity<SwCharFormat*> // the actual object pointer
36 >
37{
38};
39
40typedef boost::multi_index_container<
42 boost::multi_index::indexed_by<boost::multi_index::random_access<>,
43 boost::multi_index::ordered_unique<char_formats_name_key>>>
45
47{
48 // function updating ByName index via modify
49 friend void SwFormat::SetName(const OUString&, bool);
50
51public:
52 typedef SwCharFormatsBase::nth_index<0>::type ByPos;
53 typedef SwCharFormatsBase::nth_index<1>::type ByName;
54 typedef ByPos::iterator iterator;
55
56private:
60
61public:
62 typedef ByPos::const_iterator const_iterator;
63 typedef SwCharFormatsBase::size_type size_type;
64 typedef SwCharFormatsBase::value_type value_type;
65
67 // frees all SwCharFormat!
68 virtual ~SwCharFormats() override;
69
70 bool empty() const { return m_Array.empty(); }
71 size_t size() const { return m_Array.size(); }
72
73 // Only fails, if you try to insert the same object twice
74 void insert(SwCharFormat* x);
75
76 // This will try to remove the exact object!
77 void erase(const_iterator const& position);
78
79 // Get the iterator of the exact object (includes pointer!),
80 // e.g for position with std::distance.
81 // There is also ContainsFormat, if you don't need the position.
82 const_iterator find(const SwCharFormat* x) const;
83 size_t GetPos(const SwCharFormat* p) const;
84
85 // search for formats by name
86 ByName::const_iterator findByName(const OUString& name) const;
87
88 SwCharFormat* operator[](size_t index_) const { return m_PosIndex.operator[](index_); }
89 const_iterator begin() const { return m_PosIndex.begin(); }
90 const_iterator end() const { return m_PosIndex.end(); }
91
92 void dumpAsXml(xmlTextWriterPtr pWriter) const;
93
94 virtual size_t GetFormatCount() const override { return m_Array.size(); }
95 virtual SwCharFormat* GetFormat(size_t idx) const override { return operator[](idx); }
96
99 bool ContainsFormat(const SwCharFormat* pFormat) const;
100
101 void DeleteAndDestroyAll(bool keepDefault = false);
102
103 // Override return type to reduce casting
104 virtual SwCharFormat* FindFormatByName(const OUString& rName) const override;
105
107 void SetFormatNameAndReindex(SwCharFormat* v, const OUString& sNewName);
108};
109
110/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _xmlTextWriter * xmlTextWriterPtr
boost::multi_index_container< SwCharFormat *, boost::multi_index::indexed_by< boost::multi_index::random_access<>, boost::multi_index::ordered_unique< char_formats_name_key > > > SwCharFormatsBase
Definition: charformats.hxx:44
Represents the style of a text portion.
Definition: charfmt.hxx:27
ByPos & m_PosIndex
Definition: charformats.hxx:58
virtual SwCharFormat * GetFormat(size_t idx) const override
Definition: charformats.hxx:95
SwCharFormatsBase::nth_index< 0 >::type ByPos
Definition: charformats.hxx:52
SwCharFormatsBase m_Array
Definition: charformats.hxx:57
SwCharFormat * operator[](size_t index_) const
Definition: charformats.hxx:88
size_t size() const
Definition: charformats.hxx:71
ByPos::const_iterator const_iterator
Definition: charformats.hxx:62
ByPos::iterator iterator
Definition: charformats.hxx:54
const_iterator begin() const
Definition: charformats.hxx:89
ByName & m_NameIndex
Definition: charformats.hxx:59
virtual size_t GetFormatCount() const override
Definition: charformats.hxx:94
SwCharFormatsBase::size_type size_type
Definition: charformats.hxx:63
SwCharFormatsBase::value_type value_type
Definition: charformats.hxx:64
SwCharFormatsBase::nth_index< 1 >::type ByName
Definition: charformats.hxx:53
bool empty() const
Definition: charformats.hxx:70
const_iterator end() const
Definition: charformats.hxx:90
virtual void SetName(const OUString &rNewName, bool bBroadcast=false)
Definition: format.cxx:144
provides some methods for generic operations on lists that contain SwFormat* subclasses.
Definition: docary.hxx:44
virtual SwFormat * FindFormatByName(const OUString &rName) const
Definition: format.cxx:767
const sal_uInt16 idx[]
sal_uInt32 index_
OSQLColumns::const_iterator find(const OSQLColumns::const_iterator &first, const OSQLColumns::const_iterator &last, std::u16string_view _rVal, const ::comphelper::UStringMixEqual &_rCase)
#define SW_DLLPUBLIC
Definition: swdllapi.h:28