Bump version to 4.3-4
[LibreOffice.git] / comphelper / source / misc / sequenceashashmap.cxx
blob1023dbea14905ce51e8e9fe831999a9520be8c20
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 <comphelper/sequenceashashmap.hxx>
23 namespace comphelper{
25 SequenceAsHashMap::SequenceAsHashMap()
26 : SequenceAsHashMapBase()
30 SequenceAsHashMap::SequenceAsHashMap(const css::uno::Any& aSource)
32 (*this) << aSource;
36 SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence< css::uno::Any >& lSource)
38 (*this) << lSource;
41 SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence< css::beans::PropertyValue >& lSource)
43 (*this) << lSource;
46 SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence< css::beans::NamedValue >& lSource)
48 (*this) << lSource;
51 SequenceAsHashMap::~SequenceAsHashMap()
55 void SequenceAsHashMap::operator<<(const css::uno::Any& aSource)
57 // An empty Any reset this instance!
58 if (!aSource.hasValue())
60 clear();
61 return;
64 css::uno::Sequence< css::beans::NamedValue > lN;
65 if (aSource >>= lN)
67 (*this) << lN;
68 return;
71 css::uno::Sequence< css::beans::PropertyValue > lP;
72 if (aSource >>= lP)
74 (*this) << lP;
75 return;
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();
87 sal_Int32 i = 0;
89 for (i=0; i<c; ++i)
91 css::beans::PropertyValue lP;
92 if (lSource[i] >>= lP)
94 if (
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;
102 continue;
105 css::beans::NamedValue lN;
106 if (lSource[i] >>= lN)
108 if (
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;
116 continue;
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)
129 clear();
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)
140 clear();
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();
155 sal_Int32 i = 0;
156 for (const_iterator pThis = begin();
157 pThis != end() ;
158 ++pThis )
160 pDestination[i].Name = pThis->first ;
161 pDestination[i].Value = pThis->second;
162 ++i;
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();
172 sal_Int32 i = 0;
173 for (const_iterator pThis = begin();
174 pThis != end() ;
175 ++pThis )
177 pDestination[i].Name = pThis->first ;
178 pDestination[i].Value = pThis->second;
179 ++i;
183 const css::uno::Any SequenceAsHashMap::getAsConstAny(bool bAsPropertyValueList) const
185 css::uno::Any aDestination;
186 if (bAsPropertyValueList)
187 aDestination = css::uno::makeAny(getAsConstPropertyValueList());
188 else
189 aDestination = css::uno::makeAny(getAsConstNamedValueList());
190 return aDestination;
193 const css::uno::Sequence< css::beans::NamedValue > SequenceAsHashMap::getAsConstNamedValueList() const
195 css::uno::Sequence< css::beans::NamedValue > lReturn;
196 (*this) >> lReturn;
197 return lReturn;
200 const css::uno::Sequence< css::beans::PropertyValue > SequenceAsHashMap::getAsConstPropertyValueList() const
202 css::uno::Sequence< css::beans::PropertyValue > lReturn;
203 (*this) >> lReturn;
204 return lReturn;
207 bool SequenceAsHashMap::match(const SequenceAsHashMap& rCheck) const
209 const_iterator pCheck;
210 for ( pCheck = rCheck.begin();
211 pCheck != rCheck.end() ;
212 ++pCheck )
214 const OUString& sCheckName = pCheck->first;
215 const css::uno::Any& aCheckValue = pCheck->second;
216 const_iterator pFound = find(sCheckName);
218 if (pFound == end())
219 return false;
221 const css::uno::Any& aFoundValue = pFound->second;
222 if (aFoundValue != aCheckValue)
223 return false;
226 return true;
229 void SequenceAsHashMap::update(const SequenceAsHashMap& rUpdate)
231 const_iterator pUpdate;
232 for ( pUpdate = rUpdate.begin();
233 pUpdate != rUpdate.end() ;
234 ++pUpdate )
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: */