LibreOffice Module sd (master) 1
shapelist.cxx
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
20#include <svx/svdobj.hxx>
21#include <osl/diagnose.h>
22#include <shapelist.hxx>
23
24#include <algorithm>
25
26using namespace sd;
27
28ShapeList::ShapeList()
29{
30 maIter = maShapeList.end();
31}
32
34{
35 clear();
36}
37
40{
41 ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
42 if( aIter == maShapeList.end() )
43 {
44 maShapeList.push_back(&rObject);
45 rObject.AddObjectUser( *this );
46 }
47 else
48 {
49 OSL_FAIL("sd::ShapeList::addShape(), given shape already part of list!");
50 }
51}
52
55{
56 ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
57 if( aIter != maShapeList.end() )
58 {
59 bool bIterErased = aIter == maIter;
60
61 (*aIter)->RemoveObjectUser(*this);
62 aIter = maShapeList.erase( aIter );
63
64 if( bIterErased )
65 maIter = aIter;
66 }
67 else
68 {
69 OSL_FAIL("sd::ShapeList::removeShape(), given shape not part of list!");
70 }
71}
72
76{
77 ListImpl aShapeList;
78 aShapeList.swap( maShapeList );
79
80 for( auto& rpShape : aShapeList )
81 rpShape->RemoveObjectUser(*this);
82
83 maIter = maShapeList.end();
84}
85
88{
89 return maShapeList.empty();
90}
91
93bool ShapeList::hasShape( SdrObject& rObject ) const
94{
95 return std::find( maShapeList.begin(), maShapeList.end(), &rObject ) != maShapeList.end();
96}
97
99{
100 ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
101 if( aIter != maShapeList.end() )
102 {
103 bool bIterErased = aIter == maIter;
104
105 aIter = maShapeList.erase( aIter );
106
107 if( bIterErased )
108 maIter = aIter;
109 }
110 else
111 {
112 OSL_FAIL("sd::ShapeList::ObjectInDestruction(), got a call from an unknown friend!");
113 }
114}
115
117{
118 if( maIter != maShapeList.end() )
119 {
120 return (*maIter++);
121 }
122 else
123 {
124 return nullptr;
125 }
126}
127
128void ShapeList::seekShape( sal_uInt32 nIndex )
129{
130 maIter = maShapeList.begin();
131 nIndex = std::min(nIndex, static_cast<sal_uInt32>(maShapeList.size()));
132 std::advance(maIter, nIndex);
133}
134
136{
137 return maIter != maShapeList.end();
138}
139
140/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void AddObjectUser(sdr::ObjectUser &rNewUser)
ListImpl::iterator maIter
Definition: shapelist.hxx:67
std::list< SdrObject * > ListImpl
Definition: shapelist.hxx:65
virtual void ObjectInDestruction(const SdrObject &rObject) override
Definition: shapelist.cxx:98
void addShape(SdrObject &rObject)
adds the given shape to this list
Definition: shapelist.cxx:39
void removeShape(SdrObject &rObject)
removes the shape from this list
Definition: shapelist.cxx:54
bool isEmpty() const
returns true if this list is empty
Definition: shapelist.cxx:87
bool hasShape(SdrObject &rObject) const
returns true if given shape is part of this list
Definition: shapelist.cxx:93
virtual ~ShapeList()
Definition: shapelist.cxx:33
bool hasMore() const
Definition: shapelist.cxx:135
SdrObject * getNextShape()
returns the shape the internal iterator points to, or 0 if the list end is reached.
Definition: shapelist.cxx:116
void clear()
removes all shapes from this list
Definition: shapelist.cxx:75
ListImpl maShapeList
Definition: shapelist.hxx:66
void seekShape(sal_uInt32 nIndex)
Sets the internal iterator to the shape at given index.
Definition: shapelist.cxx:128
sal_Int32 nIndex