1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <comphelper/sequenceashashmap.hxx>
25 SequenceAsHashMap::SequenceAsHashMap()
26 : SequenceAsHashMapBase()
30 SequenceAsHashMap::SequenceAsHashMap(const css::uno::Any
& aSource
)
36 SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence
< css::uno::Any
>& lSource
)
41 SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence
< css::beans::PropertyValue
>& lSource
)
46 SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence
< css::beans::NamedValue
>& lSource
)
51 SequenceAsHashMap::~SequenceAsHashMap()
55 void SequenceAsHashMap::operator<<(const css::uno::Any
& aSource
)
57 // An empty Any reset this instance!
58 if (!aSource
.hasValue())
64 css::uno::Sequence
< css::beans::NamedValue
> lN
;
71 css::uno::Sequence
< css::beans::PropertyValue
> lP
;
78 throw css::beans::IllegalTypeException(
79 OUString( "Any contains wrong type." ),
80 css::uno::Reference
< css::uno::XInterface
>());
84 void SequenceAsHashMap::operator<<(const css::uno::Sequence
< css::uno::Any
>& lSource
)
86 sal_Int32 c
= lSource
.getLength();
91 css::beans::PropertyValue lP
;
92 if (lSource
[i
] >>= lP
)
95 (lP
.Name
.isEmpty()) ||
96 (!lP
.Value
.hasValue())
98 throw css::beans::IllegalTypeException(
99 OUString( "PropertyValue struct contains no useful information." ),
100 css::uno::Reference
< css::uno::XInterface
>());
101 (*this)[lP
.Name
] = lP
.Value
;
105 css::beans::NamedValue lN
;
106 if (lSource
[i
] >>= lN
)
109 (lN
.Name
.isEmpty()) ||
110 (!lN
.Value
.hasValue())
112 throw css::beans::IllegalTypeException(
113 OUString( "NamedValue struct contains no useful information." ),
114 css::uno::Reference
< css::uno::XInterface
>());
115 (*this)[lN
.Name
] = lN
.Value
;
119 // ignore VOID Any ... but reject wrong filled ones!
120 if (lSource
[i
].hasValue())
121 throw css::beans::IllegalTypeException(
122 OUString( "Any contains wrong type." ),
123 css::uno::Reference
< css::uno::XInterface
>());
127 void SequenceAsHashMap::operator<<(const css::uno::Sequence
< css::beans::PropertyValue
>& lSource
)
131 sal_Int32 c
= lSource
.getLength();
132 const css::beans::PropertyValue
* pSource
= lSource
.getConstArray();
134 for (sal_Int32 i
=0; i
<c
; ++i
)
135 (*this)[pSource
[i
].Name
] = pSource
[i
].Value
;
138 void SequenceAsHashMap::operator<<(const css::uno::Sequence
< css::beans::NamedValue
>& lSource
)
142 sal_Int32 c
= lSource
.getLength();
143 const css::beans::NamedValue
* pSource
= lSource
.getConstArray();
145 for (sal_Int32 i
=0; i
<c
; ++i
)
146 (*this)[pSource
[i
].Name
] = pSource
[i
].Value
;
149 void SequenceAsHashMap::operator>>(css::uno::Sequence
< css::beans::PropertyValue
>& lDestination
) const
151 sal_Int32 c
= (sal_Int32
)size();
152 lDestination
.realloc(c
);
153 css::beans::PropertyValue
* pDestination
= lDestination
.getArray();
156 for (const_iterator pThis
= begin();
160 pDestination
[i
].Name
= pThis
->first
;
161 pDestination
[i
].Value
= pThis
->second
;
166 void SequenceAsHashMap::operator>>(css::uno::Sequence
< css::beans::NamedValue
>& lDestination
) const
168 sal_Int32 c
= (sal_Int32
)size();
169 lDestination
.realloc(c
);
170 css::beans::NamedValue
* pDestination
= lDestination
.getArray();
173 for (const_iterator pThis
= begin();
177 pDestination
[i
].Name
= pThis
->first
;
178 pDestination
[i
].Value
= pThis
->second
;
183 const css::uno::Any
SequenceAsHashMap::getAsConstAny(bool bAsPropertyValueList
) const
185 css::uno::Any aDestination
;
186 if (bAsPropertyValueList
)
187 aDestination
= css::uno::makeAny(getAsConstPropertyValueList());
189 aDestination
= css::uno::makeAny(getAsConstNamedValueList());
193 const css::uno::Sequence
< css::beans::NamedValue
> SequenceAsHashMap::getAsConstNamedValueList() const
195 css::uno::Sequence
< css::beans::NamedValue
> lReturn
;
200 const css::uno::Sequence
< css::beans::PropertyValue
> SequenceAsHashMap::getAsConstPropertyValueList() const
202 css::uno::Sequence
< css::beans::PropertyValue
> lReturn
;
207 bool SequenceAsHashMap::match(const SequenceAsHashMap
& rCheck
) const
209 const_iterator pCheck
;
210 for ( pCheck
= rCheck
.begin();
211 pCheck
!= rCheck
.end() ;
214 const OUString
& sCheckName
= pCheck
->first
;
215 const css::uno::Any
& aCheckValue
= pCheck
->second
;
216 const_iterator pFound
= find(sCheckName
);
221 const css::uno::Any
& aFoundValue
= pFound
->second
;
222 if (aFoundValue
!= aCheckValue
)
229 void SequenceAsHashMap::update(const SequenceAsHashMap
& rUpdate
)
231 const_iterator pUpdate
;
232 for ( pUpdate
= rUpdate
.begin();
233 pUpdate
!= rUpdate
.end() ;
236 const OUString
& sName
= pUpdate
->first
;
237 const css::uno::Any
& aValue
= pUpdate
->second
;
239 (*this)[sName
] = aValue
;
243 } // namespace comphelper
245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */