bump product version to 5.0.4.1
[LibreOffice.git] / comphelper / source / misc / sequenceashashmap.cxx
blob46df283f32781f7d8078d5498ed3b69e051552be
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
26 namespace comphelper{
28 SequenceAsHashMap::SequenceAsHashMap()
29 : SequenceAsHashMapBase()
33 SequenceAsHashMap::SequenceAsHashMap(const css::uno::Any& aSource)
35 (*this) << aSource;
39 SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence< css::uno::Any >& lSource)
41 (*this) << lSource;
44 SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence< css::beans::PropertyValue >& lSource)
46 (*this) << lSource;
49 SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence< css::beans::NamedValue >& lSource)
51 (*this) << lSource;
54 SequenceAsHashMap::~SequenceAsHashMap()
58 void SequenceAsHashMap::operator<<(const css::uno::Any& aSource)
60 // An empty Any reset this instance!
61 if (!aSource.hasValue())
63 clear();
64 return;
67 css::uno::Sequence< css::beans::NamedValue > lN;
68 if (aSource >>= lN)
70 (*this) << lN;
71 return;
74 css::uno::Sequence< css::beans::PropertyValue > lP;
75 if (aSource >>= lP)
77 (*this) << lP;
78 return;
81 throw css::lang::IllegalArgumentException(
82 "Any contains wrong type.", css::uno::Reference<css::uno::XInterface>(),
83 -1);
87 void SequenceAsHashMap::operator<<(const css::uno::Sequence< css::uno::Any >& lSource)
89 sal_Int32 c = lSource.getLength();
90 sal_Int32 i = 0;
92 for (i=0; i<c; ++i)
94 css::beans::PropertyValue lP;
95 if (lSource[i] >>= lP)
97 if (
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;
105 continue;
108 css::beans::NamedValue lN;
109 if (lSource[i] >>= lN)
111 if (
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;
119 continue;
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)
132 clear();
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)
143 clear();
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();
158 sal_Int32 i = 0;
159 for (const_iterator pThis = begin();
160 pThis != end() ;
161 ++pThis )
163 pDestination[i].Name = pThis->first ;
164 pDestination[i].Value = pThis->second;
165 ++i;
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();
175 sal_Int32 i = 0;
176 for (const_iterator pThis = begin();
177 pThis != end() ;
178 ++pThis )
180 pDestination[i].Name = pThis->first ;
181 pDestination[i].Value = pThis->second;
182 ++i;
186 const css::uno::Any SequenceAsHashMap::getAsConstAny(bool bAsPropertyValueList) const
188 css::uno::Any aDestination;
189 if (bAsPropertyValueList)
190 aDestination = css::uno::makeAny(getAsConstPropertyValueList());
191 else
192 aDestination = css::uno::makeAny(getAsConstNamedValueList());
193 return aDestination;
196 const css::uno::Sequence< css::beans::NamedValue > SequenceAsHashMap::getAsConstNamedValueList() const
198 css::uno::Sequence< css::beans::NamedValue > lReturn;
199 (*this) >> lReturn;
200 return lReturn;
203 const css::uno::Sequence< css::beans::PropertyValue > SequenceAsHashMap::getAsConstPropertyValueList() const
205 css::uno::Sequence< css::beans::PropertyValue > lReturn;
206 (*this) >> lReturn;
207 return lReturn;
210 bool SequenceAsHashMap::match(const SequenceAsHashMap& rCheck) const
212 const_iterator pCheck;
213 for ( pCheck = rCheck.begin();
214 pCheck != rCheck.end() ;
215 ++pCheck )
217 const OUString& sCheckName = pCheck->first;
218 const css::uno::Any& aCheckValue = pCheck->second;
219 const_iterator pFound = find(sCheckName);
221 if (pFound == end())
222 return false;
224 const css::uno::Any& aFoundValue = pFound->second;
225 if (aFoundValue != aCheckValue)
226 return false;
229 return true;
232 void SequenceAsHashMap::update(const SequenceAsHashMap& rUpdate)
234 const_iterator pUpdate;
235 for ( pUpdate = rUpdate.begin();
236 pUpdate != rUpdate.end() ;
237 ++pUpdate )
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: */