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 <comphelper/sequenceashashmap.hxx>
21 :
22 :
23 : namespace comphelper{
24 :
25 957740 : SequenceAsHashMap::SequenceAsHashMap()
26 957740 : : SequenceAsHashMapBase()
27 : {
28 957740 : }
29 :
30 20480 : SequenceAsHashMap::SequenceAsHashMap(const css::uno::Any& aSource)
31 : {
32 20480 : (*this) << aSource;
33 20480 : }
34 :
35 :
36 2210 : SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence< css::uno::Any >& lSource)
37 : {
38 2210 : (*this) << lSource;
39 2210 : }
40 :
41 28701 : SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence< css::beans::PropertyValue >& lSource)
42 : {
43 28701 : (*this) << lSource;
44 28701 : }
45 :
46 1716 : SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence< css::beans::NamedValue >& lSource)
47 : {
48 1716 : (*this) << lSource;
49 1716 : }
50 :
51 1759500 : SequenceAsHashMap::~SequenceAsHashMap()
52 : {
53 1759500 : }
54 :
55 20484 : void SequenceAsHashMap::operator<<(const css::uno::Any& aSource)
56 : {
57 : // An empty Any reset this instance!
58 20484 : if (!aSource.hasValue())
59 : {
60 13 : clear();
61 13 : return;
62 : }
63 :
64 20471 : css::uno::Sequence< css::beans::NamedValue > lN;
65 20471 : if (aSource >>= lN)
66 : {
67 0 : (*this) << lN;
68 0 : return;
69 : }
70 :
71 40942 : css::uno::Sequence< css::beans::PropertyValue > lP;
72 20471 : if (aSource >>= lP)
73 : {
74 20470 : (*this) << lP;
75 20470 : return;
76 : }
77 :
78 : throw css::beans::IllegalTypeException(
79 : OUString( "Any contains wrong type." ),
80 20472 : css::uno::Reference< css::uno::XInterface >());
81 : }
82 :
83 :
84 2210 : void SequenceAsHashMap::operator<<(const css::uno::Sequence< css::uno::Any >& lSource)
85 : {
86 2210 : sal_Int32 c = lSource.getLength();
87 2210 : sal_Int32 i = 0;
88 :
89 12721 : for (i=0; i<c; ++i)
90 : {
91 10511 : css::beans::PropertyValue lP;
92 10511 : if (lSource[i] >>= lP)
93 : {
94 0 : if (
95 0 : (lP.Name.isEmpty()) ||
96 0 : (!lP.Value.hasValue())
97 : )
98 : throw css::beans::IllegalTypeException(
99 : OUString( "PropertyValue struct contains no useful information." ),
100 0 : css::uno::Reference< css::uno::XInterface >());
101 0 : (*this)[lP.Name] = lP.Value;
102 0 : continue;
103 : }
104 :
105 10511 : css::beans::NamedValue lN;
106 10511 : if (lSource[i] >>= lN)
107 : {
108 10511 : if (
109 21022 : (lN.Name.isEmpty()) ||
110 10511 : (!lN.Value.hasValue())
111 : )
112 : throw css::beans::IllegalTypeException(
113 : OUString( "NamedValue struct contains no useful information." ),
114 0 : css::uno::Reference< css::uno::XInterface >());
115 10511 : (*this)[lN.Name] = lN.Value;
116 10511 : continue;
117 : }
118 :
119 : // ignore VOID Any ... but reject wrong filled ones!
120 0 : if (lSource[i].hasValue())
121 : throw css::beans::IllegalTypeException(
122 : OUString( "Any contains wrong type." ),
123 0 : css::uno::Reference< css::uno::XInterface >());
124 0 : }
125 2210 : }
126 :
127 55273 : void SequenceAsHashMap::operator<<(const css::uno::Sequence< css::beans::PropertyValue >& lSource)
128 : {
129 55273 : clear();
130 :
131 55273 : sal_Int32 c = lSource.getLength();
132 55273 : const css::beans::PropertyValue* pSource = lSource.getConstArray();
133 :
134 464753 : for (sal_Int32 i=0; i<c; ++i)
135 409480 : (*this)[pSource[i].Name] = pSource[i].Value;
136 55273 : }
137 :
138 36294 : void SequenceAsHashMap::operator<<(const css::uno::Sequence< css::beans::NamedValue >& lSource)
139 : {
140 36294 : clear();
141 :
142 36294 : sal_Int32 c = lSource.getLength();
143 36294 : const css::beans::NamedValue* pSource = lSource.getConstArray();
144 :
145 76883 : for (sal_Int32 i=0; i<c; ++i)
146 40589 : (*this)[pSource[i].Name] = pSource[i].Value;
147 36294 : }
148 :
149 54016 : void SequenceAsHashMap::operator>>(css::uno::Sequence< css::beans::PropertyValue >& lDestination) const
150 : {
151 54016 : sal_Int32 c = (sal_Int32)size();
152 54016 : lDestination.realloc(c);
153 54016 : css::beans::PropertyValue* pDestination = lDestination.getArray();
154 :
155 54016 : sal_Int32 i = 0;
156 1267629 : for (const_iterator pThis = begin();
157 845086 : pThis != end() ;
158 : ++pThis )
159 : {
160 368527 : pDestination[i].Name = pThis->first ;
161 368527 : pDestination[i].Value = pThis->second;
162 368527 : ++i;
163 : }
164 54016 : }
165 :
166 30 : void SequenceAsHashMap::operator>>(css::uno::Sequence< css::beans::NamedValue >& lDestination) const
167 : {
168 30 : sal_Int32 c = (sal_Int32)size();
169 30 : lDestination.realloc(c);
170 30 : css::beans::NamedValue* pDestination = lDestination.getArray();
171 :
172 30 : sal_Int32 i = 0;
173 354 : for (const_iterator pThis = begin();
174 236 : pThis != end() ;
175 : ++pThis )
176 : {
177 88 : pDestination[i].Name = pThis->first ;
178 88 : pDestination[i].Value = pThis->second;
179 88 : ++i;
180 : }
181 30 : }
182 :
183 1 : const css::uno::Any SequenceAsHashMap::getAsConstAny(bool bAsPropertyValueList) const
184 : {
185 1 : css::uno::Any aDestination;
186 1 : if (bAsPropertyValueList)
187 0 : aDestination = css::uno::makeAny(getAsConstPropertyValueList());
188 : else
189 1 : aDestination = css::uno::makeAny(getAsConstNamedValueList());
190 1 : return aDestination;
191 : }
192 :
193 30 : const css::uno::Sequence< css::beans::NamedValue > SequenceAsHashMap::getAsConstNamedValueList() const
194 : {
195 30 : css::uno::Sequence< css::beans::NamedValue > lReturn;
196 30 : (*this) >> lReturn;
197 30 : return lReturn;
198 : }
199 :
200 44596 : const css::uno::Sequence< css::beans::PropertyValue > SequenceAsHashMap::getAsConstPropertyValueList() const
201 : {
202 44596 : css::uno::Sequence< css::beans::PropertyValue > lReturn;
203 44596 : (*this) >> lReturn;
204 44596 : return lReturn;
205 : }
206 :
207 0 : bool SequenceAsHashMap::match(const SequenceAsHashMap& rCheck) const
208 : {
209 0 : const_iterator pCheck;
210 0 : for ( pCheck = rCheck.begin();
211 0 : pCheck != rCheck.end() ;
212 : ++pCheck )
213 : {
214 0 : const OUString& sCheckName = pCheck->first;
215 0 : const css::uno::Any& aCheckValue = pCheck->second;
216 0 : const_iterator pFound = find(sCheckName);
217 :
218 0 : if (pFound == end())
219 0 : return false;
220 :
221 0 : const css::uno::Any& aFoundValue = pFound->second;
222 0 : if (aFoundValue != aCheckValue)
223 0 : return false;
224 : }
225 :
226 0 : return true;
227 : }
228 :
229 0 : void SequenceAsHashMap::update(const SequenceAsHashMap& rUpdate)
230 : {
231 0 : const_iterator pUpdate;
232 0 : for ( pUpdate = rUpdate.begin();
233 0 : pUpdate != rUpdate.end() ;
234 : ++pUpdate )
235 : {
236 0 : const OUString& sName = pUpdate->first;
237 0 : const css::uno::Any& aValue = pUpdate->second;
238 :
239 0 : (*this)[sName] = aValue;
240 : }
241 0 : }
242 :
243 : } // namespace comphelper
244 :
245 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|