1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_comphelper.hxx"
31 //_______________________________________________
33 #include <comphelper/sequenceashashmap.hxx>
35 //_______________________________________________
40 namespace css
= ::com::sun::star
;
42 //_______________________________________________
45 /*-----------------------------------------------
47 -----------------------------------------------*/
48 SequenceAsHashMap::SequenceAsHashMap()
49 : SequenceAsHashMapBase()
53 /*-----------------------------------------------
55 -----------------------------------------------*/
56 SequenceAsHashMap::SequenceAsHashMap(const css::uno::Any
& aSource
)
61 //-----------------------------------------------
62 SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence
< css::uno::Any
>& lSource
)
67 /*-----------------------------------------------
69 -----------------------------------------------*/
70 SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence
< css::beans::PropertyValue
>& lSource
)
75 /*-----------------------------------------------
77 -----------------------------------------------*/
78 SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence
< css::beans::NamedValue
>& lSource
)
83 /*-----------------------------------------------
85 -----------------------------------------------*/
86 SequenceAsHashMap::~SequenceAsHashMap()
90 /*-----------------------------------------------
92 -----------------------------------------------*/
93 void SequenceAsHashMap::operator<<(const css::uno::Any
& aSource
)
95 // An empty Any reset this instance!
96 if (!aSource
.hasValue())
102 css::uno::Sequence
< css::beans::NamedValue
> lN
;
109 css::uno::Sequence
< css::beans::PropertyValue
> lP
;
116 throw css::beans::IllegalTypeException(
117 ::rtl::OUString::createFromAscii("Any contains wrong type."),
118 css::uno::Reference
< css::uno::XInterface
>());
121 //-----------------------------------------------
122 void SequenceAsHashMap::operator<<(const css::uno::Sequence
< css::uno::Any
>& lSource
)
124 sal_Int32 c
= lSource
.getLength();
129 css::beans::PropertyValue lP
;
130 if (lSource
[i
] >>= lP
)
133 (!lP
.Name
.getLength()) ||
134 (!lP
.Value
.hasValue())
136 throw css::beans::IllegalTypeException(
137 ::rtl::OUString::createFromAscii("PropertyValue struct contains no usefull informations."),
138 css::uno::Reference
< css::uno::XInterface
>());
139 (*this)[lP
.Name
] = lP
.Value
;
143 css::beans::NamedValue lN
;
144 if (lSource
[i
] >>= lN
)
147 (!lN
.Name
.getLength()) ||
148 (!lN
.Value
.hasValue())
150 throw css::beans::IllegalTypeException(
151 ::rtl::OUString::createFromAscii("NamedValue struct contains no usefull informations."),
152 css::uno::Reference
< css::uno::XInterface
>());
153 (*this)[lN
.Name
] = lN
.Value
;
157 // ignore VOID Any ... but reject wrong filled ones!
158 if (lSource
[i
].hasValue())
159 throw css::beans::IllegalTypeException(
160 ::rtl::OUString::createFromAscii("Any contains wrong type."),
161 css::uno::Reference
< css::uno::XInterface
>());
165 /*-----------------------------------------------
167 -----------------------------------------------*/
168 void SequenceAsHashMap::operator<<(const css::uno::Sequence
< css::beans::PropertyValue
>& lSource
)
172 sal_Int32 c
= lSource
.getLength();
173 const css::beans::PropertyValue
* pSource
= lSource
.getConstArray();
175 for (sal_Int32 i
=0; i
<c
; ++i
)
176 (*this)[pSource
[i
].Name
] = pSource
[i
].Value
;
179 /*-----------------------------------------------
181 -----------------------------------------------*/
182 void SequenceAsHashMap::operator<<(const css::uno::Sequence
< css::beans::NamedValue
>& lSource
)
186 sal_Int32 c
= lSource
.getLength();
187 const css::beans::NamedValue
* pSource
= lSource
.getConstArray();
189 for (sal_Int32 i
=0; i
<c
; ++i
)
190 (*this)[pSource
[i
].Name
] = pSource
[i
].Value
;
193 /*-----------------------------------------------
195 -----------------------------------------------*/
196 void SequenceAsHashMap::operator>>(css::uno::Sequence
< css::beans::PropertyValue
>& lDestination
) const
198 sal_Int32 c
= (sal_Int32
)size();
199 lDestination
.realloc(c
);
200 css::beans::PropertyValue
* pDestination
= lDestination
.getArray();
203 for (const_iterator pThis
= begin();
207 pDestination
[i
].Name
= pThis
->first
;
208 pDestination
[i
].Value
= pThis
->second
;
213 /*-----------------------------------------------
215 -----------------------------------------------*/
216 void SequenceAsHashMap::operator>>(css::uno::Sequence
< css::beans::NamedValue
>& lDestination
) const
218 sal_Int32 c
= (sal_Int32
)size();
219 lDestination
.realloc(c
);
220 css::beans::NamedValue
* pDestination
= lDestination
.getArray();
223 for (const_iterator pThis
= begin();
227 pDestination
[i
].Name
= pThis
->first
;
228 pDestination
[i
].Value
= pThis
->second
;
233 /*-----------------------------------------------
235 -----------------------------------------------*/
236 const css::uno::Any
SequenceAsHashMap::getAsConstAny(::sal_Bool bAsPropertyValueList
) const
238 css::uno::Any aDestination
;
239 if (bAsPropertyValueList
)
240 aDestination
= css::uno::makeAny(getAsConstPropertyValueList());
242 aDestination
= css::uno::makeAny(getAsConstNamedValueList());
246 /*-----------------------------------------------
248 -----------------------------------------------*/
249 const css::uno::Sequence
< css::uno::Any
> SequenceAsHashMap::getAsConstAnyList(::sal_Bool bAsPropertyValueList
) const
252 ::sal_Int32 c
= (::sal_Int32
)size();
253 css::uno::Sequence
< css::uno::Any
> lDestination(c
);
254 css::uno::Any
* pDestination
= lDestination
.getArray();
256 for (const_iterator pThis
= begin();
260 if (bAsPropertyValueList
)
262 css::beans::PropertyValue aProp
;
263 aProp
.Name
= pThis
->first
;
264 aProp
.Value
= pThis
->second
;
265 pDestination
[i
] = css::uno::makeAny(aProp
);
269 css::beans::NamedValue aProp
;
270 aProp
.Name
= pThis
->first
;
271 aProp
.Value
= pThis
->second
;
272 pDestination
[i
] = css::uno::makeAny(aProp
);
281 /*-----------------------------------------------
283 -----------------------------------------------*/
284 const css::uno::Sequence
< css::beans::NamedValue
> SequenceAsHashMap::getAsConstNamedValueList() const
286 css::uno::Sequence
< css::beans::NamedValue
> lReturn
;
291 /*-----------------------------------------------
293 -----------------------------------------------*/
294 const css::uno::Sequence
< css::beans::PropertyValue
> SequenceAsHashMap::getAsConstPropertyValueList() const
296 css::uno::Sequence
< css::beans::PropertyValue
> lReturn
;
301 /*-----------------------------------------------
303 -----------------------------------------------*/
304 sal_Bool
SequenceAsHashMap::match(const SequenceAsHashMap
& rCheck
) const
306 const_iterator pCheck
;
307 for ( pCheck
= rCheck
.begin();
308 pCheck
!= rCheck
.end() ;
311 const ::rtl::OUString
& sCheckName
= pCheck
->first
;
312 const css::uno::Any
& aCheckValue
= pCheck
->second
;
313 const_iterator pFound
= find(sCheckName
);
318 const css::uno::Any
& aFoundValue
= pFound
->second
;
319 if (aFoundValue
!= aCheckValue
)
326 /*-----------------------------------------------
328 -----------------------------------------------*/
329 void SequenceAsHashMap::update(const SequenceAsHashMap
& rUpdate
)
331 const_iterator pUpdate
;
332 for ( pUpdate
= rUpdate
.begin();
333 pUpdate
!= rUpdate
.end() ;
336 const ::rtl::OUString
& sName
= pUpdate
->first
;
337 const css::uno::Any
& aValue
= pUpdate
->second
;
339 (*this)[sName
] = aValue
;
343 /*-----------------------------------------------
345 -----------------------------------------------*/
346 #if OSL_DEBUG_LEVEL > 1
347 void SequenceAsHashMap::dbg_dumpToFile(const char* pFileName
,
348 const char* pComment
) const
350 if (!pFileName
|| !pComment
)
353 FILE* pFile
= fopen(pFileName
, "a");
357 ::rtl::OUStringBuffer
sBuffer(1000);
358 sBuffer
.appendAscii("\n----------------------------------------\n");
359 sBuffer
.appendAscii(pComment
);
360 sBuffer
.appendAscii("\n----------------------------------------\n");
362 for (const_iterator pIt
= begin();
366 sBuffer
.appendAscii("[" );
367 sBuffer
.append (i
++ );
368 sBuffer
.appendAscii("] " );
369 sBuffer
.appendAscii("\"" );
370 sBuffer
.append (pIt
->first
);
371 sBuffer
.appendAscii("\" = \"" );
373 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> xv
;
378 if (pIt
->second
>>= sv
)
381 if (pIt
->second
>>= nv
)
384 if (pIt
->second
>>= bv
)
385 sBuffer
.appendAscii(bv
? "true" : "false");
387 if (pIt
->second
>>= xv
)
388 sBuffer
.appendAscii(xv
.is() ? "object" : "null");
390 sBuffer
.appendAscii("???");
392 sBuffer
.appendAscii("\"\n");
395 fprintf(pFile
, ::rtl::OUStringToOString(sBuffer
.makeStringAndClear(), RTL_TEXTENCODING_UTF8
).getStr());
398 #endif // OSL_DEBUG_LEVEL > 1
400 } // namespace comphelper