LibreOffice Module sw (master)  1
frameformats.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  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
36  >
37 {
38 };
39 
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>>>
45 
48 {
49  // function updating ByName index via modify
50  friend void SwFrameFormat::SetName(const OUString&, bool);
51 
52  typedef SwFrameFormatsBase::nth_index<0>::type ByPos;
53  typedef SwFrameFormatsBase::nth_index<1>::type ByTypeAndName;
54  typedef ByPos::iterator iterator;
55 
57  ByPos& m_PosIndex;
58  ByTypeAndName& m_TypeAndNameIndex;
59 
60 public:
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;
65 
67  // frees all SwFrameFormat!
68  virtual ~SwFrameFormats() 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  std::pair<const_iterator, bool> push_back(const value_type& x);
75 
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);
80 
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;
85 
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)
96  {
97  return m_Array.project<0>(position);
98  }
99 
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(); }
105 
106  void dumpAsXml(xmlTextWriterPtr pWriter, const char* pName) const;
107 
108  virtual size_t GetFormatCount() const override { return m_Array.size(); }
109  virtual SwFormat* GetFormat(size_t idx) const override { return operator[](idx); }
110 
113  bool ContainsFormat(SwFrameFormat const& rFormat) const;
115  bool IsAlive(SwFrameFormat const*) const;
116 
117  void DeleteAndDestroyAll(bool keepDefault = false);
118 
119  bool newDefault(const value_type& x);
120  void newDefault(const_iterator const& position);
121 };
122 
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const value_type & operator[](size_t index_) const
virtual size_t GetFormatCount() const override
const_iterator begin() const
ByPos & m_PosIndex
const_iterator end() const
SwFrameFormatsBase::value_type value_type
ByTypeAndName & m_TypeAndNameIndex
const_iterator rangeProject(const_range_iterator const &position)
SwFrameFormatsBase::nth_index< 0 >::type ByPos
provides some methods for generic operations on lists that contain SwFormat* subclasses.
Definition: docary.hxx:43
virtual void SetName(const OUString &rNewName, bool bBroadcast=false) override
Definition: atrfrm.cxx:2494
bool empty() const
ByTypeAndName::const_iterator const_range_iterator
Specific frame formats (frames, DrawObjects).
Base class for various Writer styles.
Definition: format.hxx:43
struct _xmlTextWriter * xmlTextWriterPtr
sal_uInt16 char * pName
SwFrameFormatsBase::nth_index< 1 >::type ByTypeAndName
Style of a layout element.
Definition: frmfmt.hxx:58
OSQLColumns::const_iterator find(const OSQLColumns::const_iterator &first, const OSQLColumns::const_iterator &last, const OUString &_rVal, const ::comphelper::UStringMixEqual &_rCase)
const value_type & front() const
const_range_iterator rangeEnd() const
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
ByPos::const_iterator const_iterator
virtual SwFormat * GetFormat(size_t idx) const override
boost::multi_index_container< SwFrameFormat *, boost::multi_index::indexed_by< boost::multi_index::random_access<>, boost::multi_index::ordered_unique< type_name_key > > > SwFrameFormatsBase
ByPos::iterator iterator
size_t size() const
SwFrameFormatsBase::size_type size_type
const value_type & back() const
SwFrameFormatsBase m_Array