22 #include <com/sun/star/beans/NamedValue.hpp>
23 #include <com/sun/star/lang/IllegalArgumentException.hpp>
24 #include <com/sun/star/beans/PropertyState.hpp>
25 #include <com/sun/star/beans/PropertyValue.hpp>
27 #include <rtl/instance.hxx>
31 #include <unordered_map>
37 using ::com::sun::star::uno::Any;
38 using ::com::sun::star::uno::Sequence;
39 using ::com::sun::star::beans::PropertyValue;
40 using ::com::sun::star::beans::NamedValue;
41 using ::com::sun::star::uno::Type;
42 using ::com::sun::star::uno::cpp_acquire;
43 using ::com::sun::star::uno::cpp_release;
44 using ::com::sun::star::uno::cpp_queryInterface;
45 using ::com::sun::star::lang::IllegalArgumentException;
46 using ::com::sun::star::beans::PropertyState_DIRECT_VALUE;
74 Type const & aValueType = i_value.getValueType();
77 || aValueType.equals( ::
cppu::UnoType< Sequence< PropertyValue > >::
get() )
78 || aValueType.equals( ::
cppu::UnoType< Sequence< NamedValue > >::
get() );
108 std::vector< OUString > aNames;
111 aNames.push_back(
value.first );
119 Sequence< NamedValue > aNamedValues;
121 NamedValue aNamedValue;
122 PropertyValue aPropertyValue;
124 if ( i_rWrappedElements >>= aNamedValues )
126 else if ( i_rWrappedElements >>= aPropertyValues )
128 else if ( i_rWrappedElements >>= aNamedValue )
129 impl_assign( Sequence< NamedValue >( &aNamedValue, 1 ) );
130 else if ( i_rWrappedElements >>= aPropertyValue )
131 impl_assign( Sequence< PropertyValue >( &aPropertyValue, 1 ) );
133 SAL_WARN_IF( i_rWrappedElements.hasValue(),
"comphelper",
"NamedValueCollection::impl_assign(Any): unsupported type!" );
141 PropertyValue aPropertyValue;
142 NamedValue aNamedValue;
144 for (
auto const & argument : _rArguments )
146 if ( argument >>= aPropertyValue )
147 maValues[ aPropertyValue.Name ] = aPropertyValue.Value;
148 else if ( argument >>= aNamedValue )
149 maValues[ aNamedValue.Name ] = aNamedValue.Value;
154 (
"NamedValueCollection::impl_assign: encountered a value"
155 " type which I cannot handle: "
166 for (
auto const & argument : _rArguments )
175 for (
auto const & argument : _rArguments )
186 _pValueLocation, _rExpectedValueType.getTypeLibType(),
187 const_cast< void*
>(
pos->second.getValue() ),
pos->second.getValueType().getTypeLibType(),
188 reinterpret_cast< uno_QueryInterfaceFunc
>( cpp_queryInterface ),
189 reinterpret_cast< uno_AcquireFunc >( cpp_acquire ),
190 reinterpret_cast< uno_ReleaseFunc
>( cpp_release )
196 throw IllegalArgumentException(
197 "Invalid value type for '" + _rValueName
198 +
"'.\nExpected: " + _rExpectedValueType.getTypeName()
199 +
"\nFound: " +
pos->second.getValueType().getTypeName(),
209 class theEmptyDefault :
public rtl::Static<Any, theEmptyDefault> {};
219 return theEmptyDefault::get();
232 bool bHas =
impl_has( _rValueName );
250 _out_rValues.realloc(
maValues.size() );
252 [](
const std::pair< OUString, css::uno::Any >& _rValue)
253 {
return PropertyValue( _rValue.first, 0, _rValue.second, PropertyState_DIRECT_VALUE ); } );
254 return _out_rValues.getLength();
260 _out_rValues.realloc(
maValues.size() );
262 [](
const std::pair< OUString, css::uno::Any >& _rValue)
263 {
return NamedValue( _rValue.first, _rValue.second ); } );
264 return _out_rValues.getLength();
bool impl_put(const OUString &_rValueName, const css::uno::Any &_rValue)
::std::vector< OUString > getNames() const
returns the names of all elements in the collection
bool impl_remove(const OUString &_rValueName)
sal_Bool SAL_CALL uno_type_assignData(void *pDest, typelib_TypeDescriptionReference *pDestType, void *pSource, typelib_TypeDescriptionReference *pSourceType, uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
a collection of named values, packed in various formats.
bool impl_has(const OUString &_rValueName) const
const css::uno::Any & impl_get(const OUString &_rValueName) const
bool empty() const
determines whether the collection is empty
std::unordered_map< OUString, css::uno::Any > maValues
NamedValueCollection & merge(const NamedValueCollection &_rAdditionalValues, bool _bOverwriteExisting)
merges the content of another collection into this
sal_Int32 operator>>=(css::uno::Sequence< css::beans::PropertyValue > &_out_rValues) const
transforms the collection to a sequence of PropertyValues
bool get_ensureType(const char *_pAsciiValueName, VALUE_TYPE &_out_rValue) const
retrieves a value with a given name from the collection, if it is present
::boost::spirit::classic::rule< ScannerT > argument
PropertyValueVector_t aPropertyValues
#define SAL_WARN_IF(condition, area, stream)
static bool canExtractFrom(css::uno::Any const &i_value)
determines whether or not named values can be extracted from the given value
void impl_assign(const css::uno::Any &i_rWrappedElements)
NamedValueCollection()=default
size_t size() const
returns the number of elements in the collection