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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
29 // Like o3tl::find_partialorder_ptrequals
30 // We don't allow duplicated object entries!
32 : boost::multi_index::composite_key
<
33 SwFrameFormat
*, boost::multi_index::const_mem_fun
<SwFormat
, sal_uInt16
, &SwFormat::Which
>,
34 boost::multi_index::const_mem_fun
<SwFormat
, const OUString
&, &SwFormat::GetName
>,
35 boost::multi_index::identity
<SwFrameFormat
*> // the actual object pointer
40 typedef boost::multi_index_container
<
42 boost::multi_index::indexed_by
<boost::multi_index::random_access
<>,
43 boost::multi_index::ordered_unique
<type_name_key
>>>
46 /// Specific frame formats (frames, DrawObjects).
47 class SW_DLLPUBLIC SwFrameFormats
: public SwFormatsBase
49 // function updating ByName index via modify
50 friend void SwFrameFormat::SetName(const OUString
&, bool);
52 typedef SwFrameFormatsBase::nth_index
<0>::type ByPos
;
53 typedef SwFrameFormatsBase::nth_index
<1>::type ByTypeAndName
;
54 typedef ByPos::iterator iterator
;
56 SwFrameFormatsBase m_Array
;
58 ByTypeAndName
& m_TypeAndNameIndex
;
61 typedef ByPos::const_iterator const_iterator
;
62 typedef ByTypeAndName::const_iterator const_range_iterator
;
63 typedef SwFrameFormatsBase::size_type size_type
;
64 typedef SwFrameFormatsBase::value_type value_type
;
67 // frees all SwFrameFormat!
68 virtual ~SwFrameFormats() override
;
70 bool empty() const { return m_Array
.empty(); }
71 size_t size() const { return m_Array
.size(); }
73 // Only fails, if you try to insert the same object twice
74 std::pair
<const_iterator
, bool> push_back(const value_type
& x
);
76 // This will try to remove the exact object!
77 bool erase(const value_type
& x
);
78 void erase(size_type index
);
79 void erase(const_iterator
const& position
);
81 // Get the iterator of the exact object (includes pointer!),
82 // e.g for position with std::distance.
83 // There is also ContainsFormat, if you don't need the position.
84 const_iterator
find(const value_type
& x
) const;
86 // As this array is non-unique related to type and name,
87 // we always get ranges for the "key" values.
88 std::pair
<const_range_iterator
, const_range_iterator
> rangeFind(sal_uInt16 type
,
89 const OUString
& name
) const;
90 // Convenience function, which just uses type and name!
91 // To look for the exact object use find.
92 std::pair
<const_range_iterator
, const_range_iterator
> rangeFind(const value_type
& x
) const;
93 // So we can actually check for end()
94 const_range_iterator
rangeEnd() const { return m_TypeAndNameIndex
.end(); }
95 const_iterator
rangeProject(const_range_iterator
const& position
)
97 return m_Array
.project
<0>(position
);
100 const value_type
& operator[](size_t index_
) const { return m_PosIndex
.operator[](index_
); }
101 const value_type
& front() const { return m_PosIndex
.front(); }
102 const value_type
& back() const { return m_PosIndex
.back(); }
103 const_iterator
begin() const { return m_PosIndex
.begin(); }
104 const_iterator
end() const { return m_PosIndex
.end(); }
106 void dumpAsXml(xmlTextWriterPtr pWriter
, const char* pName
) const;
108 virtual size_t GetFormatCount() const override
{ return m_Array
.size(); }
109 virtual SwFormat
* GetFormat(size_t idx
) const override
{ return operator[](idx
); }
111 /// fast check if given format is contained here
112 /// @precond pFormat must not have been deleted
113 bool ContainsFormat(SwFrameFormat
const& rFormat
) const;
114 /// not so fast check that given format is still alive (i.e. contained here)
115 bool IsAlive(SwFrameFormat
const*) const;
117 void DeleteAndDestroyAll(bool keepDefault
= false);
119 bool newDefault(const value_type
& x
);
120 void newDefault(const_iterator
const& position
);
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */