Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/inc/charformats.hxx
Line
Count
Source
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!
31
struct char_formats_name_key
32
    : boost::multi_index::composite_key<
33
          SwCharFormat*,
34
          boost::multi_index::const_mem_fun<SwFormat, const UIName&, &SwFormat::GetName>,
35
          boost::multi_index::identity<SwCharFormat*> // the actual object pointer
36
          >
37
{
38
};
39
40
typedef boost::multi_index_container<
41
    SwCharFormat*,
42
    boost::multi_index::indexed_by<boost::multi_index::random_access<>,
43
                                   boost::multi_index::ordered_unique<char_formats_name_key>>>
44
    SwCharFormatsBase;
45
46
class SW_DLLPUBLIC SwCharFormats final : public SwFormatsBase
47
{
48
    // function updating ByName index via modify
49
    friend void SwFormat::SetFormatName(const UIName&, bool);
50
51
public:
52
    typedef SwCharFormatsBase::nth_index<0>::type ByPos;
53
    typedef SwCharFormatsBase::nth_index<1>::type ByName;
54
    typedef ByPos::iterator iterator;
55
56
private:
57
    SwCharFormatsBase m_Array;
58
    ByPos& m_PosIndex;
59
    ByName& m_NameIndex;
60
61
public:
62
    typedef ByPos::const_iterator const_iterator;
63
    typedef SwCharFormatsBase::size_type size_type;
64
    typedef SwCharFormatsBase::value_type value_type;
65
66
    SwCharFormats();
67
    // frees all SwCharFormat!
68
    virtual ~SwCharFormats() override;
69
70
226k
    bool empty() const { return m_Array.empty(); }
71
386k
    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 UIName& name) const;
87
88
1.28M
    SwCharFormat* operator[](size_t index_) const { return m_PosIndex.operator[](index_); }
89
165k
    const_iterator begin() const { return m_PosIndex.begin(); }
90
261k
    const_iterator end() const { return m_PosIndex.end(); }
91
92
    void dumpAsXml(xmlTextWriterPtr pWriter) const;
93
94
1.31M
    virtual size_t GetFormatCount() const override { return m_Array.size(); }
95
1.26M
    virtual SwCharFormat* GetFormat(size_t idx) const override { return operator[](idx); }
96
97
    /// fast check if given format is contained here
98
    /// @precond pFormat must not have been deleted
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 UIName& rName) const override;
105
106
    /** Need to call this when the format name changes */
107
    void SetFormatNameAndReindex(SwCharFormat* v, const UIName& sNewName);
108
};
109
110
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */