LCOV - code coverage report
Current view: top level - include/rtl - bootstrap.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 36 37 97.3 %
Date: 2015-06-13 12:38:46 Functions: 13 13 100.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             :  * 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             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : #ifndef INCLUDED_RTL_BOOTSTRAP_HXX
      20             : #define INCLUDED_RTL_BOOTSTRAP_HXX
      21             : #include <rtl/ustring.hxx>
      22             : #include <rtl/bootstrap.h>
      23             : 
      24             : namespace rtl
      25             : {
      26             :     class Bootstrap
      27             :     {
      28             :         void * _handle;
      29             : 
      30             :         Bootstrap( Bootstrap const & ) SAL_DELETED_FUNCTION;
      31             :         Bootstrap & operator = ( Bootstrap const & ) SAL_DELETED_FUNCTION;
      32             : 
      33             :     public:
      34             :         /**
      35             :          * @see rtl_bootstrap_setIniFileName()
      36             :          */
      37             :         static inline void SAL_CALL setIniFilename( const ::rtl::OUString &sFileUri );
      38             : 
      39             :         /** Retrieves a bootstrap parameter
      40             :            @param sName name of the bootstrap value. case insensitive.
      41             :            @param outValue (out parameter). On success contains the value, otherwise
      42             :                   an empty string.
      43             :            @return false, if no value could be retrieved, otherwise true
      44             :            @see rtl_bootstrap_get()
      45             :          */
      46             :         static inline bool get(
      47             :             const ::rtl::OUString &sName,
      48             :             ::rtl::OUString &outValue );
      49             : 
      50             :         /** Retrieves a bootstrap parameter
      51             : 
      52             :            @param sName name of the bootstrap value. case insensitive.
      53             :            @param outValue (out parameter). Contains the value associated with sName.
      54             :            @param aDefault if none of the other methods retrieved a value, outValue
      55             :                            is assigned to a Default.
      56             : 
      57             :            @see rtl_bootstrap_get()
      58             :          */
      59             :         static inline void get(
      60             :             const ::rtl::OUString &sName,
      61             :             ::rtl::OUString &outValue,
      62             :             const ::rtl::OUString &aDefault );
      63             : 
      64             :         /** Sets a bootstrap parameter.
      65             : 
      66             :             @param name
      67             :                    name of bootstrap parameter
      68             :             @param value
      69             :                    value of bootstrap parameter
      70             : 
      71             :             @see rtl_bootstrap_set()
      72             :         */
      73             :         static inline void set( ::rtl::OUString const & name, ::rtl::OUString const & value );
      74             : 
      75             :         /** default ctor.
      76             :          */
      77             :         inline Bootstrap();
      78             : 
      79             :         /** Opens a bootstrap argment container
      80             :             @see rtl_bootstrap_args_open()
      81             :          */
      82             :         inline Bootstrap(const rtl::OUString & iniName);
      83             : 
      84             :         /** Closes a bootstrap argument container
      85             :             @see rtl_bootstrap_args_close()
      86             :         */
      87             :         inline ~Bootstrap();
      88             : 
      89             :         /** Retrieves a bootstrap argument.
      90             : 
      91             :             It is first tried to retrieve the value via the global function
      92             :             and second via the special bootstrap container.
      93             :             @see rtl_bootstrap_get_from_handle()
      94             :         */
      95             : 
      96             :         inline bool getFrom(const ::rtl::OUString &sName,
      97             :                                 ::rtl::OUString &outValue) const;
      98             : 
      99             :         /** Retrieves a bootstrap argument.
     100             : 
     101             :             It is first tried to retrieve the value via the global function
     102             :             and second via the special bootstrap container.
     103             :             @see rtl_bootstrap_get_from_handle()
     104             :         */
     105             :         inline void getFrom(const ::rtl::OUString &sName,
     106             :                             ::rtl::OUString &outValue,
     107             :                             const ::rtl::OUString &aDefault) const;
     108             : 
     109             :         /** Retrieves the name of the underlying ini-file.
     110             :             @see rtl_bootstrap_get_iniName_from_handle()
     111             :          */
     112             :         inline void getIniName(::rtl::OUString & iniName) const;
     113             : 
     114             :         /** Expands a macro using bootstrap variables.
     115             : 
     116             :             @param macro    [inout]  The macro to be expanded
     117             :         */
     118        3582 :         inline void expandMacrosFrom( ::rtl::OUString & macro ) const
     119        3582 :             { rtl_bootstrap_expandMacros_from_handle( _handle, &macro.pData ); }
     120             : 
     121             :         /** Expands a macro using default bootstrap variables.
     122             : 
     123             :             @param macro    [inout]  The macro to be expanded
     124             :         */
     125        9117 :         static inline void expandMacros( ::rtl::OUString & macro )
     126        9117 :             { rtl_bootstrap_expandMacros( &macro.pData ); }
     127             : 
     128             :         /** Provides the bootstrap internal handle.
     129             : 
     130             :             @return bootstrap handle
     131             :         */
     132      106927 :         inline rtlBootstrapHandle getHandle() const
     133      106927 :             { return _handle; }
     134             : 
     135             :         /** Escapes special characters ("$" and "\").
     136             : 
     137             :             @param value
     138             :             an arbitrary value
     139             : 
     140             :             @return
     141             :             the given value, with all occurrences of special characters ("$" and
     142             :             "\") escaped
     143             : 
     144             :             @since UDK 3.2.9
     145             :         */
     146             :         static inline ::rtl::OUString encode( ::rtl::OUString const & value );
     147             :     };
     148             : 
     149             : 
     150             :     // IMPLEMENTATION
     151             : 
     152           1 :     inline void Bootstrap::setIniFilename( const ::rtl::OUString &sFile )
     153             :     {
     154           1 :         rtl_bootstrap_setIniFileName( sFile.pData );
     155           1 :     }
     156             : 
     157        3125 :     inline bool Bootstrap::get( const ::rtl::OUString &sName,
     158             :                                     ::rtl::OUString & outValue )
     159             :     {
     160        3125 :         return rtl_bootstrap_get( sName.pData , &(outValue.pData) , 0 );
     161             :     }
     162             : 
     163         116 :     inline void Bootstrap::get( const ::rtl::OUString &sName,
     164             :                                 ::rtl::OUString & outValue,
     165             :                                 const ::rtl::OUString & sDefault )
     166             :     {
     167         116 :         rtl_bootstrap_get( sName.pData , &(outValue.pData) , sDefault.pData );
     168         116 :     }
     169             : 
     170        2747 :     inline void Bootstrap::set( ::rtl::OUString const & name, ::rtl::OUString const & value )
     171             :     {
     172        2747 :         rtl_bootstrap_set( name.pData, value.pData );
     173        2747 :     }
     174             : 
     175             :     inline Bootstrap::Bootstrap()
     176             :     {
     177             :         _handle = 0;
     178             :     }
     179             : 
     180       28293 :     inline Bootstrap::Bootstrap(const rtl::OUString & iniName)
     181             :     {
     182       28293 :         if(!iniName.isEmpty())
     183       28293 :             _handle = rtl_bootstrap_args_open(iniName.pData);
     184             : 
     185             :         else
     186           0 :             _handle = 0;
     187       28293 :     }
     188             : 
     189       28216 :     inline Bootstrap::~Bootstrap()
     190             :     {
     191       28216 :         rtl_bootstrap_args_close(_handle);
     192       28216 :     }
     193             : 
     194             : 
     195        3029 :     inline bool Bootstrap::getFrom(const ::rtl::OUString &sName,
     196             :                                        ::rtl::OUString &outValue) const
     197             :     {
     198        3029 :         return rtl_bootstrap_get_from_handle(_handle, sName.pData, &outValue.pData, 0);
     199             :     }
     200             : 
     201        3209 :     inline void Bootstrap::getFrom(const ::rtl::OUString &sName,
     202             :                                    ::rtl::OUString &outValue,
     203             :                                    const ::rtl::OUString &aDefault) const
     204             :     {
     205        3209 :         rtl_bootstrap_get_from_handle(_handle, sName.pData, &outValue.pData, aDefault.pData);
     206        3209 :     }
     207             : 
     208         326 :     inline void Bootstrap::getIniName(::rtl::OUString & iniName) const
     209             :     {
     210         326 :         rtl_bootstrap_get_iniName_from_handle(_handle, &iniName.pData);
     211         326 :     }
     212             : 
     213         127 :     inline ::rtl::OUString Bootstrap::encode( ::rtl::OUString const & value )
     214             :     {
     215         127 :         ::rtl::OUString encoded;
     216         127 :         rtl_bootstrap_encode(value.pData, &encoded.pData);
     217         127 :         return encoded;
     218             :     }
     219             : }
     220             : #endif
     221             : 
     222             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11