LCOV - code coverage report
Current view: top level - libreoffice/solver/unxlngi6.pro/inc/comphelper - configuration.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 12 24 50.0 %
Date: 2012-12-27 Functions: 26 104 25.0 %
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             :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4             :  *
       5             :  * The contents of this file are subject to the Mozilla Public License Version
       6             :  * 1.1 (the "License"); you may not use this file except in compliance with
       7             :  * the License or as specified alternatively below. You may obtain a copy of
       8             :  * the License at http://www.mozilla.org/MPL/
       9             :  *
      10             :  * Software distributed under the License is distributed on an "AS IS" basis,
      11             :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12             :  * for the specific language governing rights and limitations under the
      13             :  * License.
      14             :  *
      15             :  * Major Contributor(s):
      16             :  * Copyright (C) 2011 Red Hat, Inc., Stephan Bergmann <sbergman@redhat.com>
      17             :  * (initial developer)
      18             :  *
      19             :  * All Rights Reserved.
      20             :  *
      21             :  * For minor contributions see the git repository.
      22             :  *
      23             :  * Alternatively, the contents of this file may be used under the terms of
      24             :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      25             :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      26             :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      27             :  * instead of those above.
      28             :  */
      29             : 
      30             : #ifndef INCLUDED_COMPHELPER_CONFIGURATION_HXX
      31             : #define INCLUDED_COMPHELPER_CONFIGURATION_HXX
      32             : 
      33             : #include "sal/config.h"
      34             : 
      35             : #include "boost/noncopyable.hpp"
      36             : #include "boost/optional.hpp"
      37             : #include "boost/shared_ptr.hpp"
      38             : #include "com/sun/star/uno/Any.hxx"
      39             : #include "com/sun/star/uno/Reference.hxx"
      40             : #include "comphelper/comphelperdllapi.h"
      41             : #include "comphelper/processfactory.hxx"
      42             : #include "sal/types.h"
      43             : 
      44             : namespace com { namespace sun { namespace star {
      45             :     namespace configuration { class XReadWriteAccess; }
      46             :     namespace container {
      47             :         class XHierarchicalNameAccess;
      48             :         class XHierarchicalNameReplace;
      49             :         class XNameAccess;
      50             :         class XNameContainer;
      51             :     }
      52             :     namespace uno { class XComponentContext; }
      53             : } } }
      54             : namespace rtl { class OUString; }
      55             : 
      56             : namespace comphelper {
      57             : 
      58             : namespace detail { class ConfigurationWrapper; }
      59             : 
      60             : /// A batch of configuration changes that is committed as a whole.
      61             : ///
      62             : /// Client code needs to call commit explicitly; otherwise the changes are lost
      63             : /// when the instance is destroyed.
      64             : ///
      65             : /// This is the only class from this header file that client code should use
      66             : /// directly.
      67             : class COMPHELPER_DLLPUBLIC ConfigurationChanges: private boost::noncopyable {
      68             : public:
      69             :     static boost::shared_ptr< ConfigurationChanges > create(
      70             :         com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
      71             :             const & context = comphelper::getProcessComponentContext());
      72             : 
      73             :     ~ConfigurationChanges();
      74             : 
      75             :     void commit() const;
      76             : 
      77             : private:
      78             :     SAL_DLLPRIVATE ConfigurationChanges(
      79             :         com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
      80             :             const & context);
      81             : 
      82             :     SAL_DLLPRIVATE void setPropertyValue(
      83             :         rtl::OUString const & path, com::sun::star::uno::Any const & value)
      84             :         const;
      85             : 
      86             :     SAL_DLLPRIVATE com::sun::star::uno::Reference<
      87             :         com::sun::star::container::XHierarchicalNameReplace >
      88             :     getGroup(rtl::OUString const & path) const;
      89             : 
      90             :     SAL_DLLPRIVATE
      91             :     com::sun::star::uno::Reference< com::sun::star::container::XNameContainer >
      92             :     getSet(rtl::OUString const & path) const;
      93             : 
      94             :     com::sun::star::uno::Reference<
      95             :         com::sun::star::configuration::XReadWriteAccess > access_;
      96             : 
      97             :     friend class detail::ConfigurationWrapper;
      98             : };
      99             : 
     100             : namespace detail {
     101             : 
     102             : /// @internal
     103             : class COMPHELPER_DLLPUBLIC ConfigurationWrapper: private boost::noncopyable {
     104             : public:
     105             :     static ConfigurationWrapper const & get(
     106             :         com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
     107             :             const & context);
     108             : 
     109             :     SAL_DLLPRIVATE explicit ConfigurationWrapper(
     110             :         com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
     111             :             const & context);
     112             : 
     113             :     SAL_DLLPRIVATE ~ConfigurationWrapper();
     114             : 
     115             :     com::sun::star::uno::Any getPropertyValue(rtl::OUString const & path) const;
     116             : 
     117             :     void setPropertyValue(
     118             :         boost::shared_ptr< ConfigurationChanges > const & batch,
     119             :         rtl::OUString const & path, com::sun::star::uno::Any const & value)
     120             :         const;
     121             : 
     122             :     com::sun::star::uno::Any getLocalizedPropertyValue(
     123             :         rtl::OUString const & path) const;
     124             : 
     125             :     void setLocalizedPropertyValue(
     126             :         boost::shared_ptr< ConfigurationChanges > const & batch,
     127             :         rtl::OUString const & path, com::sun::star::uno::Any const & value)
     128             :         const;
     129             : 
     130             :     com::sun::star::uno::Reference<
     131             :         com::sun::star::container::XHierarchicalNameAccess >
     132             :     getGroupReadOnly(rtl::OUString const & path) const;
     133             : 
     134             :     com::sun::star::uno::Reference<
     135             :         com::sun::star::container::XHierarchicalNameReplace >
     136             :     getGroupReadWrite(
     137             :         boost::shared_ptr< ConfigurationChanges > const & batch,
     138             :         rtl::OUString const & path) const;
     139             : 
     140             :     com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >
     141             :     getSetReadOnly(rtl::OUString const & path) const;
     142             : 
     143             :     com::sun::star::uno::Reference< com::sun::star::container::XNameContainer >
     144             :     getSetReadWrite(
     145             :         boost::shared_ptr< ConfigurationChanges > const & batch,
     146             :         rtl::OUString const & path) const;
     147             : 
     148             :     boost::shared_ptr< ConfigurationChanges > createChanges() const;
     149             : 
     150             : private:
     151             :     com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
     152             :         context_;
     153             : 
     154             :     com::sun::star::uno::Reference<
     155             :         com::sun::star::container::XHierarchicalNameAccess > access_;
     156             : };
     157             : 
     158             : /// @internal
     159             : template< typename T > struct Convert: private boost::noncopyable {
     160           0 :     static com::sun::star::uno::Any toAny(T const & value)
     161           0 :     { return com::sun::star::uno::makeAny(value); }
     162             : 
     163        4985 :     static T fromAny(com::sun::star::uno::Any const & value)
     164        4985 :     { return value.get< T >(); }
     165             : 
     166             : private:
     167             :     Convert(); // not defined
     168             :     ~Convert(); // not defined
     169             : };
     170             : 
     171             : /// @internal
     172             : template< typename T > struct Convert< boost::optional< T > >:
     173             :     private boost::noncopyable
     174             : {
     175           0 :     static com::sun::star::uno::Any toAny(boost::optional< T > const & value) {
     176             :         return value
     177             :             ? com::sun::star::uno::makeAny(value.get())
     178           0 :             : com::sun::star::uno::Any();
     179             :     }
     180             : 
     181           2 :     static boost::optional< T > fromAny(com::sun::star::uno::Any const & value)
     182             :     {
     183             :         return value.hasValue()
     184           2 :             ? boost::optional< T >(value.get< T >()) : boost::optional< T >();
     185             :     }
     186             : 
     187             : private:
     188             :     Convert(); // not defined
     189             :     ~Convert(); // not defined
     190             : };
     191             : 
     192             : }
     193             : 
     194             : /// A type-safe wrapper around a (non-localized) configuration property.
     195             : ///
     196             : /// Automatically generated headers for the various configuration properties
     197             : /// derive from this template and make available its member functions to access
     198             : /// each given configuration property.
     199             : template< typename T, typename U > struct ConfigurationProperty:
     200             :     private boost::noncopyable
     201             : {
     202             :     /// Get the value of the given (non-localized) configuration property.
     203             :     ///
     204             :     /// For nillable properties, U is of type boost::optional<U'>.
     205        4987 :     static U get(
     206             :         com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
     207        5116 :             const & context = comphelper::getProcessComponentContext())
     208             :     {
     209             :         // Folding this into one statement causes a bogus error at least with
     210             :         // Red Hat GCC 4.6.2-1:
     211             :         com::sun::star::uno::Any a(
     212             :             detail::ConfigurationWrapper::get(context).getPropertyValue(
     213        4987 :                 T::path()));
     214        4987 :         return detail::Convert< U >::fromAny(a);
     215             :     }
     216             : 
     217             :     /// Set the value of the given (non-localized) configuration property, via a
     218             :     /// given changes batch.
     219             :     ///
     220             :     /// For nillable properties, U is of type boost::optional<U'>.
     221           0 :     static void set(
     222             :         U const & value,
     223             :         boost::shared_ptr< ConfigurationChanges > const & batch,
     224             :         com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
     225           0 :             const & context = comphelper::getProcessComponentContext())
     226             :     {
     227           0 :         detail::ConfigurationWrapper::get(context).setPropertyValue(
     228             :             batch, T::path(), detail::Convert< U >::toAny(value));
     229           0 :     }
     230             : 
     231             : private:
     232             :     ConfigurationProperty(); // not defined
     233             :     ~ConfigurationProperty(); // not defined
     234             : };
     235             : 
     236             : /// A type-safe wrapper around a localized configuration property.
     237             : ///
     238             : /// Automatically generated headers for the various localized configuration
     239             : /// properties derive from this template and make available its member functions
     240             : /// to access each given localized configuration property.
     241             : template< typename T, typename U > struct ConfigurationLocalizedProperty:
     242             :     private boost::noncopyable
     243             : {
     244             :     /// Get the value of the given localized configuration property, for the
     245             :     /// locale currently set at the
     246             :     /// com.sun.star.configuration.theDefaultProvider.
     247             :     ///
     248             :     /// For nillable properties, U is of type boost::optional<U'>.
     249             :     static U get(
     250             :         com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
     251             :             const & context = comphelper::getProcessComponentContext())
     252             :     {
     253             :         // Folding this into one statement causes a bogus error at least with
     254             :         // Red Hat GCC 4.6.2-1:
     255             :         com::sun::star::uno::Any a(
     256             :             detail::ConfigurationWrapper::get(context).
     257             :             getLocalizedPropertyValue(T::path()));
     258             :         return detail::Convert< U >::fromAny(a);
     259             :     }
     260             : 
     261             :     /// Set the value of the given localized configuration property, for the
     262             :     /// locale currently set at the
     263             :     /// com.sun.star.configuration.theDefaultProvider, via a given changes
     264             :     /// batch.
     265             :     ///
     266             :     /// For nillable properties, U is of type boost::optional<U'>.
     267             :     static void set(
     268             :         U const & value,
     269             :         boost::shared_ptr< ConfigurationChanges > const & batch,
     270             :         com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
     271             :             const & context = comphelper::getProcessComponentContext())
     272             :     {
     273             :         detail::ConfigurationWrapper::get(context).setLocalizedPropertyValue(
     274             :             batch, T::path(), detail::Convert< U >::toAny(value));
     275             :     }
     276             : 
     277             : private:
     278             :     ConfigurationLocalizedProperty(); // not defined
     279             :     ~ConfigurationLocalizedProperty(); // not defined
     280             : };
     281             : 
     282             : /// A type-safe wrapper around a configuration group.
     283             : ///
     284             : /// Automatically generated headers for the various configuration groups derive
     285             : /// from this template and make available its member functions to access each
     286             : /// given configuration group.
     287             : template< typename T > struct ConfigurationGroup: private boost::noncopyable {
     288             :     /// Get read-only access to the given configuration group.
     289             :     static com::sun::star::uno::Reference<
     290             :         com::sun::star::container::XHierarchicalNameAccess >
     291           3 :     get(com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
     292             :             const & context = comphelper::getProcessComponentContext())
     293             :     {
     294             :         return detail::ConfigurationWrapper::get(context).getGroupReadOnly(
     295           3 :             T::path());
     296             :     }
     297             : 
     298             :     /// Get read/write access to the given configuration group, storing any
     299             :     /// modifications via the given changes batch.
     300             :     static com::sun::star::uno::Reference<
     301             :         com::sun::star::container::XHierarchicalNameReplace >
     302             :     get(boost::shared_ptr< ConfigurationChanges > const & batch,
     303             :         com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
     304             :             const & context = comphelper::getProcessComponentContext())
     305             :     {
     306             :         return detail::ConfigurationWrapper::get(context).getGroupReadWrite(
     307             :             batch, T::path());
     308             :     }
     309             : 
     310             : private:
     311             :     ConfigurationGroup(); // not defined
     312             :     ~ConfigurationGroup(); // not defined
     313             : };
     314             : 
     315             : /// A type-safe wrapper around a configuration set.
     316             : ///
     317             : /// Automatically generated headers for the various configuration sets derive
     318             : /// from this template and make available its member functions to access each
     319             : /// given configuration set.
     320             : template< typename T > struct ConfigurationSet: private boost::noncopyable {
     321             :     /// Get read-only access to the given configuration set.
     322             :     static
     323             :     com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >
     324         395 :     get(com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
     325           0 :             const & context = comphelper::getProcessComponentContext())
     326             :     {
     327             :         return detail::ConfigurationWrapper::get(context).getSetReadOnly(
     328         395 :             T::path());
     329             :     }
     330             : 
     331             :     /// Get read/write access to the given configuration set, storing any
     332             :     /// modifications via the given changes batch.
     333             :     static
     334             :     com::sun::star::uno::Reference< com::sun::star::container::XNameContainer >
     335           0 :     get(boost::shared_ptr< ConfigurationChanges > const & batch,
     336             :         com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
     337           0 :             const & context = comphelper::getProcessComponentContext())
     338             :     {
     339             :         return detail::ConfigurationWrapper::get(context).getSetReadWrite(
     340           0 :             batch, T::path());
     341             :     }
     342             : 
     343             : private:
     344             :     ConfigurationSet(); // not defined
     345             :     ~ConfigurationSet(); // not defined
     346             : };
     347             : 
     348             : }
     349             : 
     350             : #endif
     351             : 
     352             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10