diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2012-01-30 12:19:11 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2012-01-30 12:27:47 +0100 |
commit | e8bb827571f540ac4af2247cb11239bb96876669 (patch) | |
tree | 24a7ee39d336a476c88f76f533fb292d5fdd9332 /unotools/inc | |
parent | dc6953f932ffbddd5168f039e58075789b91b98b (diff) |
Fixed cppheader.xsl nillable treatment.
* cppheader.xsl had initially been written under the false assumption that a
missing oor:nillable attribute defaults to "false" instead of "true". That has
been fixed.
* As a result, many places that use the new simplified officecfg/*.hxx headers
broke as they did not expect value types to be wrapped boost::optional. To keep
the code simple, I decided to change all occurrences in
officecfg/registry/schema/ of properties that specify a default <value> and do
not explicitly specify oor:nillable="true" to oor:nillable="false". Strictly
speaking, this is an incompatible change, but in many cases it should be what
was intended, anyway.
* Some places that use the new simplified officecfg/*.hxx headers still had to
be adapted to boost::optional wrapping.
* This showed that unotools/configuration.hxx did not yet work for those wrapped
properties and needed fixing, too.
Diffstat (limited to 'unotools/inc')
-rw-r--r-- | unotools/inc/unotools/configuration.hxx | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/unotools/inc/unotools/configuration.hxx b/unotools/inc/unotools/configuration.hxx index cfcc7e776404..f308aa818037 100644 --- a/unotools/inc/unotools/configuration.hxx +++ b/unotools/inc/unotools/configuration.hxx @@ -33,6 +33,7 @@ #include "sal/config.h" #include "boost/noncopyable.hpp" +#include "boost/optional.hpp" #include "boost/shared_ptr.hpp" #include "com/sun/star/uno/Any.hxx" #include "com/sun/star/uno/Reference.hxx" @@ -155,6 +156,40 @@ private: com::sun::star::container::XHierarchicalNameAccess > access_; }; +/// @internal +template< typename T > struct Convert: private boost::noncopyable { + static com::sun::star::uno::Any toAny(T const & value) + { return com::sun::star::uno::makeAny(value); } + + static T fromAny(com::sun::star::uno::Any const & value) + { return value.get< T >(); } + +private: + Convert(); // not defined + ~Convert(); // not defined +}; + +/// @internal +template< typename T > struct Convert< boost::optional< T > >: + private boost::noncopyable +{ + static com::sun::star::uno::Any toAny(boost::optional< T > const & value) { + return value + ? com::sun::star::uno::makeAny(value.get()) + : com::sun::star::uno::Any(); + } + + static boost::optional< T > fromAny(com::sun::star::uno::Any const & value) + { + return value.hasValue() + ? boost::optional< T >(value.get< T >()) : boost::optional< T >(); + } + +private: + Convert(); // not defined + ~Convert(); // not defined +}; + } /// A type-safe wrapper around a (non-localized) configuration property. @@ -177,7 +212,7 @@ template< typename T, typename U > struct ConfigurationProperty: com::sun::star::uno::Any a( detail::ConfigurationWrapper::get(context).getPropertyValue( T::path())); - return a.get< U >(); + return detail::Convert< U >::fromAny(a); } /// Set the value of the given (non-localized) configuration property, via a @@ -191,7 +226,7 @@ template< typename T, typename U > struct ConfigurationProperty: U const & value) { detail::ConfigurationWrapper::get(context).setPropertyValue( - batch, T::path(), com::sun::star::uno::makeAny(value)); + batch, T::path(), detail::Convert< U >::toAny(value)); } private: @@ -221,7 +256,7 @@ template< typename T, typename U > struct ConfigurationLocalizedProperty: com::sun::star::uno::Any a( detail::ConfigurationWrapper::get(context). getLocalizedPropertyValue(T::path())); - return a.get< U >(); + return detail::Convert< U >::fromAny(a); } /// Set the value of the given localized configuration property, for the @@ -237,7 +272,7 @@ template< typename T, typename U > struct ConfigurationLocalizedProperty: U const & value) { detail::ConfigurationWrapper::get(context).setLocalizedPropertyValue( - batch, T::path(), com::sun::star::uno::makeAny(value)); + batch, T::path(), detail::Convert< U >::toAny(value)); } private: |