Bump version to 6.0-36
[LibreOffice.git] / slideshow / source / engine / unoviewcontainer.cxx
blob8306085ab5cc1d81d40a9a7ea7299c9ebbc8ddee
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 .
21 #include <unoviewcontainer.hxx>
23 #include <osl/diagnose.h>
25 #include <algorithm>
28 using namespace ::com::sun::star;
31 namespace slideshow
33 namespace internal
35 UnoViewContainer::UnoViewContainer() :
36 maViews()
40 bool UnoViewContainer::addView( const UnoViewSharedPtr& rView )
42 // check whether same view is already added
44 uno::Reference< presentation::XSlideShowView > rTmpView = rView->getUnoView();
45 // already added?
46 if( ::std::any_of( maViews.begin(),
47 maViews.end(),
48 [&rTmpView]( const UnoViewSharedPtr& pView )
49 { return rTmpView == pView->getUnoView(); } ) )
51 // yes, nothing to do
52 return false;
55 // add locally
56 maViews.push_back( rView );
58 return true;
61 UnoViewSharedPtr UnoViewContainer::removeView( const uno::Reference< presentation::XSlideShowView >& xView )
63 // check whether same view is already added
64 const UnoViewVector::iterator aEnd( maViews.end() );
65 UnoViewVector::iterator aIter;
67 // added in the first place?
68 if( (aIter=::std::find_if( maViews.begin(),
69 aEnd,
70 [&xView]( const UnoViewSharedPtr& pView )
71 { return xView == pView->getUnoView(); } )) == aEnd )
73 // nope, nothing to do
74 return UnoViewSharedPtr();
77 OSL_ENSURE(
78 ::std::count_if(
79 maViews.begin(),
80 aEnd,
81 [&xView]( const UnoViewSharedPtr& pView )
82 { return xView == pView->getUnoView(); } ) == 1,
83 "UnoViewContainer::removeView(): View was added multiple times" );
85 UnoViewSharedPtr pView( *aIter );
87 // actually erase from container
88 maViews.erase( aIter );
90 return pView;
93 void UnoViewContainer::dispose()
95 for( const auto& pView : maViews )
96 pView->_dispose();
97 maViews.clear();
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */