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