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 <sal/config.h>
22 #include <com/sun/star/lang/IllegalArgumentException.hpp>
23 #include <comphelper/sequenceashashmap.hxx>
28 SequenceAsHashMap::SequenceAsHashMap()
29 : SequenceAsHashMapBase()
33 SequenceAsHashMap::SequenceAsHashMap(const css::uno::Any
& aSource
)
39 SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence
< css::uno::Any
>& lSource
)
44 SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence
< css::beans::PropertyValue
>& lSource
)
49 SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence
< css::beans::NamedValue
>& lSource
)
54 SequenceAsHashMap::~SequenceAsHashMap()
58 void SequenceAsHashMap::operator<<(const css::uno::Any
& aSource
)
60 // An empty Any reset this instance!
61 if (!aSource
.hasValue())
67 css::uno::Sequence
< css::beans::NamedValue
> lN
;
74 css::uno::Sequence
< css::beans::PropertyValue
> lP
;
81 throw css::lang::IllegalArgumentException(
82 "Any contains wrong type.", css::uno::Reference
<css::uno::XInterface
>(),
87 void SequenceAsHashMap::operator<<(const css::uno::Sequence
< css::uno::Any
>& lSource
)
89 sal_Int32 c
= lSource
.getLength();
94 css::beans::PropertyValue lP
;
95 if (lSource
[i
] >>= lP
)
98 (lP
.Name
.isEmpty()) ||
99 (!lP
.Value
.hasValue())
101 throw css::lang::IllegalArgumentException(
102 "PropertyValue struct contains no useful information.",
103 css::uno::Reference
<css::uno::XInterface
>(), -1);
104 (*this)[lP
.Name
] = lP
.Value
;
108 css::beans::NamedValue lN
;
109 if (lSource
[i
] >>= lN
)
112 (lN
.Name
.isEmpty()) ||
113 (!lN
.Value
.hasValue())
115 throw css::lang::IllegalArgumentException(
116 "NamedValue struct contains no useful information.",
117 css::uno::Reference
<css::uno::XInterface
>(), -1);
118 (*this)[lN
.Name
] = lN
.Value
;
122 // ignore VOID Any ... but reject wrong filled ones!
123 if (lSource
[i
].hasValue())
124 throw css::lang::IllegalArgumentException(
125 "Any contains wrong type.",
126 css::uno::Reference
<css::uno::XInterface
>(), -1);
130 void SequenceAsHashMap::operator<<(const css::uno::Sequence
< css::beans::PropertyValue
>& lSource
)
134 sal_Int32 c
= lSource
.getLength();
135 const css::beans::PropertyValue
* pSource
= lSource
.getConstArray();
137 for (sal_Int32 i
=0; i
<c
; ++i
)
138 (*this)[pSource
[i
].Name
] = pSource
[i
].Value
;
141 void SequenceAsHashMap::operator<<(const css::uno::Sequence
< css::beans::NamedValue
>& lSource
)
145 sal_Int32 c
= lSource
.getLength();
146 const css::beans::NamedValue
* pSource
= lSource
.getConstArray();
148 for (sal_Int32 i
=0; i
<c
; ++i
)
149 (*this)[pSource
[i
].Name
] = pSource
[i
].Value
;
152 void SequenceAsHashMap::operator>>(css::uno::Sequence
< css::beans::PropertyValue
>& lDestination
) const
154 sal_Int32 c
= (sal_Int32
)size();
155 lDestination
.realloc(c
);
156 css::beans::PropertyValue
* pDestination
= lDestination
.getArray();
159 for (const_iterator pThis
= begin();
163 pDestination
[i
].Name
= pThis
->first
;
164 pDestination
[i
].Value
= pThis
->second
;
169 void SequenceAsHashMap::operator>>(css::uno::Sequence
< css::beans::NamedValue
>& lDestination
) const
171 sal_Int32 c
= (sal_Int32
)size();
172 lDestination
.realloc(c
);
173 css::beans::NamedValue
* pDestination
= lDestination
.getArray();
176 for (const_iterator pThis
= begin();
180 pDestination
[i
].Name
= pThis
->first
;
181 pDestination
[i
].Value
= pThis
->second
;
186 const css::uno::Any
SequenceAsHashMap::getAsConstAny(bool bAsPropertyValueList
) const
188 css::uno::Any aDestination
;
189 if (bAsPropertyValueList
)
190 aDestination
= css::uno::makeAny(getAsConstPropertyValueList());
192 aDestination
= css::uno::makeAny(getAsConstNamedValueList());
196 const css::uno::Sequence
< css::beans::NamedValue
> SequenceAsHashMap::getAsConstNamedValueList() const
198 css::uno::Sequence
< css::beans::NamedValue
> lReturn
;
203 const css::uno::Sequence
< css::beans::PropertyValue
> SequenceAsHashMap::getAsConstPropertyValueList() const
205 css::uno::Sequence
< css::beans::PropertyValue
> lReturn
;
210 bool SequenceAsHashMap::match(const SequenceAsHashMap
& rCheck
) const
212 const_iterator pCheck
;
213 for ( pCheck
= rCheck
.begin();
214 pCheck
!= rCheck
.end() ;
217 const OUString
& sCheckName
= pCheck
->first
;
218 const css::uno::Any
& aCheckValue
= pCheck
->second
;
219 const_iterator pFound
= find(sCheckName
);
224 const css::uno::Any
& aFoundValue
= pFound
->second
;
225 if (aFoundValue
!= aCheckValue
)
232 void SequenceAsHashMap::update(const SequenceAsHashMap
& rUpdate
)
234 const_iterator pUpdate
;
235 for ( pUpdate
= rUpdate
.begin();
236 pUpdate
!= rUpdate
.end() ;
239 const OUString
& sName
= pUpdate
->first
;
240 const css::uno::Any
& aValue
= pUpdate
->second
;
242 (*this)[sName
] = aValue
;
246 } // namespace comphelper
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */