LCOV - code coverage report
Current view: top level - sd/source/ui/slidesorter/model - SlsPageEnumeration.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 34 58 58.6 %
Date: 2014-04-11 Functions: 12 20 60.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      21             : #include "model/SlideSorterModel.hxx"
      22             : #include "model/SlsPageDescriptor.hxx"
      23             : 
      24             : using namespace ::sd::slidesorter;
      25             : using namespace ::sd::slidesorter::model;
      26             : 
      27             : namespace {
      28             : 
      29             : class PageEnumerationImpl
      30             :     : public Enumeration<SharedPageDescriptor>
      31             : {
      32             : public:
      33             :     inline PageEnumerationImpl (
      34             :         const SlideSorterModel& rModel,
      35             :         const PageEnumeration::PagePredicate& rPredicate);
      36             :     virtual ~PageEnumerationImpl (void);
      37             :     /** Create a copy of the called enumeration object.
      38             :     */
      39             :     SAL_WNODEPRECATED_DECLARATIONS_PUSH
      40             :     virtual ::std::auto_ptr<Enumeration<SharedPageDescriptor> > Clone (void) SAL_OVERRIDE;
      41             :     SAL_WNODEPRECATED_DECLARATIONS_POP
      42             : 
      43             :     virtual bool HasMoreElements (void) const SAL_OVERRIDE;
      44             :     virtual SharedPageDescriptor GetNextElement (void) SAL_OVERRIDE;
      45             :     virtual void Rewind (void) SAL_OVERRIDE;
      46             : 
      47             : private:
      48             :     const SlideSorterModel& mrModel;
      49             :     const PageEnumeration::PagePredicate maPredicate;
      50             :     int mnIndex;
      51             : 
      52             :     /** This constructor sets the internal page index to the given value.
      53             :         It does not call AdvanceToNextValidElement() to skip elements that
      54             :         do not fullfill Predicate.
      55             :     */
      56             :     inline PageEnumerationImpl (
      57             :         const SlideSorterModel& rModel,
      58             :         const PageEnumeration::PagePredicate& rPredicate,
      59             :         int nIndex);
      60             : 
      61             :     /** Skip all elements that do not fullfill Predicate starting with the
      62             :         one pointed to by mnIndex.
      63             :     */
      64             :     inline void AdvanceToNextValidElement (void);
      65             : 
      66             :     // Assignment operator not implemented.
      67             :     PageEnumerationImpl& operator= (const PageEnumerationImpl&);
      68             : };
      69             : 
      70             : } // end of anonymouse namespace
      71             : 
      72             : 
      73             : 
      74             : 
      75             : namespace sd { namespace slidesorter { namespace model {
      76             : 
      77             : SAL_WNODEPRECATED_DECLARATIONS_PUSH
      78        2639 : PageEnumeration PageEnumeration::Create (
      79             :     const SlideSorterModel& rModel,
      80             :     const PagePredicate& rPredicate)
      81             : {
      82             :     return PageEnumeration(::std::auto_ptr<Enumeration<SharedPageDescriptor> >(
      83        2639 :         new PageEnumerationImpl(rModel, rPredicate)));
      84             : }
      85             : SAL_WNODEPRECATED_DECLARATIONS_POP
      86             : 
      87             : 
      88             : SAL_WNODEPRECATED_DECLARATIONS_PUSH
      89        2639 : PageEnumeration::PageEnumeration (
      90             :     ::std::auto_ptr<Enumeration<SharedPageDescriptor> > pImpl)
      91        2639 :     : mpImpl(pImpl)
      92             : {
      93        2639 : }
      94             : SAL_WNODEPRECATED_DECLARATIONS_POP
      95             : 
      96             : 
      97             : 
      98           0 : PageEnumeration::PageEnumeration (
      99             :     PageEnumeration& rEnumeration,
     100           0 :     bool bCloneImpl)
     101             : {
     102             : 
     103           0 :     if( bCloneImpl )
     104             :     {
     105           0 :         mpImpl = rEnumeration.mpImpl->Clone();
     106             :     }
     107             :     else
     108             :     {
     109           0 :         mpImpl = rEnumeration.mpImpl;
     110             :     }
     111           0 : }
     112             : 
     113             : 
     114             : 
     115             : 
     116           0 : PageEnumeration::PageEnumeration (const PageEnumeration& rEnumeration )
     117           0 : : sd::slidesorter::model::Enumeration<sd::slidesorter::model::SharedPageDescriptor>()
     118             : {
     119           0 :     mpImpl = rEnumeration.mpImpl->Clone();
     120           0 : }
     121             : 
     122             : 
     123             : 
     124             : 
     125        2639 : PageEnumeration::~PageEnumeration (void)
     126             : {
     127        2639 : }
     128             : 
     129             : 
     130             : 
     131             : 
     132           0 : PageEnumeration& PageEnumeration::operator= (
     133             :     const PageEnumeration& rEnumeration)
     134             : {
     135           0 :     mpImpl = rEnumeration.mpImpl->Clone();
     136           0 :     return *this;
     137             : }
     138             : 
     139             : 
     140             : 
     141             : SAL_WNODEPRECATED_DECLARATIONS_PUSH
     142           0 : ::std::auto_ptr<Enumeration<SharedPageDescriptor> > PageEnumeration::Clone (void)
     143             : {
     144             :     return ::std::auto_ptr<Enumeration<SharedPageDescriptor> >(
     145           0 :         new PageEnumeration (*this, true));
     146             : }
     147             : SAL_WNODEPRECATED_DECLARATIONS_POP
     148             : 
     149             : 
     150             : 
     151        4943 : bool PageEnumeration::HasMoreElements (void) const
     152             : {
     153        4943 :     return mpImpl->HasMoreElements();
     154             : }
     155             : 
     156             : 
     157             : 
     158        2509 : SharedPageDescriptor PageEnumeration::GetNextElement (void)
     159             : {
     160        2509 :     return mpImpl->GetNextElement();
     161             : }
     162             : 
     163             : 
     164             : 
     165             : 
     166           0 : void PageEnumeration::Rewind (void)
     167             : {
     168           0 :     return mpImpl->Rewind();
     169             : }
     170             : 
     171             : } } } // end of namespace ::sd::slidesorter::model
     172             : 
     173             : 
     174             : 
     175             : 
     176             : namespace {
     177             : 
     178        2639 : PageEnumerationImpl::PageEnumerationImpl (
     179             :     const SlideSorterModel& rModel,
     180             :     const PageEnumeration::PagePredicate& rPredicate)
     181             :     : mrModel(rModel),
     182             :       maPredicate(rPredicate),
     183        2639 :       mnIndex(0)
     184             : {
     185        2639 :     Rewind();
     186        2639 : }
     187             : 
     188             : 
     189             : 
     190             : 
     191           0 : PageEnumerationImpl::PageEnumerationImpl (
     192             :     const SlideSorterModel& rModel,
     193             :     const PageEnumeration::PagePredicate& rPredicate,
     194             :     int nIndex)
     195             :     : mrModel(rModel),
     196             :       maPredicate(rPredicate),
     197           0 :       mnIndex(nIndex)
     198             : {
     199           0 : }
     200             : 
     201             : 
     202             : 
     203             : 
     204        5278 : PageEnumerationImpl::~PageEnumerationImpl (void)
     205             : {
     206        5278 : }
     207             : 
     208             : 
     209             : 
     210             : SAL_WNODEPRECATED_DECLARATIONS_PUSH
     211             : ::std::auto_ptr<Enumeration<SharedPageDescriptor> >
     212           0 :     PageEnumerationImpl::Clone (void)
     213             : {
     214             :     return ::std::auto_ptr<Enumeration<SharedPageDescriptor> >(
     215           0 :         new PageEnumerationImpl(mrModel,maPredicate,mnIndex));
     216             : }
     217             : SAL_WNODEPRECATED_DECLARATIONS_POP
     218             : 
     219             : 
     220             : 
     221        4943 : bool PageEnumerationImpl::HasMoreElements (void) const
     222             : {
     223        4943 :     return (mnIndex < mrModel.GetPageCount());
     224             : }
     225             : 
     226             : 
     227             : 
     228             : 
     229        2509 : SharedPageDescriptor PageEnumerationImpl::GetNextElement (void)
     230             : {
     231        2509 :     SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(mnIndex));
     232             : 
     233             :     // Go to the following valid element.
     234        2509 :     mnIndex += 1;
     235        2509 :     AdvanceToNextValidElement();
     236             : 
     237        2509 :     return pDescriptor;
     238             : }
     239             : 
     240             : 
     241             : 
     242             : 
     243        2639 : void PageEnumerationImpl::Rewind (void)
     244             : {
     245             :     // Go to first valid element.
     246        2639 :     mnIndex = 0;
     247        2639 :     AdvanceToNextValidElement();
     248        2639 : }
     249             : 
     250             : 
     251             : 
     252             : 
     253             : 
     254        5148 : void PageEnumerationImpl::AdvanceToNextValidElement (void)
     255             : {
     256       10296 :     while (mnIndex < mrModel.GetPageCount())
     257             :     {
     258        2588 :         SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(mnIndex));
     259             : 
     260             :         // Test for the predicate being fullfilled.
     261        2588 :         if (pDescriptor.get()!=NULL && maPredicate(pDescriptor))
     262             :         {
     263             :             // This predicate is valid.
     264        2588 :             break;
     265             :         }
     266             :         else
     267             :         {
     268             :             // Advance to next predicate.
     269           0 :             mnIndex += 1;
     270             :         }
     271           0 :     }
     272        5148 : }
     273             : 
     274             : } // end of anonymous namespace
     275             : 
     276             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10