LCOV - code coverage report
Current view: top level - include/comphelper - configuration.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 20 26 76.9 %
Date: 2014-11-03 Functions: 65 158 41.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #ifndef INCLUDED_COMPHELPER_CONFIGURATION_HXX
      11             : #define INCLUDED_COMPHELPER_CONFIGURATION_HXX
      12             : 
      13             : #include <sal/config.h>
      14             : 
      15             : #include <boost/noncopyable.hpp>
      16             : #include <boost/optional.hpp>
      17             : #include <boost/shared_ptr.hpp>
      18             : #include <com/sun/star/uno/Any.hxx>
      19             : #include <com/sun/star/uno/Reference.hxx>
      20             : #include <comphelper/comphelperdllapi.h>
      21             : #include <comphelper/processfactory.hxx>
      22             : #include <sal/types.h>
      23             : 
      24             : namespace com { namespace sun { namespace star {
      25             :     namespace configuration { class XReadWriteAccess; }
      26             :     namespace container {
      27             :         class XHierarchicalNameAccess;
      28             :         class XHierarchicalNameReplace;
      29             :         class XNameAccess;
      30             :         class XNameContainer;
      31             :     }
      32             :     namespace uno { class XComponentContext; }
      33             : } } }
      34             : 
      35             : namespace comphelper {
      36             : 
      37             : namespace detail { class ConfigurationWrapper; }
      38             : 
      39             : /// A batch of configuration changes that is committed as a whole.
      40             : ///
      41             : /// Client code needs to call commit explicitly; otherwise the changes are lost
      42             : /// when the instance is destroyed.
      43             : ///
      44             : /// This is the only class from this header file that client code should use
      45             : /// directly.
      46             : class COMPHELPER_DLLPUBLIC ConfigurationChanges: private boost::noncopyable {
      47             : public:
      48             :     static boost::shared_ptr< ConfigurationChanges > create(
      49             :         com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
      50             :             const & context = comphelper::getProcessComponentContext());
      51             : 
      52             :     ~ConfigurationChanges();
      53             : 
      54             :     void commit() const;
      55             : 
      56             : private:
      57             :     SAL_DLLPRIVATE ConfigurationChanges(
      58             :         com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
      59             :             const & context);
      60             : 
      61             :     SAL_DLLPRIVATE void setPropertyValue(
      62             :         OUString const & path, com::sun::star::uno::Any const & value)
      63             :         const;
      64             : 
      65             :     SAL_DLLPRIVATE com::sun::star::uno::Reference<
      66             :         com::sun::star::container::XHierarchicalNameReplace >
      67             :     getGroup(OUString const & path) const;
      68             : 
      69             :     SAL_DLLPRIVATE
      70             :     com::sun::star::uno::Reference< com::sun::star::container::XNameContainer >
      71             :     getSet(OUString const & path) const;
      72             : 
      73             :     com::sun::star::uno::Reference<
      74             :         com::sun::star::configuration::XReadWriteAccess > access_;
      75             : 
      76             :     friend class detail::ConfigurationWrapper;
      77             : };
      78             : 
      79             : namespace detail {
      80             : 
      81             : /// @internal
      82             : class COMPHELPER_DLLPUBLIC ConfigurationWrapper: private boost::noncopyable {
      83             : public:
      84             :     static ConfigurationWrapper const & get(
      85             :         com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
      86             :             const & context);
      87             : 
      88             :     SAL_DLLPRIVATE explicit ConfigurationWrapper(
      89             :         com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
      90             :             const & context);
      91             : 
      92             :     SAL_DLLPRIVATE ~ConfigurationWrapper();
      93             : 
      94             :     com::sun::star::uno::Any getPropertyValue(OUString const & path) const;
      95             : 
      96             :     void setPropertyValue(
      97             :         boost::shared_ptr< ConfigurationChanges > const & batch,
      98             :         OUString const & path, com::sun::star::uno::Any const & value)
      99             :         const;
     100             : 
     101             :     com::sun::star::uno::Any getLocalizedPropertyValue(
     102             :         OUString const & path) const;
     103             : 
     104             :     void setLocalizedPropertyValue(
     105             :         boost::shared_ptr< ConfigurationChanges > const & batch,
     106             :         OUString const & path, com::sun::star::uno::Any const & value)
     107             :         const;
     108             : 
     109             :     com::sun::star::uno::Reference<
     110             :         com::sun::star::container::XHierarchicalNameAccess >
     111             :     getGroupReadOnly(OUString const & path) const;
     112             : 
     113             :     com::sun::star::uno::Reference<
     114             :         com::sun::star::container::XHierarchicalNameReplace >
     115             :     getGroupReadWrite(
     116             :         boost::shared_ptr< ConfigurationChanges > const & batch,
     117             :         OUString const & path) const;
     118             : 
     119             :     com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >
     120             :     getSetReadOnly(OUString const & path) const;
     121             : 
     122             :     com::sun::star::uno::Reference< com::sun::star::container::XNameContainer >
     123             :     getSetReadWrite(
     124             :         boost::shared_ptr< ConfigurationChanges > const & batch,
     125             :         OUString const & path) const;
     126             : 
     127             :     boost::shared_ptr< ConfigurationChanges > createChanges() const;
     128             : 
     129             : private:
     130             :     com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
     131             :         context_;
     132             : 
     133             :     com::sun::star::uno::Reference<
     134             :         com::sun::star::container::XHierarchicalNameAccess > access_;
     135             : };
     136             : 
     137             : /// @internal
     138             : template< typename T > struct Convert: private boost::noncopyable {
     139         536 :     static com::sun::star::uno::Any toAny(T const & value)
     140         536 :     { return com::sun::star::uno::makeAny(value); }
     141             : 
     142      164767 :     static T fromAny(com::sun::star::uno::Any const & value)
     143      164767 :     { return value.get< T >(); }
     144             : 
     145             : private:
     146             :     Convert(); // not defined
     147             :     ~Convert(); // not defined
     148             : };
     149             : 
     150             : /// @internal
     151             : template< typename T > struct Convert< boost::optional< T > >:
     152             :     private boost::noncopyable
     153             : {
     154           0 :     static com::sun::star::uno::Any toAny(boost::optional< T > const & value) {
     155             :         return value
     156           0 :             ? com::sun::star::uno::makeAny(value.get())
     157           0 :             : com::sun::star::uno::Any();
     158             :     }
     159             : 
     160        6619 :     static boost::optional< T > fromAny(com::sun::star::uno::Any const & value)
     161             :     {
     162        6619 :         return value.hasValue()
     163        6619 :             ? boost::optional< T >(value.get< T >()) : boost::optional< T >();
     164             :     }
     165             : 
     166             : private:
     167             :     Convert(); // not defined
     168             :     ~Convert(); // not defined
     169             : };
     170             : 
     171             : }
     172             : 
     173             : /// A type-safe wrapper around a (non-localized) configuration property.
     174             : ///
     175             : /// Automatically generated headers for the various configuration properties
     176             : /// derive from this template and make available its member functions to access
     177             : /// each given configuration property.
     178             : template< typename T, typename U > struct ConfigurationProperty:
     179             :     private boost::noncopyable
     180             : {
     181             :     /// Get the value of the given (non-localized) configuration property.
     182             :     ///
     183             :     /// For nillable properties, U is of type boost::optional<U'>.
     184      171386 :     static U get(
     185             :         com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
     186             :             const & context = comphelper::getProcessComponentContext())
     187             :     {
     188             :         // Folding this into one statement causes a bogus error at least with
     189             :         // Red Hat GCC 4.6.2-1:
     190             :         com::sun::star::uno::Any a(
     191      171386 :             detail::ConfigurationWrapper::get(context).getPropertyValue(
     192      342772 :                 T::path()));
     193      171386 :         return detail::Convert< U >::fromAny(a);
     194             :     }
     195             : 
     196             :     /// Set the value of the given (non-localized) configuration property, via a
     197             :     /// given changes batch.
     198             :     ///
     199             :     /// For nillable properties, U is of type boost::optional<U'>.
     200         536 :     static void set(
     201             :         U const & value,
     202             :         boost::shared_ptr< ConfigurationChanges > const & batch,
     203             :         com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
     204             :             const & context = comphelper::getProcessComponentContext())
     205             :     {
     206         536 :         detail::ConfigurationWrapper::get(context).setPropertyValue(
     207             :             batch, T::path(), detail::Convert< U >::toAny(value));
     208         536 :     }
     209             : 
     210             : private:
     211             :     ConfigurationProperty(); // not defined
     212             :     ~ConfigurationProperty(); // not defined
     213             : };
     214             : 
     215             : /// A type-safe wrapper around a localized configuration property.
     216             : ///
     217             : /// Automatically generated headers for the various localized configuration
     218             : /// properties derive from this template and make available its member functions
     219             : /// to access each given localized configuration property.
     220             : template< typename T, typename U > struct ConfigurationLocalizedProperty:
     221             :     private boost::noncopyable
     222             : {
     223             :     /// Get the value of the given localized configuration property, for the
     224             :     /// locale currently set at the
     225             :     /// com.sun.star.configuration.theDefaultProvider.
     226             :     ///
     227             :     /// For nillable properties, U is of type boost::optional<U'>.
     228             :     static U get(
     229             :         com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
     230             :             const & context = comphelper::getProcessComponentContext())
     231             :     {
     232             :         // Folding this into one statement causes a bogus error at least with
     233             :         // Red Hat GCC 4.6.2-1:
     234             :         com::sun::star::uno::Any a(
     235             :             detail::ConfigurationWrapper::get(context).
     236             :             getLocalizedPropertyValue(T::path()));
     237             :         return detail::Convert< U >::fromAny(a);
     238             :     }
     239             : 
     240             :     /// Set the value of the given localized configuration property, for the
     241             :     /// locale currently set at the
     242             :     /// com.sun.star.configuration.theDefaultProvider, via a given changes
     243             :     /// batch.
     244             :     ///
     245             :     /// For nillable properties, U is of type boost::optional<U'>.
     246             :     static void set(
     247             :         U const & value,
     248             :         boost::shared_ptr< ConfigurationChanges > const & batch,
     249             :         com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
     250             :             const & context = comphelper::getProcessComponentContext())
     251             :     {
     252             :         detail::ConfigurationWrapper::get(context).setLocalizedPropertyValue(
     253             :             batch, T::path(), detail::Convert< U >::toAny(value));
     254             :     }
     255             : 
     256             : private:
     257             :     ConfigurationLocalizedProperty(); // not defined
     258             :     ~ConfigurationLocalizedProperty(); // not defined
     259             : };
     260             : 
     261             : /// A type-safe wrapper around a configuration group.
     262             : ///
     263             : /// Automatically generated headers for the various configuration groups derive
     264             : /// from this template and make available its member functions to access each
     265             : /// given configuration group.
     266             : template< typename T > struct ConfigurationGroup: private boost::noncopyable {
     267             :     /// Get read-only access to the given configuration group.
     268             :     static com::sun::star::uno::Reference<
     269             :         com::sun::star::container::XHierarchicalNameAccess >
     270           6 :     get(com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
     271             :             const & context = comphelper::getProcessComponentContext())
     272             :     {
     273           6 :         return detail::ConfigurationWrapper::get(context).getGroupReadOnly(
     274          12 :             T::path());
     275             :     }
     276             : 
     277             :     /// Get read/write access to the given configuration group, storing any
     278             :     /// modifications via the given changes batch.
     279             :     static com::sun::star::uno::Reference<
     280             :         com::sun::star::container::XHierarchicalNameReplace >
     281             :     get(boost::shared_ptr< ConfigurationChanges > const & batch,
     282             :         com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
     283             :             const & context = comphelper::getProcessComponentContext())
     284             :     {
     285             :         return detail::ConfigurationWrapper::get(context).getGroupReadWrite(
     286             :             batch, T::path());
     287             :     }
     288             : 
     289             : private:
     290             :     ConfigurationGroup(); // not defined
     291             :     ~ConfigurationGroup(); // not defined
     292             : };
     293             : 
     294             : /// A type-safe wrapper around a configuration set.
     295             : ///
     296             : /// Automatically generated headers for the various configuration sets derive
     297             : /// from this template and make available its member functions to access each
     298             : /// given configuration set.
     299             : template< typename T > struct ConfigurationSet: private boost::noncopyable {
     300             :     /// Get read-only access to the given configuration set.
     301             :     static
     302             :     com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >
     303        7449 :     get(com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
     304             :             const & context = comphelper::getProcessComponentContext())
     305             :     {
     306        7449 :         return detail::ConfigurationWrapper::get(context).getSetReadOnly(
     307       14898 :             T::path());
     308             :     }
     309             : 
     310             :     /// Get read/write access to the given configuration set, storing any
     311             :     /// modifications via the given changes batch.
     312             :     static
     313             :     com::sun::star::uno::Reference< com::sun::star::container::XNameContainer >
     314           0 :     get(boost::shared_ptr< ConfigurationChanges > const & batch,
     315             :         com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
     316             :             const & context = comphelper::getProcessComponentContext())
     317             :     {
     318           0 :         return detail::ConfigurationWrapper::get(context).getSetReadWrite(
     319           0 :             batch, T::path());
     320             :     }
     321             : 
     322             : private:
     323             :     ConfigurationSet(); // not defined
     324             :     ~ConfigurationSet(); // not defined
     325             : };
     326             : 
     327             : }
     328             : 
     329             : #endif
     330             : 
     331             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10