diff options
-rw-r--r-- | officecfg/registry/cppheader.xsl | 24 | ||||
-rw-r--r-- | unotools/inc/unotools/configuration.hxx | 48 | ||||
-rw-r--r-- | unotools/source/config/configuration.cxx | 25 |
3 files changed, 93 insertions, 4 deletions
diff --git a/officecfg/registry/cppheader.xsl b/officecfg/registry/cppheader.xsl index df891c29e6e2..2522aca68d5d 100644 --- a/officecfg/registry/cppheader.xsl +++ b/officecfg/registry/cppheader.xsl @@ -141,9 +141,18 @@ <xsl:template match="group"> <xsl:param name="path"/> <xsl:if test=".//prop or .//set"> - <xsl:text>namespace </xsl:text> - <xsl:value-of select="translate(@oor:name, '-.', '__')"/> - <xsl:text> {
</xsl:text> + <xsl:variable name="name" select="translate(@oor:name, '-.', '__')"/> + <xsl:text>struct </xsl:text> + <xsl:value-of select="$name"/> + <xsl:text>: public unotools::ConfigurationGroup< </xsl:text> + <xsl:value-of select="$name"/> + <xsl:text>> {
</xsl:text> + <xsl:text> static rtl::OUString path() { return rtl::OUString(<!-- + -->RTL_CONSTASCII_USTRINGPARAM("</xsl:text> + <xsl:value-of select="$path"/> + <xsl:text>/</xsl:text> + <xsl:value-of select="@oor:name"/> + <xsl:text>")); }
</xsl:text> <xsl:text>
</xsl:text> <xsl:apply-templates select="group|set|prop"> <xsl:with-param name="path"> @@ -152,7 +161,14 @@ <xsl:value-of select="@oor:name"/> </xsl:with-param> </xsl:apply-templates> - <xsl:text>}
</xsl:text> + <xsl:text>private:
</xsl:text> + <xsl:text> </xsl:text> + <xsl:value-of select="$name"/> + <xsl:text>(); // not defined
</xsl:text> + <xsl:text> ~</xsl:text> + <xsl:value-of select="$name"/> + <xsl:text>(); // not defined
</xsl:text> + <xsl:text>};
</xsl:text> <xsl:text>
</xsl:text> </xsl:if> </xsl:template> diff --git a/unotools/inc/unotools/configuration.hxx b/unotools/inc/unotools/configuration.hxx index c9969c8a024f..cfcc7e776404 100644 --- a/unotools/inc/unotools/configuration.hxx +++ b/unotools/inc/unotools/configuration.hxx @@ -43,6 +43,7 @@ namespace com { namespace sun { namespace star { namespace configuration { class XReadWriteAccess; } namespace container { class XHierarchicalNameAccess; + class XHierarchicalNameReplace; class XNameAccess; class XNameContainer; } @@ -80,6 +81,10 @@ private: rtl::OUString const & path, com::sun::star::uno::Any const & value) const; + SAL_DLLPRIVATE com::sun::star::uno::Reference< + com::sun::star::container::XHierarchicalNameReplace > + getGroup(rtl::OUString const & path) const; + SAL_DLLPRIVATE com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > getSet(rtl::OUString const & path) const; @@ -120,6 +125,16 @@ public: rtl::OUString const & path, com::sun::star::uno::Any const & value) const; + com::sun::star::uno::Reference< + com::sun::star::container::XHierarchicalNameAccess > + getGroupReadOnly(rtl::OUString const & path) const; + + com::sun::star::uno::Reference< + com::sun::star::container::XHierarchicalNameReplace > + getGroupReadWrite( + boost::shared_ptr< ConfigurationChanges > const & batch, + rtl::OUString const & path) const; + com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > getSetReadOnly(rtl::OUString const & path) const; @@ -230,6 +245,39 @@ private: ~ConfigurationLocalizedProperty(); // not defined }; +/// A type-safe wrapper around a configuration group. +/// +/// Automatically generated headers for the various configuration groups derive +/// from this template and make available its member functions to access each +/// given configuration group. +template< typename T > struct ConfigurationGroup: private boost::noncopyable { + /// Get read-only access to the given configuration group. + static com::sun::star::uno::Reference< + com::sun::star::container::XHierarchicalNameAccess > + get(com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > + const & context) + { + return detail::ConfigurationWrapper::get(context).getGroupReadOnly( + T::path()); + } + + /// Get read/write access to the given configuration group, storing any + /// modifications via the given changes batch. + static com::sun::star::uno::Reference< + com::sun::star::container::XHierarchicalNameReplace > + get(com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > + const & context, + boost::shared_ptr< ConfigurationChanges > const & batch) + { + return detail::ConfigurationWrapper::get(context).getGroupReadWrite( + batch, T::path()); + } + +private: + ConfigurationGroup(); // not defined + ~ConfigurationGroup(); // not defined +}; + /// A type-safe wrapper around a configuration set. /// /// Automatically generated headers for the various configuration sets derive diff --git a/unotools/source/config/configuration.cxx b/unotools/source/config/configuration.cxx index a4b30ed360fa..a8c818c124dd 100644 --- a/unotools/source/config/configuration.cxx +++ b/unotools/source/config/configuration.cxx @@ -37,6 +37,7 @@ #include "com/sun/star/configuration/XReadWriteAccess.hpp" #include "com/sun/star/configuration/theDefaultProvider.hpp" #include "com/sun/star/container/XHierarchicalNameAccess.hpp" +#include "com/sun/star/container/XHierarchicalNameReplace.hpp" #include "com/sun/star/container/XNameAccess.hpp" #include "com/sun/star/container/XNameContainer.hpp" #include "com/sun/star/lang/Locale.hpp" @@ -90,6 +91,13 @@ void unotools::ConfigurationChanges::setPropertyValue( access_->replaceByHierarchicalName(path, value); } +css::uno::Reference< css::container::XHierarchicalNameReplace > +unotools::ConfigurationChanges::getGroup(rtl::OUString const & path) const +{ + return css::uno::Reference< css::container::XHierarchicalNameReplace >( + access_->getByHierarchicalName(path), css::uno::UNO_QUERY_THROW); +} + css::uno::Reference< css::container::XNameContainer > unotools::ConfigurationChanges::getSet(rtl::OUString const & path) const { @@ -139,6 +147,23 @@ void unotools::detail::ConfigurationWrapper::setLocalizedPropertyValue( batch->setPropertyValue(extendLocalizedPath(path), value); } +css::uno::Reference< css::container::XHierarchicalNameAccess > +unotools::detail::ConfigurationWrapper::getGroupReadOnly( + rtl::OUString const & path) const +{ + return css::uno::Reference< css::container::XHierarchicalNameAccess >( + access_->getByHierarchicalName(path), css::uno::UNO_QUERY_THROW); +} + +css::uno::Reference< css::container::XHierarchicalNameReplace > +unotools::detail::ConfigurationWrapper::getGroupReadWrite( + boost::shared_ptr< ConfigurationChanges > const & batch, + rtl::OUString const & path) const +{ + assert(batch.get() != 0); + return batch->getGroup(path); +} + css::uno::Reference< css::container::XNameAccess > unotools::detail::ConfigurationWrapper::getSetReadOnly( rtl::OUString const & path) const |