diff --git a/comphelper/inc/comphelper/namedvaluecollection.hxx b/comphelper/inc/comphelper/namedvaluecollection.hxx index 72cd0e7cdfbe..e13059361b0a 100644 --- a/comphelper/inc/comphelper/namedvaluecollection.hxx +++ b/comphelper/inc/comphelper/namedvaluecollection.hxx @@ -39,6 +39,7 @@ #include #include +#include //........................................................................ namespace comphelper @@ -91,6 +92,11 @@ namespace comphelper ~NamedValueCollection(); + inline void assign( const ::com::sun::star::uno::Any& i_rWrappedElements ) + { + impl_assign( i_rWrappedElements ); + } + inline void assign( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& _rArguments ) { impl_assign( _rArguments ); @@ -117,6 +123,11 @@ namespace comphelper /// determines whether the collection is empty bool empty() const; + /** returns the names of all elements in the collection + */ + ::std::vector< ::rtl::OUString > + getNames() const; + /** merges the content of another collection into |this| @param _rAdditionalValues the collection whose values are to be merged @@ -312,6 +323,7 @@ namespace comphelper } private: + void impl_assign( const ::com::sun::star::uno::Any& i_rWrappedElements ); void impl_assign( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& _rArguments ); void impl_assign( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rArguments ); void impl_assign( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& _rArguments ); diff --git a/comphelper/source/misc/namedvaluecollection.cxx b/comphelper/source/misc/namedvaluecollection.cxx index 8bab7fa3d7c7..566e5526019c 100644 --- a/comphelper/source/misc/namedvaluecollection.cxx +++ b/comphelper/source/misc/namedvaluecollection.cxx @@ -99,21 +99,7 @@ namespace comphelper NamedValueCollection::NamedValueCollection( const Any& _rElements ) :m_pImpl( new NamedValueCollection_Impl ) { - Sequence< NamedValue > aNamedValues; - Sequence< PropertyValue > aPropertyValues; - NamedValue aNamedValue; - PropertyValue aPropertyValue; - - if ( _rElements >>= aNamedValues ) - impl_assign( aNamedValues ); - else if ( _rElements >>= aPropertyValues ) - impl_assign( aPropertyValues ); - else if ( _rElements >>= aNamedValue ) - impl_assign( Sequence< NamedValue >( &aNamedValue, 1 ) ); - else if ( _rElements >>= aPropertyValue ) - impl_assign( Sequence< PropertyValue >( &aPropertyValue, 1 ) ); - else - OSL_ENSURE( !_rElements.hasValue(), "NamedValueCollection::NamedValueCollection(Any): unsupported type!" ); + impl_assign( _rElements ); } //-------------------------------------------------------------------- @@ -169,6 +155,39 @@ namespace comphelper return m_pImpl->aValues.empty(); } + //-------------------------------------------------------------------- + ::std::vector< ::rtl::OUString > NamedValueCollection::getNames() const + { + ::std::vector< ::rtl::OUString > aNames( m_pImpl->aValues.size() ); + ::std::transform( + m_pImpl->aValues.begin(), + m_pImpl->aValues.end(), + aNames.begin(), + ::std::select1st< NamedValueRepository::value_type >() + ); + return aNames; + } + + //-------------------------------------------------------------------- + void NamedValueCollection::impl_assign( const Any& i_rWrappedElements ) + { + Sequence< NamedValue > aNamedValues; + Sequence< PropertyValue > aPropertyValues; + NamedValue aNamedValue; + PropertyValue aPropertyValue; + + if ( i_rWrappedElements >>= aNamedValues ) + impl_assign( aNamedValues ); + else if ( i_rWrappedElements >>= aPropertyValues ) + impl_assign( aPropertyValues ); + else if ( i_rWrappedElements >>= aNamedValue ) + impl_assign( Sequence< NamedValue >( &aNamedValue, 1 ) ); + else if ( i_rWrappedElements >>= aPropertyValue ) + impl_assign( Sequence< PropertyValue >( &aPropertyValue, 1 ) ); + else + OSL_ENSURE( !i_rWrappedElements.hasValue(), "NamedValueCollection::impl_assign(Any): unsupported type!" ); + } + //-------------------------------------------------------------------- void NamedValueCollection::impl_assign( const Sequence< Any >& _rArguments ) {