LCOV - code coverage report
Current view: top level - sd/source/ui/framework/configuration - ConfigurationClassifier.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 64 72 88.9 %
Date: 2014-04-11 Functions: 7 9 77.8 %
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 "ConfigurationClassifier.hxx"
      22             : 
      23             : #include "framework/FrameworkHelper.hxx"
      24             : 
      25             : using namespace ::com::sun::star;
      26             : using namespace ::com::sun::star::uno;
      27             : using namespace ::com::sun::star::drawing::framework;
      28             : 
      29             : namespace sd { namespace framework {
      30             : 
      31         381 : ConfigurationClassifier::ConfigurationClassifier (
      32             :     const Reference<XConfiguration>& rxConfiguration1,
      33             :     const Reference<XConfiguration>& rxConfiguration2)
      34             :     : mxConfiguration1(rxConfiguration1),
      35             :       mxConfiguration2(rxConfiguration2),
      36             :       maC1minusC2(),
      37             :       maC2minusC1(),
      38         381 :       maC1andC2()
      39             : {
      40         381 : }
      41             : 
      42             : 
      43             : 
      44             : 
      45         381 : bool ConfigurationClassifier::Partition (void)
      46             : {
      47         381 :     maC1minusC2.clear();
      48         381 :     maC2minusC1.clear();
      49         381 :     maC1andC2.clear();
      50             : 
      51             :     PartitionResources(
      52         381 :         mxConfiguration1->getResources(NULL, OUString(), AnchorBindingMode_DIRECT),
      53         762 :         mxConfiguration2->getResources(NULL, OUString(), AnchorBindingMode_DIRECT));
      54             : 
      55         381 :     return !maC1minusC2.empty() || !maC2minusC1.empty();
      56             : }
      57             : 
      58             : 
      59             : 
      60             : 
      61         325 : const ConfigurationClassifier::ResourceIdVector& ConfigurationClassifier::GetC1minusC2 (void) const
      62             : {
      63         325 :     return maC1minusC2;
      64             : }
      65             : 
      66             : 
      67             : 
      68             : 
      69         325 : const ConfigurationClassifier::ResourceIdVector& ConfigurationClassifier::GetC2minusC1 (void) const
      70             : {
      71         325 :     return maC2minusC1;
      72             : }
      73             : 
      74             : 
      75             : 
      76           0 : const ConfigurationClassifier::ResourceIdVector& ConfigurationClassifier::GetC1andC2 (void) const
      77             : {
      78           0 :     return maC1andC2;
      79             : }
      80             : 
      81             : 
      82         958 : void ConfigurationClassifier::PartitionResources (
      83             :     const ::com::sun::star::uno::Sequence<Reference<XResourceId> >& rS1,
      84             :     const ::com::sun::star::uno::Sequence<Reference<XResourceId> >& rS2)
      85             : {
      86         958 :     ResourceIdVector aC1minusC2;
      87        1916 :     ResourceIdVector aC2minusC1;
      88        1916 :     ResourceIdVector aC1andC2;
      89             : 
      90             :     // Classify the resources in the configurations that are not bound to
      91             :     // other resources.
      92             :     ClassifyResources(
      93             :         rS1,
      94             :         rS2,
      95             :         aC1minusC2,
      96             :         aC2minusC1,
      97         958 :         aC1andC2);
      98             : 
      99             :     SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": copying resource ids to C1-C2");
     100         958 :     CopyResources(aC1minusC2, mxConfiguration1, maC1minusC2);
     101             :     SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": copying resource ids to C2-C1");
     102         958 :     CopyResources(aC2minusC1, mxConfiguration2, maC2minusC1);
     103             : 
     104             :     // Process the unique resources that belong to both configurations.
     105         958 :     ResourceIdVector::const_iterator iResource;
     106        1535 :     for (iResource=aC1andC2.begin(); iResource!=aC1andC2.end(); ++iResource)
     107             :     {
     108         577 :         maC1andC2.push_back(*iResource);
     109             :         PartitionResources(
     110        1154 :             mxConfiguration1->getResources(*iResource, OUString(), AnchorBindingMode_DIRECT),
     111        1731 :             mxConfiguration2->getResources(*iResource, OUString(), AnchorBindingMode_DIRECT));
     112         958 :     }
     113         958 : }
     114             : 
     115             : 
     116             : 
     117             : 
     118         958 : void ConfigurationClassifier::ClassifyResources (
     119             :     const ::com::sun::star::uno::Sequence<Reference<XResourceId> >& rS1,
     120             :     const ::com::sun::star::uno::Sequence<Reference<XResourceId> >& rS2,
     121             :     ResourceIdVector& rS1minusS2,
     122             :     ResourceIdVector& rS2minusS1,
     123             :     ResourceIdVector& rS1andS2)
     124             : {
     125             :     // Get arrays from the sequences for faster iteration.
     126         958 :     const Reference<XResourceId>* aA1 = rS1.getConstArray();
     127         958 :     const Reference<XResourceId>* aA2 = rS2.getConstArray();
     128         958 :     sal_Int32 nL1 (rS1.getLength());
     129         958 :     sal_Int32 nL2 (rS2.getLength());
     130             : 
     131             :     // Find all elements in rS1 and place them in rS1minusS2 or rS1andS2
     132             :     // depending on whether they are in rS2 or not.
     133        1820 :     for (sal_Int32 i=0; i<nL1; ++i)
     134             :     {
     135         862 :         bool bFound (false);
     136        1754 :         for (sal_Int32 j=0; j<nL2 && !bFound; ++j)
     137         892 :             if (aA1[i]->getResourceURL().equals(aA2[j]->getResourceURL()))
     138         577 :                 bFound = true;
     139             : 
     140         862 :         if (bFound)
     141         577 :             rS1andS2.push_back(aA1[i]);
     142             :         else
     143         285 :             rS1minusS2.push_back(aA1[i]);
     144             :     }
     145             : 
     146             :     // Find all elements in rS2 that are not in rS1.  The elements that are
     147             :     // in both rS1 and rS2 have been handled above and are therefore ignored
     148             :     // here.
     149        1838 :     for (sal_Int32 j=0; j<nL2; ++j)
     150             :     {
     151         880 :         bool bFound (false);
     152        1772 :         for (sal_Int32 i=0; i<nL1 && !bFound; ++i)
     153         892 :             if (aA2[j]->getResourceURL().equals(aA1[i]->getResourceURL()))
     154         577 :                 bFound = true;
     155             : 
     156         880 :         if ( ! bFound)
     157         303 :             rS2minusS1.push_back(aA2[j]);
     158             :     }
     159         958 : }
     160             : 
     161             : 
     162             : 
     163             : 
     164        1916 : void ConfigurationClassifier::CopyResources (
     165             :     const ResourceIdVector& rSource,
     166             :     const Reference<XConfiguration>& rxConfiguration,
     167             :     ResourceIdVector& rTarget)
     168             : {
     169             :     // Copy all resources bound to the ones in aC1minusC2Unique to rC1minusC2.
     170        1916 :     ResourceIdVector::const_iterator iResource (rSource.begin());
     171        1916 :     ResourceIdVector::const_iterator iEnd(rSource.end());
     172        2504 :     for ( ; iResource!=iEnd; ++iResource)
     173             :     {
     174             :         const Sequence<Reference<XResourceId> > aBoundResources (
     175         588 :             rxConfiguration->getResources(
     176         588 :                 *iResource,
     177             :                 OUString(),
     178        1176 :                 AnchorBindingMode_INDIRECT));
     179         588 :         const sal_Int32 nL (aBoundResources.getLength());
     180             : 
     181         588 :         rTarget.reserve(rTarget.size() + 1 + nL);
     182         588 :         rTarget.push_back(*iResource);
     183             : 
     184             :         SAL_INFO("sd.fwk", OSL_THIS_FUNC << ":    copying " <<
     185             :             OUStringToOString(FrameworkHelper::ResourceIdToString(*iResource),
     186             :                 RTL_TEXTENCODING_UTF8).getStr());
     187             : 
     188         588 :         const Reference<XResourceId>* aA = aBoundResources.getConstArray();
     189        1235 :         for (sal_Int32 i=0; i<nL; ++i)
     190             :         {
     191         647 :             rTarget.push_back(aA[i]);
     192             :             SAL_INFO("sd.fwk", OSL_THIS_FUNC << ":    copying " <<
     193             :                 OUStringToOString(FrameworkHelper::ResourceIdToString(aA[i]),
     194             :                     RTL_TEXTENCODING_UTF8).getStr());
     195             :         }
     196         588 :     }
     197        1916 : }
     198             : 
     199             : 
     200           0 : void ConfigurationClassifier::TraceResourceIdVector (
     201             :     const sal_Char* pMessage,
     202             :     const ResourceIdVector& rResources) const
     203             : {
     204             : 
     205             :     SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": " << pMessage);
     206           0 :     ResourceIdVector::const_iterator iResource;
     207           0 :     for (iResource=rResources.begin(); iResource!=rResources.end(); ++iResource)
     208             :     {
     209           0 :         OUString sResource (FrameworkHelper::ResourceIdToString(*iResource));
     210             :         SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": " <<
     211             :             OUStringToOString(sResource, RTL_TEXTENCODING_UTF8).getStr());
     212           0 :     }
     213           0 : }
     214             : 
     215             : 
     216             : } } // end of namespace sd::framework
     217             : 
     218             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10