1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef SD_FRAMEWORK_CONFIGURATION_CLASSIFIER_HXX 25 #define SD_FRAMEWORK_CONFIGURATION_CLASSIFIER_HXX 26 27 #include <com/sun/star/drawing/framework/XConfiguration.hpp> 28 29 #include <vector> 30 31 namespace sd { namespace framework { 32 33 /** A ConfigurationClassifier object compares two configurations of 34 resources and gives access to the differences. It is used mainly when 35 changes to the current configuration have been requested and the various 36 resource controllers have to be supplied with the set of resources that 37 are to be activated or deactivated. 38 */ 39 class ConfigurationClassifier 40 { 41 public: 42 /** Create a new ConfigurationClassifier object that will compare the 43 two given configurations. 44 */ 45 ConfigurationClassifier ( 46 const ::com::sun::star::uno::Reference< 47 ::com::sun::star::drawing::framework::XConfiguration>& rxConfiguration1, 48 const ::com::sun::star::uno::Reference< 49 ::com::sun::star::drawing::framework::XConfiguration>& rxConfiguration2); 50 51 /** Calculate three lists of resource ids. These contain the resources 52 that belong to one configuration but not the other, or that belong 53 to both configurations. 54 @return 55 When the two configurations differ then return <TRUE/>. When 56 they are equivalent then return <FALSE/>. 57 */ 58 bool Partition (void); 59 60 typedef ::std::vector<com::sun::star::uno::Reference< 61 ::com::sun::star::drawing::framework::XResourceId> > ResourceIdVector; 62 63 /** Return the resources that belong to the configuration given as 64 rxConfiguration1 to the constructor but that do not belong to 65 rxConfiguration2. 66 @return 67 A reference to the, possibly empty, list of resources is 68 returned. This reference remains valid as long as the called 69 ConfigurationClassifier object stays alive. 70 */ 71 const ResourceIdVector& GetC1minusC2 (void) const; 72 73 /** Return the resources that belong to the configuration given as 74 rxConfiguration2 to the constructor but that do not belong to 75 rxConfiguration1. 76 @return 77 A reference to the, possibly empty, list of resources is 78 returned. This reference remains valid as long as the called 79 ConfigurationClassifier object stays alive. 80 */ 81 const ResourceIdVector& GetC2minusC1 (void) const; 82 83 /** Return the resources that belong to both the configurations that 84 where given to the constructor. 85 @return 86 A reference to the, possibly empty, list of resources is 87 returned. This reference remains valid as long as the called 88 ConfigurationClassifier object stays alive. 89 */ 90 const ResourceIdVector& GetC1andC2 (void) const; 91 92 void TraceResourceIdVector ( 93 const sal_Char* pMessage, 94 const ResourceIdVector& rResources) const; 95 96 private: 97 ::com::sun::star::uno::Reference< 98 ::com::sun::star::drawing::framework::XConfiguration> mxConfiguration1; 99 ::com::sun::star::uno::Reference< 100 ::com::sun::star::drawing::framework::XConfiguration> mxConfiguration2; 101 102 /** After the call to Classify() this vector holds all elements from 103 mxConfiguration1 that are not in mxConfiguration2. 104 */ 105 ResourceIdVector maC1minusC2; 106 107 /** After the call to Classify() this vector holds all elements from 108 mxConfiguration2 that are not in mxConfiguration1. 109 */ 110 ResourceIdVector maC2minusC1; 111 112 /** After the call to Classify() this vector holds all elements that are 113 member both of mxConfiguration1 and mxConfiguration2. 114 */ 115 ResourceIdVector maC1andC2; 116 117 /** Put all the elements in the two gven sequences of resource ids and 118 copy them into one of the resource id result vectors maC1minusC2, 119 maC2minusC1, and maC1andC2. This is done by using only the resource 120 URLs for classification. Therefor this method calls itself 121 recursively. 122 @param rS1 123 One sequence of XResourceId objects. 124 @param rS2 125 Another sequence of XResourceId objects. 126 */ 127 void PartitionResources ( 128 const ::com::sun::star::uno::Sequence< 129 ::com::sun::star::uno::Reference< 130 ::com::sun::star::drawing::framework::XResourceId> >& rS1, 131 const ::com::sun::star::uno::Sequence< 132 ::com::sun::star::uno::Reference< 133 ::com::sun::star::drawing::framework::XResourceId> >& rS2); 134 135 /** Compare the given sequences of resource ids and put their elements 136 in one of three vectors depending on whether an element belongs to 137 both sequences or to one but not the other. Note that only the 138 resource URLs of the XResourceId objects are used for the 139 classification. 140 @param rS1 141 One sequence of XResourceId objects. 142 @param rS2 143 Another sequence of XResourceId objects. 144 */ 145 void ClassifyResources ( 146 const ::com::sun::star::uno::Sequence< 147 ::com::sun::star::uno::Reference< 148 ::com::sun::star::drawing::framework::XResourceId> >& rS1, 149 const ::com::sun::star::uno::Sequence< 150 ::com::sun::star::uno::Reference< 151 ::com::sun::star::drawing::framework::XResourceId> >& rS2, 152 ResourceIdVector& rS1minusS2, 153 ResourceIdVector& rS2minusS1, 154 ResourceIdVector& rS1andS2); 155 156 157 /** Copy the resources given in rSource to the list of resources 158 specified by rTarget. Resources bound to the ones in rSource, 159 either directly or indirectly, are copied as well. 160 @param rSource 161 All resources and the ones bound to them, either directly or 162 indirectly, are copied. 163 @param rxConfiguration 164 This configuration is used to determine the resources bound to 165 the ones in rSource. 166 @param rTarget 167 This list is filled with resources from rSource and the ones 168 bound to them. 169 */ 170 void CopyResources ( 171 const ResourceIdVector& rSource, 172 const ::com::sun::star::uno::Reference< 173 ::com::sun::star::drawing::framework::XConfiguration>& rxConfiguration, 174 ResourceIdVector& rTarget); 175 }; 176 177 } } // end of namespace sd::framework 178 179 #endif 180