LCOV - code coverage report
Current view: top level - include/rtl - bootstrap.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 21 40 52.5 %
Date: 2014-04-14 Functions: 8 14 57.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             :  * 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             :         inline Bootstrap( Bootstrap const & ); // not impl
      31             :         inline Bootstrap & operator = ( Bootstrap const & ); // not impl
      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             :             SAL_THROW(());
      75             : 
      76             :         /** default ctor.
      77             :          */
      78             :         inline Bootstrap();
      79             : 
      80             :         /** Opens a bootstrap argment container
      81             :             @see rtl_bootstrap_args_open()
      82             :          */
      83             :         inline Bootstrap(const rtl::OUString & iniName);
      84             : 
      85             :         /** Closes a bootstrap argument container
      86             :             @see rtl_bootstrap_args_close()
      87             :         */
      88             :         inline ~Bootstrap();
      89             : 
      90             :         /** Retrieves a bootstrap argument.
      91             : 
      92             :             It is first tried to retrieve the value via the global function
      93             :             and second via the special bootstrap container.
      94             :             @see rtl_bootstrap_get_from_handle()
      95             :         */
      96             : 
      97             :         inline bool getFrom(const ::rtl::OUString &sName,
      98             :                                 ::rtl::OUString &outValue) const;
      99             : 
     100             :         /** Retrieves a bootstrap argument.
     101             : 
     102             :             It is first tried to retrieve the value via the global function
     103             :             and second via the special bootstrap container.
     104             :             @see rtl_bootstrap_get_from_handle()
     105             :         */
     106             :         inline void getFrom(const ::rtl::OUString &sName,
     107             :                             ::rtl::OUString &outValue,
     108             :                             const ::rtl::OUString &aDefault) const;
     109             : 
     110             :         /** Retrieves the name of the underlying ini-file.
     111             :             @see rtl_bootstrap_get_iniName_from_handle()
     112             :          */
     113             :         inline void getIniName(::rtl::OUString & iniName) const;
     114             : 
     115             :         /** Expands a macro using bootstrap variables.
     116             : 
     117             :             @param macro    [inout]  The macro to be expanded
     118             :         */
     119           0 :         inline void expandMacrosFrom( ::rtl::OUString & macro ) const SAL_THROW(())
     120           0 :             { rtl_bootstrap_expandMacros_from_handle( _handle, &macro.pData ); }
     121             : 
     122             :         /** Expands a macro using default bootstrap variables.
     123             : 
     124             :             @param macro    [inout]  The macro to be expanded
     125             :         */
     126           9 :         static inline void expandMacros( ::rtl::OUString & macro ) SAL_THROW(())
     127           9 :             { rtl_bootstrap_expandMacros( &macro.pData ); }
     128             : 
     129             :         /** Provides the bootstrap internal handle.
     130             : 
     131             :             @return bootstrap handle
     132             :         */
     133      297578 :         inline rtlBootstrapHandle getHandle() const SAL_THROW(())
     134      297578 :             { return _handle; }
     135             : 
     136             :         /** Escapes special characters ("$" and "\").
     137             : 
     138             :             @param value
     139             :             an arbitrary value
     140             : 
     141             :             @return
     142             :             the given value, with all occurrences of special characters ("$" and
     143             :             "\") escaped
     144             : 
     145             :             @since UDK 3.2.9
     146             :         */
     147             :         static inline ::rtl::OUString encode( ::rtl::OUString const & value )
     148             :             SAL_THROW(());
     149             :     };
     150             : 
     151             : 
     152             :     // IMPLEMENTATION
     153             : 
     154           0 :     inline void Bootstrap::setIniFilename( const ::rtl::OUString &sFile )
     155             :     {
     156           0 :         rtl_bootstrap_setIniFileName( sFile.pData );
     157           0 :     }
     158             : 
     159           4 :     inline bool Bootstrap::get( const ::rtl::OUString &sName,
     160             :                                     ::rtl::OUString & outValue )
     161             :     {
     162           4 :         return rtl_bootstrap_get( sName.pData , &(outValue.pData) , 0 );
     163             :     }
     164             : 
     165           0 :     inline void Bootstrap::get( const ::rtl::OUString &sName,
     166             :                                 ::rtl::OUString & outValue,
     167             :                                 const ::rtl::OUString & sDefault )
     168             :     {
     169           0 :         rtl_bootstrap_get( sName.pData , &(outValue.pData) , sDefault.pData );
     170           0 :     }
     171             : 
     172           0 :     inline void Bootstrap::set( ::rtl::OUString const & name, ::rtl::OUString const & value )
     173             :         SAL_THROW(())
     174             :     {
     175           0 :         rtl_bootstrap_set( name.pData, value.pData );
     176           0 :     }
     177             : 
     178           0 :     inline Bootstrap::Bootstrap()
     179             :     {
     180           0 :         _handle = 0;
     181           0 :     }
     182             : 
     183      297572 :     inline Bootstrap::Bootstrap(const rtl::OUString & iniName)
     184             :     {
     185      297572 :         if(!iniName.isEmpty())
     186      297572 :             _handle = rtl_bootstrap_args_open(iniName.pData);
     187             : 
     188             :         else
     189           0 :             _handle = 0;
     190      297572 :     }
     191             : 
     192      255067 :     inline Bootstrap::~Bootstrap()
     193             :     {
     194      255067 :         rtl_bootstrap_args_close(_handle);
     195      255067 :     }
     196             : 
     197             : 
     198      637587 :     inline bool Bootstrap::getFrom(const ::rtl::OUString &sName,
     199             :                                        ::rtl::OUString &outValue) const
     200             :     {
     201      637587 :         return rtl_bootstrap_get_from_handle(_handle, sName.pData, &outValue.pData, 0);
     202             :     }
     203             : 
     204           2 :     inline void Bootstrap::getFrom(const ::rtl::OUString &sName,
     205             :                                    ::rtl::OUString &outValue,
     206             :                                    const ::rtl::OUString &aDefault) const
     207             :     {
     208           2 :         rtl_bootstrap_get_from_handle(_handle, sName.pData, &outValue.pData, aDefault.pData);
     209           2 :     }
     210             : 
     211           1 :     inline void Bootstrap::getIniName(::rtl::OUString & iniName) const
     212             :     {
     213           1 :         rtl_bootstrap_get_iniName_from_handle(_handle, &iniName.pData);
     214           1 :     }
     215             : 
     216           0 :     inline ::rtl::OUString Bootstrap::encode( ::rtl::OUString const & value )
     217             :         SAL_THROW(())
     218             :     {
     219           0 :         ::rtl::OUString encoded;
     220           0 :         rtl_bootstrap_encode(value.pData, &encoded.pData);
     221           0 :         return encoded;
     222             :     }
     223             : }
     224             : #endif
     225             : 
     226             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10