1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sequenceashashmap.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_comphelper.hxx"
34 //_______________________________________________
36 #include <comphelper/sequenceashashmap.hxx>
38 //_______________________________________________
43 namespace css
= ::com::sun::star
;
45 //_______________________________________________
48 /*-----------------------------------------------
50 -----------------------------------------------*/
51 SequenceAsHashMap::SequenceAsHashMap()
52 : SequenceAsHashMapBase()
56 /*-----------------------------------------------
58 -----------------------------------------------*/
59 SequenceAsHashMap::SequenceAsHashMap(const css::uno::Any
& aSource
)
64 //-----------------------------------------------
65 SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence
< css::uno::Any
>& lSource
)
70 /*-----------------------------------------------
72 -----------------------------------------------*/
73 SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence
< css::beans::PropertyValue
>& lSource
)
78 /*-----------------------------------------------
80 -----------------------------------------------*/
81 SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence
< css::beans::NamedValue
>& lSource
)
86 /*-----------------------------------------------
88 -----------------------------------------------*/
89 SequenceAsHashMap::~SequenceAsHashMap()
93 /*-----------------------------------------------
95 -----------------------------------------------*/
96 void SequenceAsHashMap::operator<<(const css::uno::Any
& aSource
)
98 // An empty Any reset this instance!
99 if (!aSource
.hasValue())
105 css::uno::Sequence
< css::beans::NamedValue
> lN
;
112 css::uno::Sequence
< css::beans::PropertyValue
> lP
;
119 throw css::beans::IllegalTypeException(
120 ::rtl::OUString::createFromAscii("Any contains wrong type."),
121 css::uno::Reference
< css::uno::XInterface
>());
124 //-----------------------------------------------
125 void SequenceAsHashMap::operator<<(const css::uno::Sequence
< css::uno::Any
>& lSource
)
127 sal_Int32 c
= lSource
.getLength();
132 css::beans::PropertyValue lP
;
133 if (lSource
[i
] >>= lP
)
136 (!lP
.Name
.getLength()) ||
137 (!lP
.Value
.hasValue())
139 throw css::beans::IllegalTypeException(
140 ::rtl::OUString::createFromAscii("PropertyValue struct contains no usefull informations."),
141 css::uno::Reference
< css::uno::XInterface
>());
142 (*this)[lP
.Name
] = lP
.Value
;
146 css::beans::NamedValue lN
;
147 if (lSource
[i
] >>= lN
)
150 (!lN
.Name
.getLength()) ||
151 (!lN
.Value
.hasValue())
153 throw css::beans::IllegalTypeException(
154 ::rtl::OUString::createFromAscii("NamedValue struct contains no usefull informations."),
155 css::uno::Reference
< css::uno::XInterface
>());
156 (*this)[lN
.Name
] = lN
.Value
;
160 // ignore VOID Any ... but reject wrong filled ones!
161 if (lSource
[i
].hasValue())
162 throw css::beans::IllegalTypeException(
163 ::rtl::OUString::createFromAscii("Any contains wrong type."),
164 css::uno::Reference
< css::uno::XInterface
>());
168 /*-----------------------------------------------
170 -----------------------------------------------*/
171 void SequenceAsHashMap::operator<<(const css::uno::Sequence
< css::beans::PropertyValue
>& lSource
)
175 sal_Int32 c
= lSource
.getLength();
176 const css::beans::PropertyValue
* pSource
= lSource
.getConstArray();
178 for (sal_Int32 i
=0; i
<c
; ++i
)
179 (*this)[pSource
[i
].Name
] = pSource
[i
].Value
;
182 /*-----------------------------------------------
184 -----------------------------------------------*/
185 void SequenceAsHashMap::operator<<(const css::uno::Sequence
< css::beans::NamedValue
>& lSource
)
189 sal_Int32 c
= lSource
.getLength();
190 const css::beans::NamedValue
* pSource
= lSource
.getConstArray();
192 for (sal_Int32 i
=0; i
<c
; ++i
)
193 (*this)[pSource
[i
].Name
] = pSource
[i
].Value
;
196 /*-----------------------------------------------
198 -----------------------------------------------*/
199 void SequenceAsHashMap::operator>>(css::uno::Sequence
< css::beans::PropertyValue
>& lDestination
) const
201 sal_Int32 c
= (sal_Int32
)size();
202 lDestination
.realloc(c
);
203 css::beans::PropertyValue
* pDestination
= lDestination
.getArray();
206 for (const_iterator pThis
= begin();
210 pDestination
[i
].Name
= pThis
->first
;
211 pDestination
[i
].Value
= pThis
->second
;
216 /*-----------------------------------------------
218 -----------------------------------------------*/
219 void SequenceAsHashMap::operator>>(css::uno::Sequence
< css::beans::NamedValue
>& lDestination
) const
221 sal_Int32 c
= (sal_Int32
)size();
222 lDestination
.realloc(c
);
223 css::beans::NamedValue
* pDestination
= lDestination
.getArray();
226 for (const_iterator pThis
= begin();
230 pDestination
[i
].Name
= pThis
->first
;
231 pDestination
[i
].Value
= pThis
->second
;
236 /*-----------------------------------------------
238 -----------------------------------------------*/
239 const css::uno::Any
SequenceAsHashMap::getAsConstAny(::sal_Bool bAsPropertyValueList
) const
241 css::uno::Any aDestination
;
242 if (bAsPropertyValueList
)
243 aDestination
= css::uno::makeAny(getAsConstPropertyValueList());
245 aDestination
= css::uno::makeAny(getAsConstNamedValueList());
249 /*-----------------------------------------------
251 -----------------------------------------------*/
252 const css::uno::Sequence
< css::uno::Any
> SequenceAsHashMap::getAsConstAnyList(::sal_Bool bAsPropertyValueList
) const
255 ::sal_Int32 c
= (::sal_Int32
)size();
256 css::uno::Sequence
< css::uno::Any
> lDestination(c
);
257 css::uno::Any
* pDestination
= lDestination
.getArray();
259 for (const_iterator pThis
= begin();
263 if (bAsPropertyValueList
)
265 css::beans::PropertyValue aProp
;
266 aProp
.Name
= pThis
->first
;
267 aProp
.Value
= pThis
->second
;
268 pDestination
[i
] = css::uno::makeAny(aProp
);
272 css::beans::NamedValue aProp
;
273 aProp
.Name
= pThis
->first
;
274 aProp
.Value
= pThis
->second
;
275 pDestination
[i
] = css::uno::makeAny(aProp
);
284 /*-----------------------------------------------
286 -----------------------------------------------*/
287 const css::uno::Sequence
< css::beans::NamedValue
> SequenceAsHashMap::getAsConstNamedValueList() const
289 css::uno::Sequence
< css::beans::NamedValue
> lReturn
;
294 /*-----------------------------------------------
296 -----------------------------------------------*/
297 const css::uno::Sequence
< css::beans::PropertyValue
> SequenceAsHashMap::getAsConstPropertyValueList() const
299 css::uno::Sequence
< css::beans::PropertyValue
> lReturn
;
304 /*-----------------------------------------------
306 -----------------------------------------------*/
307 sal_Bool
SequenceAsHashMap::match(const SequenceAsHashMap
& rCheck
) const
309 const_iterator pCheck
;
310 for ( pCheck
= rCheck
.begin();
311 pCheck
!= rCheck
.end() ;
314 const ::rtl::OUString
& sCheckName
= pCheck
->first
;
315 const css::uno::Any
& aCheckValue
= pCheck
->second
;
316 const_iterator pFound
= find(sCheckName
);
321 const css::uno::Any
& aFoundValue
= pFound
->second
;
322 if (aFoundValue
!= aCheckValue
)
329 /*-----------------------------------------------
331 -----------------------------------------------*/
332 void SequenceAsHashMap::update(const SequenceAsHashMap
& rUpdate
)
334 const_iterator pUpdate
;
335 for ( pUpdate
= rUpdate
.begin();
336 pUpdate
!= rUpdate
.end() ;
339 const ::rtl::OUString
& sName
= pUpdate
->first
;
340 const css::uno::Any
& aValue
= pUpdate
->second
;
342 (*this)[sName
] = aValue
;
346 /*-----------------------------------------------
348 -----------------------------------------------*/
349 #if OSL_DEBUG_LEVEL > 1
350 void SequenceAsHashMap::dbg_dumpToFile(const char* pFileName
,
351 const char* pComment
) const
353 if (!pFileName
|| !pComment
)
356 FILE* pFile
= fopen(pFileName
, "a");
360 ::rtl::OUStringBuffer
sBuffer(1000);
361 sBuffer
.appendAscii("\n----------------------------------------\n");
362 sBuffer
.appendAscii(pComment
);
363 sBuffer
.appendAscii("\n----------------------------------------\n");
365 for (const_iterator pIt
= begin();
369 sBuffer
.appendAscii("[" );
370 sBuffer
.append (i
++ );
371 sBuffer
.appendAscii("] " );
372 sBuffer
.appendAscii("\"" );
373 sBuffer
.append (pIt
->first
);
374 sBuffer
.appendAscii("\" = \"" );
376 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> xv
;
381 if (pIt
->second
>>= sv
)
384 if (pIt
->second
>>= nv
)
387 if (pIt
->second
>>= bv
)
388 sBuffer
.appendAscii(bv
? "true" : "false");
390 if (pIt
->second
>>= xv
)
391 sBuffer
.appendAscii(xv
.is() ? "object" : "null");
393 sBuffer
.appendAscii("???");
395 sBuffer
.appendAscii("\"\n");
398 fprintf(pFile
, ::rtl::OUStringToOString(sBuffer
.makeStringAndClear(), RTL_TEXTENCODING_UTF8
).getStr());
401 #endif // OSL_DEBUG_LEVEL > 1
403 } // namespace comphelper