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 36313 : SequenceAsHashMap::SequenceAsHashMap()
26 36313 : : SequenceAsHashMapBase()
27 : {
28 36313 : }
29 :
30 1912 : SequenceAsHashMap::SequenceAsHashMap(const css::uno::Any& aSource)
31 : {
32 1912 : (*this) << aSource;
33 1912 : }
34 :
35 : //-----------------------------------------------
36 412 : SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence< css::uno::Any >& lSource)
37 : {
38 412 : (*this) << lSource;
39 412 : }
40 :
41 3176 : SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence< css::beans::PropertyValue >& lSource)
42 : {
43 3176 : (*this) << lSource;
44 3176 : }
45 :
46 10 : SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence< css::beans::NamedValue >& lSource)
47 : {
48 10 : (*this) << lSource;
49 10 : }
50 :
51 50749 : SequenceAsHashMap::~SequenceAsHashMap()
52 : {
53 50749 : }
54 :
55 1912 : void SequenceAsHashMap::operator<<(const css::uno::Any& aSource)
56 : {
57 : // An empty Any reset this instance!
58 1912 : if (!aSource.hasValue())
59 : {
60 0 : clear();
61 : return;
62 : }
63 :
64 1912 : css::uno::Sequence< css::beans::NamedValue > lN;
65 1912 : if (aSource >>= lN)
66 : {
67 0 : (*this) << lN;
68 : return;
69 : }
70 :
71 1912 : css::uno::Sequence< css::beans::PropertyValue > lP;
72 1912 : if (aSource >>= lP)
73 : {
74 1912 : (*this) << lP;
75 : return;
76 : }
77 :
78 : throw css::beans::IllegalTypeException(
79 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Any contains wrong type." )),
80 0 : css::uno::Reference< css::uno::XInterface >());
81 : }
82 :
83 : //-----------------------------------------------
84 412 : void SequenceAsHashMap::operator<<(const css::uno::Sequence< css::uno::Any >& lSource)
85 : {
86 412 : sal_Int32 c = lSource.getLength();
87 412 : sal_Int32 i = 0;
88 :
89 1741 : for (i=0; i<c; ++i)
90 : {
91 1329 : css::beans::PropertyValue lP;
92 1329 : if (lSource[i] >>= lP)
93 : {
94 28 : if (
95 14 : (lP.Name.isEmpty()) ||
96 14 : (!lP.Value.hasValue())
97 : )
98 : throw css::beans::IllegalTypeException(
99 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PropertyValue struct contains no usefull informations." )),
100 0 : css::uno::Reference< css::uno::XInterface >());
101 14 : (*this)[lP.Name] = lP.Value;
102 14 : continue;
103 : }
104 :
105 1315 : css::beans::NamedValue lN;
106 1315 : if (lSource[i] >>= lN)
107 : {
108 2630 : if (
109 1315 : (lN.Name.isEmpty()) ||
110 1315 : (!lN.Value.hasValue())
111 : )
112 : throw css::beans::IllegalTypeException(
113 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "NamedValue struct contains no usefull informations." )),
114 0 : css::uno::Reference< css::uno::XInterface >());
115 1315 : (*this)[lN.Name] = lN.Value;
116 1315 : continue;
117 : }
118 :
119 : // ignore VOID Any ... but reject wrong filled ones!
120 0 : if (lSource[i].hasValue())
121 : throw css::beans::IllegalTypeException(
122 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Any contains wrong type." )),
123 0 : css::uno::Reference< css::uno::XInterface >());
124 1315 : }
125 412 : }
126 :
127 5526 : void SequenceAsHashMap::operator<<(const css::uno::Sequence< css::beans::PropertyValue >& lSource)
128 : {
129 5526 : clear();
130 :
131 5526 : sal_Int32 c = lSource.getLength();
132 5526 : const css::beans::PropertyValue* pSource = lSource.getConstArray();
133 :
134 42074 : for (sal_Int32 i=0; i<c; ++i)
135 36548 : (*this)[pSource[i].Name] = pSource[i].Value;
136 5526 : }
137 :
138 4905 : void SequenceAsHashMap::operator<<(const css::uno::Sequence< css::beans::NamedValue >& lSource)
139 : {
140 4905 : clear();
141 :
142 4905 : sal_Int32 c = lSource.getLength();
143 4905 : const css::beans::NamedValue* pSource = lSource.getConstArray();
144 :
145 10000 : for (sal_Int32 i=0; i<c; ++i)
146 5095 : (*this)[pSource[i].Name] = pSource[i].Value;
147 4905 : }
148 :
149 5643 : void SequenceAsHashMap::operator>>(css::uno::Sequence< css::beans::PropertyValue >& lDestination) const
150 : {
151 5643 : sal_Int32 c = (sal_Int32)size();
152 5643 : lDestination.realloc(c);
153 5643 : css::beans::PropertyValue* pDestination = lDestination.getArray();
154 :
155 5643 : sal_Int32 i = 0;
156 92679 : for (const_iterator pThis = begin();
157 61786 : pThis != end() ;
158 : ++pThis )
159 : {
160 25250 : pDestination[i].Name = pThis->first ;
161 25250 : pDestination[i].Value = pThis->second;
162 25250 : ++i;
163 : }
164 5643 : }
165 :
166 22 : void SequenceAsHashMap::operator>>(css::uno::Sequence< css::beans::NamedValue >& lDestination) const
167 : {
168 22 : sal_Int32 c = (sal_Int32)size();
169 22 : lDestination.realloc(c);
170 22 : css::beans::NamedValue* pDestination = lDestination.getArray();
171 :
172 22 : sal_Int32 i = 0;
173 264 : for (const_iterator pThis = begin();
174 176 : pThis != end() ;
175 : ++pThis )
176 : {
177 66 : pDestination[i].Name = pThis->first ;
178 66 : pDestination[i].Value = pThis->second;
179 66 : ++i;
180 : }
181 22 : }
182 :
183 0 : const css::uno::Any SequenceAsHashMap::getAsConstAny(::sal_Bool bAsPropertyValueList) const
184 : {
185 0 : css::uno::Any aDestination;
186 0 : if (bAsPropertyValueList)
187 0 : aDestination = css::uno::makeAny(getAsConstPropertyValueList());
188 : else
189 0 : aDestination = css::uno::makeAny(getAsConstNamedValueList());
190 0 : return aDestination;
191 : }
192 :
193 22 : const css::uno::Sequence< css::beans::NamedValue > SequenceAsHashMap::getAsConstNamedValueList() const
194 : {
195 22 : css::uno::Sequence< css::beans::NamedValue > lReturn;
196 22 : (*this) >> lReturn;
197 22 : return lReturn;
198 : }
199 :
200 4801 : const css::uno::Sequence< css::beans::PropertyValue > SequenceAsHashMap::getAsConstPropertyValueList() const
201 : {
202 4801 : css::uno::Sequence< css::beans::PropertyValue > lReturn;
203 4801 : (*this) >> lReturn;
204 4801 : return lReturn;
205 : }
206 :
207 0 : sal_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 ::rtl::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 sal_False;
220 :
221 0 : const css::uno::Any& aFoundValue = pFound->second;
222 0 : if (aFoundValue != aCheckValue)
223 0 : return sal_False;
224 : }
225 :
226 0 : return sal_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 ::rtl::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: */
|