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

Generated by: LCOV version 1.10