LCOV - code coverage report
Current view: top level - libreoffice/sd/source/ui/slidesorter/model - SlsPageEnumeration.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 57 0.0 %
Date: 2012-12-27 Functions: 0 20 0.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 inline ::std::auto_ptr<Enumeration<SharedPageDescriptor> > Clone (void);
      41             :     SAL_WNODEPRECATED_DECLARATIONS_POP
      42             : 
      43             :     virtual inline bool HasMoreElements (void) const;
      44             :     virtual inline SharedPageDescriptor GetNextElement (void);
      45             :     virtual inline void Rewind (void);
      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             :     // Default constructor not implemented.
      67             :     PageEnumerationImpl (void);
      68             :     // Assignment operator not implemented.
      69             :     PageEnumerationImpl& operator= (const PageEnumerationImpl&);
      70             : };
      71             : 
      72             : } // end of anonymouse namespace
      73             : 
      74             : 
      75             : 
      76             : 
      77             : namespace sd { namespace slidesorter { namespace model {
      78             : 
      79             : SAL_WNODEPRECATED_DECLARATIONS_PUSH
      80           0 : PageEnumeration PageEnumeration::Create (
      81             :     const SlideSorterModel& rModel,
      82             :     const PagePredicate& rPredicate)
      83             : {
      84             :     return PageEnumeration(::std::auto_ptr<Enumeration<SharedPageDescriptor> >(
      85           0 :         new PageEnumerationImpl(rModel, rPredicate)));
      86             : }
      87             : SAL_WNODEPRECATED_DECLARATIONS_POP
      88             : 
      89             : 
      90             : SAL_WNODEPRECATED_DECLARATIONS_PUSH
      91           0 : PageEnumeration::PageEnumeration (
      92             :     ::std::auto_ptr<Enumeration<SharedPageDescriptor> > pImpl)
      93           0 :     : mpImpl(pImpl)
      94             : {
      95           0 : }
      96             : SAL_WNODEPRECATED_DECLARATIONS_POP
      97             : 
      98             : 
      99             : 
     100           0 : PageEnumeration::PageEnumeration (
     101             :     PageEnumeration& rEnumeration,
     102           0 :     bool bCloneImpl)
     103             : {
     104             : 
     105           0 :     if( bCloneImpl )
     106             :     {
     107           0 :         mpImpl = rEnumeration.mpImpl->Clone();
     108             :     }
     109             :     else
     110             :     {
     111           0 :         mpImpl = rEnumeration.mpImpl;
     112             :     }
     113           0 : }
     114             : 
     115             : 
     116             : 
     117             : 
     118           0 : PageEnumeration::PageEnumeration (const PageEnumeration& rEnumeration )
     119           0 : : sd::slidesorter::model::Enumeration<sd::slidesorter::model::SharedPageDescriptor>()
     120             : {
     121           0 :     mpImpl = rEnumeration.mpImpl->Clone();
     122           0 : }
     123             : 
     124             : 
     125             : 
     126             : 
     127           0 : PageEnumeration::~PageEnumeration (void)
     128             : {
     129           0 : }
     130             : 
     131             : 
     132             : 
     133             : 
     134           0 : PageEnumeration& PageEnumeration::operator= (
     135             :     const PageEnumeration& rEnumeration)
     136             : {
     137           0 :     mpImpl = rEnumeration.mpImpl->Clone();
     138           0 :     return *this;
     139             : }
     140             : 
     141             : 
     142             : 
     143             : SAL_WNODEPRECATED_DECLARATIONS_PUSH
     144           0 : ::std::auto_ptr<Enumeration<SharedPageDescriptor> > PageEnumeration::Clone (void)
     145             : {
     146             :     return ::std::auto_ptr<Enumeration<SharedPageDescriptor> >(
     147           0 :         new PageEnumeration (*this, true));
     148             : }
     149             : SAL_WNODEPRECATED_DECLARATIONS_POP
     150             : 
     151             : 
     152             : 
     153           0 : bool PageEnumeration::HasMoreElements (void) const
     154             : {
     155           0 :     return mpImpl->HasMoreElements();
     156             : }
     157             : 
     158             : 
     159             : 
     160           0 : SharedPageDescriptor PageEnumeration::GetNextElement (void)
     161             : {
     162           0 :     return mpImpl->GetNextElement();
     163             : }
     164             : 
     165             : 
     166             : 
     167             : 
     168           0 : void PageEnumeration::Rewind (void)
     169             : {
     170           0 :     return mpImpl->Rewind();
     171             : }
     172             : 
     173             : } } } // end of namespace ::sd::slidesorter::model
     174             : 
     175             : 
     176             : 
     177             : 
     178             : namespace {
     179             : 
     180           0 : PageEnumerationImpl::PageEnumerationImpl (
     181             :     const SlideSorterModel& rModel,
     182             :     const PageEnumeration::PagePredicate& rPredicate)
     183             :     : mrModel(rModel),
     184             :       maPredicate(rPredicate),
     185           0 :       mnIndex(0)
     186             : {
     187           0 :     Rewind();
     188           0 : }
     189             : 
     190             : 
     191             : 
     192             : 
     193           0 : PageEnumerationImpl::PageEnumerationImpl (
     194             :     const SlideSorterModel& rModel,
     195             :     const PageEnumeration::PagePredicate& rPredicate,
     196             :     int nIndex)
     197             :     : mrModel(rModel),
     198             :       maPredicate(rPredicate),
     199           0 :       mnIndex(nIndex)
     200             : {
     201           0 : }
     202             : 
     203             : 
     204             : 
     205             : 
     206           0 : PageEnumerationImpl::~PageEnumerationImpl (void)
     207             : {
     208           0 : }
     209             : 
     210             : 
     211             : 
     212             : SAL_WNODEPRECATED_DECLARATIONS_PUSH
     213             : ::std::auto_ptr<Enumeration<SharedPageDescriptor> >
     214           0 :     PageEnumerationImpl::Clone (void)
     215             : {
     216             :     return ::std::auto_ptr<Enumeration<SharedPageDescriptor> >(
     217           0 :         new PageEnumerationImpl(mrModel,maPredicate,mnIndex));
     218             : }
     219             : SAL_WNODEPRECATED_DECLARATIONS_POP
     220             : 
     221             : 
     222             : 
     223           0 : bool PageEnumerationImpl::HasMoreElements (void) const
     224             : {
     225           0 :     return (mnIndex < mrModel.GetPageCount());
     226             : }
     227             : 
     228             : 
     229             : 
     230             : 
     231           0 : SharedPageDescriptor PageEnumerationImpl::GetNextElement (void)
     232             : {
     233           0 :     SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(mnIndex));
     234             : 
     235             :     // Go to the following valid element.
     236           0 :     mnIndex += 1;
     237           0 :     AdvanceToNextValidElement();
     238             : 
     239           0 :     return pDescriptor;
     240             : }
     241             : 
     242             : 
     243             : 
     244             : 
     245           0 : void PageEnumerationImpl::Rewind (void)
     246             : {
     247             :     // Go to first valid element.
     248           0 :     mnIndex = 0;
     249           0 :     AdvanceToNextValidElement();
     250           0 : }
     251             : 
     252             : 
     253             : 
     254             : 
     255             : 
     256           0 : void PageEnumerationImpl::AdvanceToNextValidElement (void)
     257             : {
     258           0 :     while (mnIndex < mrModel.GetPageCount())
     259             :     {
     260           0 :         SharedPageDescriptor pDescriptor (mrModel.GetPageDescriptor(mnIndex));
     261             : 
     262             :         // Test for the predicate being fullfilled.
     263           0 :         if (pDescriptor.get()!=NULL && maPredicate(pDescriptor))
     264             :         {
     265             :             // This predicate is valid.
     266             :             break;
     267             :         }
     268             :         else
     269             :         {
     270             :             // Advance to next predicate.
     271           0 :             mnIndex += 1;
     272             :         }
     273           0 :     }
     274           0 : }
     275             : 
     276             : } // end of anonymous namespace
     277             : 
     278             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10