2010-10-14 08:27:31 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-29 14:02:24 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2004-01-28 11:47:53 +00:00
|
|
|
|
|
|
|
#include <comphelper/sequenceashashmap.hxx>
|
|
|
|
|
|
|
|
|
|
|
|
namespace comphelper{
|
|
|
|
|
|
|
|
SequenceAsHashMap::SequenceAsHashMap()
|
|
|
|
: SequenceAsHashMapBase()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SequenceAsHashMap::SequenceAsHashMap(const css::uno::Any& aSource)
|
|
|
|
{
|
|
|
|
(*this) << aSource;
|
|
|
|
}
|
|
|
|
|
2004-09-20 09:17:34 +00:00
|
|
|
//-----------------------------------------------
|
|
|
|
SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence< css::uno::Any >& lSource)
|
|
|
|
{
|
|
|
|
(*this) << lSource;
|
|
|
|
}
|
|
|
|
|
2004-01-28 11:47:53 +00:00
|
|
|
SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence< css::beans::PropertyValue >& lSource)
|
|
|
|
{
|
|
|
|
(*this) << lSource;
|
|
|
|
}
|
|
|
|
|
|
|
|
SequenceAsHashMap::SequenceAsHashMap(const css::uno::Sequence< css::beans::NamedValue >& lSource)
|
|
|
|
{
|
|
|
|
(*this) << lSource;
|
|
|
|
}
|
|
|
|
|
|
|
|
SequenceAsHashMap::~SequenceAsHashMap()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SequenceAsHashMap::operator<<(const css::uno::Any& aSource)
|
|
|
|
{
|
|
|
|
// An empty Any reset this instance!
|
|
|
|
if (!aSource.hasValue())
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
css::uno::Sequence< css::beans::NamedValue > lN;
|
|
|
|
if (aSource >>= lN)
|
|
|
|
{
|
|
|
|
(*this) << lN;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
css::uno::Sequence< css::beans::PropertyValue > lP;
|
|
|
|
if (aSource >>= lP)
|
|
|
|
{
|
|
|
|
(*this) << lP;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw css::beans::IllegalTypeException(
|
2013-01-29 21:41:06 +01:00
|
|
|
OUString( "Any contains wrong type." ),
|
2004-01-28 11:47:53 +00:00
|
|
|
css::uno::Reference< css::uno::XInterface >());
|
|
|
|
}
|
|
|
|
|
2004-09-20 09:17:34 +00:00
|
|
|
//-----------------------------------------------
|
|
|
|
void SequenceAsHashMap::operator<<(const css::uno::Sequence< css::uno::Any >& lSource)
|
|
|
|
{
|
|
|
|
sal_Int32 c = lSource.getLength();
|
|
|
|
sal_Int32 i = 0;
|
|
|
|
|
|
|
|
for (i=0; i<c; ++i)
|
|
|
|
{
|
|
|
|
css::beans::PropertyValue lP;
|
|
|
|
if (lSource[i] >>= lP)
|
|
|
|
{
|
|
|
|
if (
|
2011-12-12 23:01:55 -02:00
|
|
|
(lP.Name.isEmpty()) ||
|
2004-09-20 09:17:34 +00:00
|
|
|
(!lP.Value.hasValue())
|
|
|
|
)
|
|
|
|
throw css::beans::IllegalTypeException(
|
2013-02-28 18:11:24 -04:00
|
|
|
OUString( "PropertyValue struct contains no useful information." ),
|
2004-09-20 09:17:34 +00:00
|
|
|
css::uno::Reference< css::uno::XInterface >());
|
|
|
|
(*this)[lP.Name] = lP.Value;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
css::beans::NamedValue lN;
|
|
|
|
if (lSource[i] >>= lN)
|
|
|
|
{
|
|
|
|
if (
|
2011-12-12 23:01:55 -02:00
|
|
|
(lN.Name.isEmpty()) ||
|
2004-09-20 09:17:34 +00:00
|
|
|
(!lN.Value.hasValue())
|
|
|
|
)
|
|
|
|
throw css::beans::IllegalTypeException(
|
2013-02-28 18:11:24 -04:00
|
|
|
OUString( "NamedValue struct contains no useful information." ),
|
2004-09-20 09:17:34 +00:00
|
|
|
css::uno::Reference< css::uno::XInterface >());
|
|
|
|
(*this)[lN.Name] = lN.Value;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ignore VOID Any ... but reject wrong filled ones!
|
|
|
|
if (lSource[i].hasValue())
|
|
|
|
throw css::beans::IllegalTypeException(
|
2013-01-29 21:41:06 +01:00
|
|
|
OUString( "Any contains wrong type." ),
|
2004-09-20 09:17:34 +00:00
|
|
|
css::uno::Reference< css::uno::XInterface >());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-28 11:47:53 +00:00
|
|
|
void SequenceAsHashMap::operator<<(const css::uno::Sequence< css::beans::PropertyValue >& lSource)
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
|
|
|
|
sal_Int32 c = lSource.getLength();
|
|
|
|
const css::beans::PropertyValue* pSource = lSource.getConstArray();
|
|
|
|
|
|
|
|
for (sal_Int32 i=0; i<c; ++i)
|
|
|
|
(*this)[pSource[i].Name] = pSource[i].Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SequenceAsHashMap::operator<<(const css::uno::Sequence< css::beans::NamedValue >& lSource)
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
|
|
|
|
sal_Int32 c = lSource.getLength();
|
|
|
|
const css::beans::NamedValue* pSource = lSource.getConstArray();
|
|
|
|
|
|
|
|
for (sal_Int32 i=0; i<c; ++i)
|
|
|
|
(*this)[pSource[i].Name] = pSource[i].Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SequenceAsHashMap::operator>>(css::uno::Sequence< css::beans::PropertyValue >& lDestination) const
|
|
|
|
{
|
|
|
|
sal_Int32 c = (sal_Int32)size();
|
|
|
|
lDestination.realloc(c);
|
|
|
|
css::beans::PropertyValue* pDestination = lDestination.getArray();
|
|
|
|
|
|
|
|
sal_Int32 i = 0;
|
|
|
|
for (const_iterator pThis = begin();
|
|
|
|
pThis != end() ;
|
|
|
|
++pThis )
|
|
|
|
{
|
|
|
|
pDestination[i].Name = pThis->first ;
|
|
|
|
pDestination[i].Value = pThis->second;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SequenceAsHashMap::operator>>(css::uno::Sequence< css::beans::NamedValue >& lDestination) const
|
|
|
|
{
|
|
|
|
sal_Int32 c = (sal_Int32)size();
|
|
|
|
lDestination.realloc(c);
|
|
|
|
css::beans::NamedValue* pDestination = lDestination.getArray();
|
|
|
|
|
|
|
|
sal_Int32 i = 0;
|
|
|
|
for (const_iterator pThis = begin();
|
|
|
|
pThis != end() ;
|
|
|
|
++pThis )
|
|
|
|
{
|
|
|
|
pDestination[i].Name = pThis->first ;
|
|
|
|
pDestination[i].Value = pThis->second;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-19 15:32:40 +00:00
|
|
|
const css::uno::Any SequenceAsHashMap::getAsConstAny(::sal_Bool bAsPropertyValueList) const
|
|
|
|
{
|
|
|
|
css::uno::Any aDestination;
|
|
|
|
if (bAsPropertyValueList)
|
|
|
|
aDestination = css::uno::makeAny(getAsConstPropertyValueList());
|
|
|
|
else
|
|
|
|
aDestination = css::uno::makeAny(getAsConstNamedValueList());
|
|
|
|
return aDestination;
|
|
|
|
}
|
|
|
|
|
2004-01-28 11:47:53 +00:00
|
|
|
const css::uno::Sequence< css::beans::NamedValue > SequenceAsHashMap::getAsConstNamedValueList() const
|
|
|
|
{
|
|
|
|
css::uno::Sequence< css::beans::NamedValue > lReturn;
|
|
|
|
(*this) >> lReturn;
|
|
|
|
return lReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
const css::uno::Sequence< css::beans::PropertyValue > SequenceAsHashMap::getAsConstPropertyValueList() const
|
|
|
|
{
|
|
|
|
css::uno::Sequence< css::beans::PropertyValue > lReturn;
|
|
|
|
(*this) >> lReturn;
|
|
|
|
return lReturn;
|
|
|
|
}
|
|
|
|
|
2007-04-16 15:58:57 +00:00
|
|
|
sal_Bool SequenceAsHashMap::match(const SequenceAsHashMap& rCheck) const
|
|
|
|
{
|
|
|
|
const_iterator pCheck;
|
|
|
|
for ( pCheck = rCheck.begin();
|
|
|
|
pCheck != rCheck.end() ;
|
|
|
|
++pCheck )
|
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString& sCheckName = pCheck->first;
|
2007-04-16 15:58:57 +00:00
|
|
|
const css::uno::Any& aCheckValue = pCheck->second;
|
|
|
|
const_iterator pFound = find(sCheckName);
|
|
|
|
|
|
|
|
if (pFound == end())
|
|
|
|
return sal_False;
|
|
|
|
|
|
|
|
const css::uno::Any& aFoundValue = pFound->second;
|
|
|
|
if (aFoundValue != aCheckValue)
|
|
|
|
return sal_False;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sal_True;
|
|
|
|
}
|
|
|
|
|
2007-11-19 15:32:40 +00:00
|
|
|
void SequenceAsHashMap::update(const SequenceAsHashMap& rUpdate)
|
|
|
|
{
|
|
|
|
const_iterator pUpdate;
|
|
|
|
for ( pUpdate = rUpdate.begin();
|
|
|
|
pUpdate != rUpdate.end() ;
|
|
|
|
++pUpdate )
|
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString& sName = pUpdate->first;
|
2007-11-19 15:32:40 +00:00
|
|
|
const css::uno::Any& aValue = pUpdate->second;
|
|
|
|
|
|
|
|
(*this)[sName] = aValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-28 11:47:53 +00:00
|
|
|
} // namespace comphelper
|
2010-10-14 08:27:31 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|