LibreOffice Module sd (master) 1
ConfigurationClassifier.cxx
Go to the documentation of this file.
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
21
23#include <com/sun/star/drawing/framework/XConfiguration.hpp>
24#include <sal/log.hxx>
25
26using namespace ::com::sun::star;
27using namespace ::com::sun::star::uno;
29
30namespace sd::framework {
31
33 const Reference<XConfiguration>& rxConfiguration1,
34 const Reference<XConfiguration>& rxConfiguration2)
35 : mxConfiguration1(rxConfiguration1),
36 mxConfiguration2(rxConfiguration2)
37{
38}
39
41{
42 maC1minusC2.clear();
43 maC2minusC1.clear();
44
46 mxConfiguration1->getResources(nullptr, OUString(), AnchorBindingMode_DIRECT),
47 mxConfiguration2->getResources(nullptr, OUString(), AnchorBindingMode_DIRECT));
48
49 return !maC1minusC2.empty() || !maC2minusC1.empty();
50}
51
53 const css::uno::Sequence<Reference<XResourceId> >& rS1,
54 const css::uno::Sequence<Reference<XResourceId> >& rS2)
55{
56 ResourceIdVector aC1minusC2;
57 ResourceIdVector aC2minusC1;
58 ResourceIdVector aC1andC2;
59
60 // Classify the resources in the configurations that are not bound to
61 // other resources.
63 rS1,
64 rS2,
65 aC1minusC2,
66 aC2minusC1,
67 aC1andC2);
68
69 SAL_INFO("sd.fwk", __func__ << ": copying resource ids to C1-C2");
71 SAL_INFO("sd.fwk", __func__ << ": copying resource ids to C2-C1");
73
74 // Process the unique resources that belong to both configurations.
75 for (const auto& rxResource : aC1andC2)
76 {
78 mxConfiguration1->getResources(rxResource, OUString(), AnchorBindingMode_DIRECT),
79 mxConfiguration2->getResources(rxResource, OUString(), AnchorBindingMode_DIRECT));
80 }
81}
82
84 const css::uno::Sequence<Reference<XResourceId> >& rS1,
85 const css::uno::Sequence<Reference<XResourceId> >& rS2,
86 ResourceIdVector& rS1minusS2,
87 ResourceIdVector& rS2minusS1,
88 ResourceIdVector& rS1andS2)
89{
90 // Find all elements in rS1 and place them in rS1minusS2 or rS1andS2
91 // depending on whether they are in rS2 or not.
92 for (const Reference<XResourceId>& rA1 : rS1)
93 {
94 bool bFound = std::any_of(rS2.begin(), rS2.end(),
95 [&rA1](const Reference<XResourceId>& rA2) {
96 return rA1->getResourceURL() == rA2->getResourceURL(); });
97
98 if (bFound)
99 rS1andS2.push_back(rA1);
100 else
101 rS1minusS2.push_back(rA1);
102 }
103
104 // Find all elements in rS2 that are not in rS1. The elements that are
105 // in both rS1 and rS2 have been handled above and are therefore ignored
106 // here.
107 for (const Reference<XResourceId>& rA2 : rS2)
108 {
109 bool bFound = std::any_of(rS1.begin(), rS1.end(),
110 [&rA2](const Reference<XResourceId>& rA1) {
111 return rA2->getResourceURL() == rA1->getResourceURL(); });
112
113 if ( ! bFound)
114 rS2minusS1.push_back(rA2);
115 }
116}
117
119 const ResourceIdVector& rSource,
120 const Reference<XConfiguration>& rxConfiguration,
121 ResourceIdVector& rTarget)
122{
123 // Copy all resources bound to the ones in aC1minusC2Unique to rC1minusC2.
124 for (const auto& rxResource : rSource)
125 {
126 const Sequence<Reference<XResourceId> > aBoundResources (
127 rxConfiguration->getResources(
128 rxResource,
129 OUString(),
130 AnchorBindingMode_INDIRECT));
131 const sal_Int32 nL (aBoundResources.getLength());
132
133 rTarget.reserve(rTarget.size() + 1 + nL);
134 rTarget.push_back(rxResource);
135
136 SAL_INFO("sd.fwk", __func__ << ": copying " <<
138
139 for (const Reference<XResourceId>& rBoundResource : aBoundResources)
140 {
141 rTarget.push_back(rBoundResource);
142 SAL_INFO("sd.fwk", __func__ << ": copying " <<
144 }
145 }
146}
147
148#if DEBUG_SD_CONFIGURATION_TRACE
149
150void ConfigurationClassifier::TraceResourceIdVector (
151 const char* pMessage,
152 const ResourceIdVector& rResources)
153{
154
155 SAL_INFO("sd.fwk", __func__ << ": " << pMessage);
156 for (const auto& rxResource : rResources)
157 {
158 OUString sResource (FrameworkHelper::ResourceIdToString(rxResource));
159 SAL_INFO("sd.fwk", __func__ << ": " << sResource);
160 }
161}
162
163#endif
164
165} // end of namespace sd::framework
166
167/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::drawing::framework::XConfiguration > mxConfiguration1
ConfigurationClassifier(const css::uno::Reference< css::drawing::framework::XConfiguration > &rxConfiguration1, const css::uno::Reference< css::drawing::framework::XConfiguration > &rxConfiguration2)
Create a new ConfigurationClassifier object that will compare the two given configurations.
static void ClassifyResources(const css::uno::Sequence< css::uno::Reference< css::drawing::framework::XResourceId > > &rS1, const css::uno::Sequence< css::uno::Reference< css::drawing::framework::XResourceId > > &rS2, ResourceIdVector &rS1minusS2, ResourceIdVector &rS2minusS1, ResourceIdVector &rS1andS2)
Compare the given sequences of resource ids and put their elements in one of three vectors depending ...
ResourceIdVector maC1minusC2
After the call to Classify() this vector holds all elements from mxConfiguration1 that are not in mxC...
bool Partition()
Calculate three lists of resource ids.
void PartitionResources(const css::uno::Sequence< css::uno::Reference< css::drawing::framework::XResourceId > > &rS1, const css::uno::Sequence< css::uno::Reference< css::drawing::framework::XResourceId > > &rS2)
Put all the elements in the two given sequences of resource ids and copy them into one of the resourc...
::std::vector< css::uno::Reference< css::drawing::framework::XResourceId > > ResourceIdVector
static void CopyResources(const ResourceIdVector &rSource, const css::uno::Reference< css::drawing::framework::XConfiguration > &rxConfiguration, ResourceIdVector &rTarget)
Copy the resources given in rSource to the list of resources specified by rTarget.
ResourceIdVector maC2minusC1
After the call to Classify() this vector holds all elements from mxConfiguration2 that are not in mxC...
css::uno::Reference< css::drawing::framework::XConfiguration > mxConfiguration2
static OUString ResourceIdToString(const css::uno::Reference< css::drawing::framework::XResourceId > &rxResourceId)
Return a string representation of the given XResourceId object.
FilterGroup & rTarget
#define SAL_INFO(area, stream)