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>
30#include <unordered_map>
36 using ::com::sun::star::uno::Any;
37 using ::com::sun::star::uno::Sequence;
38 using ::com::sun::star::beans::PropertyValue;
39 using ::com::sun::star::beans::NamedValue;
40 using ::com::sun::star::uno::Type;
41 using ::com::sun::star::uno::cpp_acquire;
42 using ::com::sun::star::uno::cpp_release;
43 using ::com::sun::star::uno::cpp_queryInterface;
44 using ::com::sun::star::lang::IllegalArgumentException;
45 using ::com::sun::star::beans::PropertyState_DIRECT_VALUE;
73 Type const & aValueType = i_value.getValueType();
107 std::vector< OUString > aNames;
110 aNames.push_back(
value.first );
118 Sequence< NamedValue > aNamedValues;
120 NamedValue aNamedValue;
121 PropertyValue aPropertyValue;
123 if ( i_rWrappedElements >>= aNamedValues )
125 else if ( i_rWrappedElements >>= aPropertyValues )
127 else if ( i_rWrappedElements >>= aNamedValue )
128 impl_assign( Sequence< NamedValue >( &aNamedValue, 1 ) );
129 else if ( i_rWrappedElements >>= aPropertyValue )
130 impl_assign( Sequence< PropertyValue >( &aPropertyValue, 1 ) );
132 SAL_WARN_IF( i_rWrappedElements.hasValue(),
"comphelper",
"NamedValueCollection::impl_assign(Any): unsupported type!" );
140 PropertyValue aPropertyValue;
141 NamedValue aNamedValue;
143 for (
auto const & argument : _rArguments )
145 if ( argument >>= aPropertyValue )
146 maValues[ aPropertyValue.Name ] = aPropertyValue.Value;
147 else if ( argument >>= aNamedValue )
148 maValues[ aNamedValue.Name ] = aNamedValue.Value;
153 (
"NamedValueCollection::impl_assign: encountered a value"
154 " type which I cannot handle: "
165 for (
auto const & argument : _rArguments )
174 for (
auto const & argument : _rArguments )
187 _pValueLocation, _rExpectedValueType.getTypeLibType(),
188 const_cast< void*
>(
pos->second.getValue() ),
pos->second.getValueType().getTypeLibType(),
189 reinterpret_cast< uno_QueryInterfaceFunc
>( cpp_queryInterface ),
190 reinterpret_cast< uno_AcquireFunc
>( cpp_acquire ),
191 reinterpret_cast< uno_ReleaseFunc
>( cpp_release )
197 throw IllegalArgumentException(
198 "Invalid value type for '" + _rValueName
199 +
"'.\nExpected: " + _rExpectedValueType.getTypeName()
200 +
"\nFound: " +
pos->second.getValueType().getTypeName(),
206 std::u16string_view _rValueName,
void* _pValueLocation,
const Type& _rExpectedValueType )
208 for (
const css::beans::PropertyValue& rPropVal : rPropSeq)
210 if (rPropVal.Name == _rValueName)
213 _pValueLocation, _rExpectedValueType.getTypeLibType(),
214 const_cast< void*
>( rPropVal.Value.getValue() ), rPropVal.Value.getValueType().getTypeLibType(),
215 reinterpret_cast< uno_QueryInterfaceFunc
>( cpp_queryInterface ),
216 reinterpret_cast< uno_AcquireFunc
>( cpp_acquire ),
217 reinterpret_cast< uno_ReleaseFunc
>( cpp_release )
223 throw IllegalArgumentException(
224 OUString::Concat(
"Invalid value type for '") + _rValueName
225 +
"'.\nExpected: " + _rExpectedValueType.getTypeName()
226 +
"\nFound: " + rPropVal.Value.getValueType().getTypeName(),
236 std::u16string_view _rValueName )
238 static const Any theEmptyDefault;
239 for (
const css::beans::PropertyValue& rPropVal : rPropSeq)
241 if (rPropVal.Name == _rValueName)
243 return rPropVal.Value;
246 return theEmptyDefault;
251 static const Any theEmptyDefault;
256 return theEmptyDefault;
269 bool bHas =
impl_has( _rValueName );
287 _out_rValues.realloc(
maValues.size() );
289 [](
const std::pair< OUString, css::uno::Any >& _rValue)
290 { return PropertyValue( _rValue.first, 0, _rValue.second, PropertyState_DIRECT_VALUE ); } );
291 return _out_rValues.getLength();
297 _out_rValues.realloc(
maValues.size() );
299 [](
const std::pair< OUString, css::uno::Any >& _rValue)
300 { return NamedValue( _rValue.first, _rValue.second ); } );
301 return _out_rValues.getLength();
::boost::spirit::classic::rule< ScannerT > argument
PropertyValueVector_t aPropertyValues
a collection of named values, packed in various formats.
bool get_ensureType(const OUString &_rValueName, VALUE_TYPE &_out_rValue) const
retrieves a value with a given name from the collection, if it is present
const css::uno::Any & get(const OUString &_rValueName) const
retrieves a (untyped) value with a given name
static bool canExtractFrom(css::uno::Any const &i_value)
determines whether or not named values can be extracted from the given value
NamedValueCollection()=default
bool impl_put(const OUString &_rValueName, const css::uno::Any &_rValue)
bool impl_has(const OUString &_rValueName) const
void impl_assign(const css::uno::Any &i_rWrappedElements)
const css::uno::Any & impl_get(const OUString &_rValueName) const
std::unordered_map< OUString, css::uno::Any > maValues
NamedValueCollection & merge(const NamedValueCollection &_rAdditionalValues, bool _bOverwriteExisting)
merges the content of another collection into this
bool empty() const
determines whether the collection is empty
bool impl_remove(const OUString &_rValueName)
size_t size() const
returns the number of elements in the collection
sal_Int32 operator>>=(css::uno::Sequence< css::beans::PropertyValue > &_out_rValues) const
transforms the collection to a sequence of PropertyValues
::std::vector< OUString > getNames() const
returns the names of all elements in the collection
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()
#define SAL_WARN_IF(condition, area, stream)