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 22 #include "sal/config.h" 23 24 #include <cstddef> 25 26 #include "rtl/ustring.hxx" 27 #include "rtl/bootstrap.h" 28 29 namespace rtl 30 { 31 class Bootstrap 32 { 33 void * _handle; 34 35 Bootstrap( Bootstrap const & ) SAL_DELETED_FUNCTION; 36 Bootstrap & operator = ( Bootstrap const & ) SAL_DELETED_FUNCTION; 37 38 public: 39 /** 40 * @see rtl_bootstrap_setIniFileName() 41 */ 42 static inline void SAL_CALL setIniFilename( const ::rtl::OUString &sFileUri ); 43 44 /** Retrieves a bootstrap parameter 45 @param sName name of the bootstrap value. case insensitive. 46 @param[out] outValue On success contains the value, otherwise 47 an empty string. 48 @return false, if no value could be retrieved, otherwise true 49 @see rtl_bootstrap_get() 50 */ 51 static inline bool get( 52 const ::rtl::OUString &sName, 53 ::rtl::OUString &outValue ); 54 55 /** Retrieves a bootstrap parameter 56 57 @param sName name of the bootstrap value. case insensitive. 58 @param[out] outValue Contains the value associated with <code>sName</code>. 59 @param aDefault if none of the other methods retrieved a value, 60 <code>outValue</code> is assigned to <code>aDefault</code>. 61 62 @see rtl_bootstrap_get() 63 */ 64 static inline void get( 65 const ::rtl::OUString &sName, 66 ::rtl::OUString &outValue, 67 const ::rtl::OUString &aDefault ); 68 69 /** Sets a bootstrap parameter. 70 71 @param name 72 name of bootstrap parameter 73 @param value 74 value of bootstrap parameter 75 76 @see rtl_bootstrap_set() 77 */ 78 static inline void set( ::rtl::OUString const & name, ::rtl::OUString const & value ); 79 80 /** default ctor. 81 */ 82 inline Bootstrap(); 83 84 /** Opens a bootstrap argument container 85 @see rtl_bootstrap_args_open() 86 */ 87 inline Bootstrap(const rtl::OUString & iniName); 88 89 /** Closes a bootstrap argument container 90 @see rtl_bootstrap_args_close() 91 */ 92 inline ~Bootstrap(); 93 94 /** Retrieves a bootstrap argument. 95 96 It is first tried to retrieve the value via the global function 97 and second via the special bootstrap container. 98 @see rtl_bootstrap_get_from_handle() 99 */ 100 101 inline bool getFrom(const ::rtl::OUString &sName, 102 ::rtl::OUString &outValue) const; 103 104 /** Retrieves a bootstrap argument. 105 106 It is first tried to retrieve the value via the global function 107 and second via the special bootstrap container. 108 @see rtl_bootstrap_get_from_handle() 109 */ 110 inline void getFrom(const ::rtl::OUString &sName, 111 ::rtl::OUString &outValue, 112 const ::rtl::OUString &aDefault) const; 113 114 /** Retrieves the name of the underlying ini-file. 115 @see rtl_bootstrap_get_iniName_from_handle() 116 */ 117 inline void getIniName(::rtl::OUString & iniName) const; 118 119 /** Expands a macro using bootstrap variables. 120 121 @param[in,out] macro The macro to be expanded 122 */ expandMacrosFrom(::rtl::OUString & macro) const123 void expandMacrosFrom( ::rtl::OUString & macro ) const 124 { rtl_bootstrap_expandMacros_from_handle( _handle, ¯o.pData ); } 125 126 /** Expands a macro using default bootstrap variables. 127 128 @param[in,out] macro The macro to be expanded 129 */ expandMacros(::rtl::OUString & macro)130 static void expandMacros( ::rtl::OUString & macro ) 131 { rtl_bootstrap_expandMacros( ¯o.pData ); } 132 133 /** Provides the bootstrap internal handle. 134 135 @return bootstrap handle 136 */ getHandle() const137 rtlBootstrapHandle getHandle() const 138 { return _handle; } 139 140 /** Escapes special characters ("$" and "\"). 141 142 @param value 143 an arbitrary value 144 145 @return 146 the given value, with all occurrences of special characters ("$" and 147 "\") escaped 148 149 @since UDK 3.2.9 150 */ 151 static inline ::rtl::OUString encode( ::rtl::OUString const & value ); 152 }; 153 154 155 // IMPLEMENTATION 156 setIniFilename(const::rtl::OUString & sFile)157 inline void Bootstrap::setIniFilename( const ::rtl::OUString &sFile ) 158 { 159 rtl_bootstrap_setIniFileName( sFile.pData ); 160 } 161 get(const::rtl::OUString & sName,::rtl::OUString & outValue)162 inline bool Bootstrap::get( const ::rtl::OUString &sName, 163 ::rtl::OUString & outValue ) 164 { 165 return rtl_bootstrap_get( sName.pData , &(outValue.pData) , NULL ); 166 } 167 get(const::rtl::OUString & sName,::rtl::OUString & outValue,const::rtl::OUString & sDefault)168 inline void Bootstrap::get( const ::rtl::OUString &sName, 169 ::rtl::OUString & outValue, 170 const ::rtl::OUString & sDefault ) 171 { 172 rtl_bootstrap_get( sName.pData , &(outValue.pData) , sDefault.pData ); 173 } 174 set(::rtl::OUString const & name,::rtl::OUString const & value)175 inline void Bootstrap::set( ::rtl::OUString const & name, ::rtl::OUString const & value ) 176 { 177 rtl_bootstrap_set( name.pData, value.pData ); 178 } 179 Bootstrap()180 inline Bootstrap::Bootstrap() 181 { 182 _handle = NULL; 183 } 184 Bootstrap(const rtl::OUString & iniName)185 inline Bootstrap::Bootstrap(const rtl::OUString & iniName) 186 { 187 if(!iniName.isEmpty()) 188 _handle = rtl_bootstrap_args_open(iniName.pData); 189 190 else 191 _handle = NULL; 192 } 193 ~Bootstrap()194 inline Bootstrap::~Bootstrap() 195 { 196 rtl_bootstrap_args_close(_handle); 197 } 198 199 getFrom(const::rtl::OUString & sName,::rtl::OUString & outValue) const200 inline bool Bootstrap::getFrom(const ::rtl::OUString &sName, 201 ::rtl::OUString &outValue) const 202 { 203 return rtl_bootstrap_get_from_handle(_handle, sName.pData, &outValue.pData, NULL); 204 } 205 getFrom(const::rtl::OUString & sName,::rtl::OUString & outValue,const::rtl::OUString & aDefault) const206 inline void Bootstrap::getFrom(const ::rtl::OUString &sName, 207 ::rtl::OUString &outValue, 208 const ::rtl::OUString &aDefault) const 209 { 210 rtl_bootstrap_get_from_handle(_handle, sName.pData, &outValue.pData, aDefault.pData); 211 } 212 getIniName(::rtl::OUString & iniName) const213 inline void Bootstrap::getIniName(::rtl::OUString & iniName) const 214 { 215 rtl_bootstrap_get_iniName_from_handle(_handle, &iniName.pData); 216 } 217 encode(::rtl::OUString const & value)218 inline ::rtl::OUString Bootstrap::encode( ::rtl::OUString const & value ) 219 { 220 ::rtl::OUString encoded; 221 rtl_bootstrap_encode(value.pData, &encoded.pData); 222 return encoded; 223 } 224 } 225 #endif 226 227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 228