LCOV - code coverage report
Current view: top level - sd/source/ui/framework/configuration - ConfigurationClassifier.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 61 67 91.0 %
Date: 2014-11-03 Functions: 7 8 87.5 %
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             : #include "ConfigurationClassifier.hxx"
      21             : 
      22             : #include "framework/FrameworkHelper.hxx"
      23             : 
      24             : using namespace ::com::sun::star;
      25             : using namespace ::com::sun::star::uno;
      26             : using namespace ::com::sun::star::drawing::framework;
      27             : 
      28             : namespace sd { namespace framework {
      29             : 
      30         920 : ConfigurationClassifier::ConfigurationClassifier (
      31             :     const Reference<XConfiguration>& rxConfiguration1,
      32             :     const Reference<XConfiguration>& rxConfiguration2)
      33             :     : mxConfiguration1(rxConfiguration1),
      34             :       mxConfiguration2(rxConfiguration2),
      35             :       maC1minusC2(),
      36             :       maC2minusC1(),
      37         920 :       maC1andC2()
      38             : {
      39         920 : }
      40             : 
      41         920 : bool ConfigurationClassifier::Partition (void)
      42             : {
      43         920 :     maC1minusC2.clear();
      44         920 :     maC2minusC1.clear();
      45         920 :     maC1andC2.clear();
      46             : 
      47             :     PartitionResources(
      48         920 :         mxConfiguration1->getResources(NULL, OUString(), AnchorBindingMode_DIRECT),
      49        1840 :         mxConfiguration2->getResources(NULL, OUString(), AnchorBindingMode_DIRECT));
      50             : 
      51         920 :     return !maC1minusC2.empty() || !maC2minusC1.empty();
      52             : }
      53             : 
      54        1862 : void ConfigurationClassifier::PartitionResources (
      55             :     const ::com::sun::star::uno::Sequence<Reference<XResourceId> >& rS1,
      56             :     const ::com::sun::star::uno::Sequence<Reference<XResourceId> >& rS2)
      57             : {
      58        1862 :     ResourceIdVector aC1minusC2;
      59        3724 :     ResourceIdVector aC2minusC1;
      60        3724 :     ResourceIdVector aC1andC2;
      61             : 
      62             :     // Classify the resources in the configurations that are not bound to
      63             :     // other resources.
      64             :     ClassifyResources(
      65             :         rS1,
      66             :         rS2,
      67             :         aC1minusC2,
      68             :         aC2minusC1,
      69        1862 :         aC1andC2);
      70             : 
      71             :     SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": copying resource ids to C1-C2");
      72        1862 :     CopyResources(aC1minusC2, mxConfiguration1, maC1minusC2);
      73             :     SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": copying resource ids to C2-C1");
      74        1862 :     CopyResources(aC2minusC1, mxConfiguration2, maC2minusC1);
      75             : 
      76             :     // Process the unique resources that belong to both configurations.
      77        1862 :     ResourceIdVector::const_iterator iResource;
      78        2804 :     for (iResource=aC1andC2.begin(); iResource!=aC1andC2.end(); ++iResource)
      79             :     {
      80         942 :         maC1andC2.push_back(*iResource);
      81             :         PartitionResources(
      82        1884 :             mxConfiguration1->getResources(*iResource, OUString(), AnchorBindingMode_DIRECT),
      83        2826 :             mxConfiguration2->getResources(*iResource, OUString(), AnchorBindingMode_DIRECT));
      84        1862 :     }
      85        1862 : }
      86             : 
      87        1862 : void ConfigurationClassifier::ClassifyResources (
      88             :     const ::com::sun::star::uno::Sequence<Reference<XResourceId> >& rS1,
      89             :     const ::com::sun::star::uno::Sequence<Reference<XResourceId> >& rS2,
      90             :     ResourceIdVector& rS1minusS2,
      91             :     ResourceIdVector& rS2minusS1,
      92             :     ResourceIdVector& rS1andS2)
      93             : {
      94             :     // Get arrays from the sequences for faster iteration.
      95        1862 :     const Reference<XResourceId>* aA1 = rS1.getConstArray();
      96        1862 :     const Reference<XResourceId>* aA2 = rS2.getConstArray();
      97        1862 :     sal_Int32 nL1 (rS1.getLength());
      98        1862 :     sal_Int32 nL2 (rS2.getLength());
      99             : 
     100             :     // Find all elements in rS1 and place them in rS1minusS2 or rS1andS2
     101             :     // depending on whether they are in rS2 or not.
     102        3464 :     for (sal_Int32 i=0; i<nL1; ++i)
     103             :     {
     104        1602 :         bool bFound (false);
     105        2978 :         for (sal_Int32 j=0; j<nL2 && !bFound; ++j)
     106        1376 :             if (aA1[i]->getResourceURL().equals(aA2[j]->getResourceURL()))
     107         942 :                 bFound = true;
     108             : 
     109        1602 :         if (bFound)
     110         942 :             rS1andS2.push_back(aA1[i]);
     111             :         else
     112         660 :             rS1minusS2.push_back(aA1[i]);
     113             :     }
     114             : 
     115             :     // Find all elements in rS2 that are not in rS1.  The elements that are
     116             :     // in both rS1 and rS2 have been handled above and are therefore ignored
     117             :     // here.
     118        3618 :     for (sal_Int32 j=0; j<nL2; ++j)
     119             :     {
     120        1756 :         bool bFound (false);
     121        3132 :         for (sal_Int32 i=0; i<nL1 && !bFound; ++i)
     122        1376 :             if (aA2[j]->getResourceURL().equals(aA1[i]->getResourceURL()))
     123         942 :                 bFound = true;
     124             : 
     125        1756 :         if ( ! bFound)
     126         814 :             rS2minusS1.push_back(aA2[j]);
     127             :     }
     128        1862 : }
     129             : 
     130        3724 : void ConfigurationClassifier::CopyResources (
     131             :     const ResourceIdVector& rSource,
     132             :     const Reference<XConfiguration>& rxConfiguration,
     133             :     ResourceIdVector& rTarget)
     134             : {
     135             :     // Copy all resources bound to the ones in aC1minusC2Unique to rC1minusC2.
     136        3724 :     ResourceIdVector::const_iterator iResource (rSource.begin());
     137        3724 :     ResourceIdVector::const_iterator iEnd(rSource.end());
     138        5198 :     for ( ; iResource!=iEnd; ++iResource)
     139             :     {
     140             :         const Sequence<Reference<XResourceId> > aBoundResources (
     141        1474 :             rxConfiguration->getResources(
     142        1474 :                 *iResource,
     143             :                 OUString(),
     144        2948 :                 AnchorBindingMode_INDIRECT));
     145        1474 :         const sal_Int32 nL (aBoundResources.getLength());
     146             : 
     147        1474 :         rTarget.reserve(rTarget.size() + 1 + nL);
     148        1474 :         rTarget.push_back(*iResource);
     149             : 
     150             :         SAL_INFO("sd.fwk", OSL_THIS_FUNC << ":    copying " <<
     151             :             OUStringToOString(FrameworkHelper::ResourceIdToString(*iResource),
     152             :                 RTL_TEXTENCODING_UTF8).getStr());
     153             : 
     154        1474 :         const Reference<XResourceId>* aA = aBoundResources.getConstArray();
     155        3104 :         for (sal_Int32 i=0; i<nL; ++i)
     156             :         {
     157        1630 :             rTarget.push_back(aA[i]);
     158             :             SAL_INFO("sd.fwk", OSL_THIS_FUNC << ":    copying " <<
     159             :                 OUStringToOString(FrameworkHelper::ResourceIdToString(aA[i]),
     160             :                     RTL_TEXTENCODING_UTF8).getStr());
     161             :         }
     162        1474 :     }
     163        3724 : }
     164             : 
     165           0 : void ConfigurationClassifier::TraceResourceIdVector (
     166             :     const sal_Char* pMessage,
     167             :     const ResourceIdVector& rResources) const
     168             : {
     169             : 
     170             :     SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": " << pMessage);
     171           0 :     ResourceIdVector::const_iterator iResource;
     172           0 :     for (iResource=rResources.begin(); iResource!=rResources.end(); ++iResource)
     173             :     {
     174           0 :         OUString sResource (FrameworkHelper::ResourceIdToString(*iResource));
     175             :         SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": " <<
     176             :             OUStringToOString(sResource, RTL_TEXTENCODING_UTF8).getStr());
     177           0 :     }
     178           0 : }
     179             : 
     180         114 : } } // end of namespace sd::framework
     181             : 
     182             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10