Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sd / source / core / shapelist.cxx
blob613286c9b9b7ef6c60d89bb13b3f95947c085df4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <svx/svdobj.hxx>
21 #include <osl/diagnose.h>
22 #include <shapelist.hxx>
24 #include <algorithm>
26 using namespace sd;
28 ShapeList::ShapeList()
30 maIter = maShapeList.end();
33 ShapeList::~ShapeList()
35 clear();
38 /** adds the given shape to this list */
39 void ShapeList::addShape( SdrObject& rObject )
41 ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
42 if( aIter == maShapeList.end() )
44 maShapeList.push_back(&rObject);
45 rObject.AddObjectUser( *this );
47 else
49 OSL_FAIL("sd::ShapeList::addShape(), given shape already part of list!");
53 /** removes the given shape from this list */
54 void ShapeList::removeShape( SdrObject& rObject )
56 ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
57 if( aIter != maShapeList.end() )
59 bool bIterErased = aIter == maIter;
61 (*aIter)->RemoveObjectUser(*this);
62 aIter = maShapeList.erase( aIter );
64 if( bIterErased )
65 maIter = aIter;
67 else
69 OSL_FAIL("sd::ShapeList::removeShape(), given shape not part of list!");
73 /** removes all shapes from this list
74 NOTE: iterators will become invalid */
75 void ShapeList::clear()
77 ListImpl aShapeList;
78 aShapeList.swap( maShapeList );
80 for( auto& rpShape : aShapeList )
81 rpShape->RemoveObjectUser(*this);
83 maIter = maShapeList.end();
86 /** returns true if this list is empty */
87 bool ShapeList::isEmpty() const
89 return maShapeList.empty();
92 /** returns true if given shape is part of this list */
93 bool ShapeList::hasShape( SdrObject& rObject ) const
95 return std::find( maShapeList.begin(), maShapeList.end(), &rObject ) != maShapeList.end();
98 void ShapeList::ObjectInDestruction(const SdrObject& rObject)
100 ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
101 if( aIter != maShapeList.end() )
103 bool bIterErased = aIter == maIter;
105 aIter = maShapeList.erase( aIter );
107 if( bIterErased )
108 maIter = aIter;
110 else
112 OSL_FAIL("sd::ShapeList::ObjectInDestruction(), got a call from an unknown friend!");
116 SdrObject* ShapeList::getNextShape()
118 if( maIter != maShapeList.end() )
120 return (*maIter++);
122 else
124 return nullptr;
128 void ShapeList::seekShape( sal_uInt32 nIndex )
130 maIter = maShapeList.begin();
131 nIndex = std::min(nIndex, static_cast<sal_uInt32>(maShapeList.size()));
132 std::advance(maIter, nIndex);
135 bool ShapeList::hasMore() const
137 return maIter != maShapeList.end();
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */