bump product version to 4.2.0.1
[LibreOffice.git] / include / rtl / bootstrap.hxx
blob5ec0107910299040dcdcf2a66da67808e147442b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_RTL_BOOTSTRAP_HXX
20 #define INCLUDED_RTL_BOOTSTRAP_HXX
21 #include <rtl/ustring.hxx>
22 #include <rtl/bootstrap.h>
24 namespace rtl
26 class Bootstrap
28 void * _handle;
30 inline Bootstrap( Bootstrap const & ); // not impl
31 inline Bootstrap & operator = ( Bootstrap const & ); // not impl
33 public:
34 /**
35 * @see rtl_bootstrap_setIniFileName()
37 static inline void SAL_CALL setIniFilename( const ::rtl::OUString &sFileUri );
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 sal_False, if no value could be retrieved, otherwise sal_True
44 @see rtl_bootstrap_get()
46 static inline sal_Bool get(
47 const ::rtl::OUString &sName,
48 ::rtl::OUString &outValue );
50 /** Retrieves a bootstrap parameter
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.
57 @see rtl_bootstrap_get()
59 static inline void get(
60 const ::rtl::OUString &sName,
61 ::rtl::OUString &outValue,
62 const ::rtl::OUString &aDefault );
64 /** Sets a bootstrap parameter.
66 @param name
67 name of bootstrap parameter
68 @param value
69 value of bootstrap parameter
71 @see rtl_bootstrap_set()
73 static inline void set( ::rtl::OUString const & name, ::rtl::OUString const & value )
74 SAL_THROW(());
76 /** default ctor.
78 inline Bootstrap();
80 /** Opens a bootstrap argment container
81 @see rtl_bootstrap_args_open()
83 inline Bootstrap(const OUString & iniName);
85 /** Closes a bootstrap argument container
86 @see rtl_bootstrap_args_close()
88 inline ~Bootstrap();
90 /** Retrieves a bootstrap argument.
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()
97 inline sal_Bool getFrom(const ::rtl::OUString &sName,
98 ::rtl::OUString &outValue) const;
100 /** Retrieves a bootstrap argument.
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()
106 inline void getFrom(const ::rtl::OUString &sName,
107 ::rtl::OUString &outValue,
108 const ::rtl::OUString &aDefault) const;
110 /** Retrieves the name of the underlying ini-file.
111 @see rtl_bootstrap_get_iniName_from_handle()
113 inline void getIniName(::rtl::OUString & iniName) const;
115 /** Expands a macro using bootstrap variables.
117 @param macro [inout] The macro to be expanded
119 inline void expandMacrosFrom( ::rtl::OUString & macro ) const SAL_THROW(())
120 { rtl_bootstrap_expandMacros_from_handle( _handle, &macro.pData ); }
122 /** Expands a macro using default bootstrap variables.
124 @param macro [inout] The macro to be expanded
126 static inline void expandMacros( ::rtl::OUString & macro ) SAL_THROW(())
127 { rtl_bootstrap_expandMacros( &macro.pData ); }
129 /** Provides the bootstrap internal handle.
131 @return bootstrap handle
133 inline rtlBootstrapHandle getHandle() const SAL_THROW(())
134 { return _handle; }
136 /** Escapes special characters ("$" and "\").
138 @param value
139 an arbitrary value
141 @return
142 the given value, with all occurrences of special characters ("$" and
143 "\") escaped
145 @since UDK 3.2.9
147 static inline ::rtl::OUString encode( ::rtl::OUString const & value )
148 SAL_THROW(());
151 //----------------------------------------------------------------------------
152 // IMPLEMENTATION
153 //----------------------------------------------------------------------------
154 inline void Bootstrap::setIniFilename( const ::rtl::OUString &sFile )
156 rtl_bootstrap_setIniFileName( sFile.pData );
159 inline sal_Bool Bootstrap::get( const ::rtl::OUString &sName,
160 ::rtl::OUString & outValue )
162 return rtl_bootstrap_get( sName.pData , &(outValue.pData) , 0 );
165 inline void Bootstrap::get( const ::rtl::OUString &sName,
166 ::rtl::OUString & outValue,
167 const ::rtl::OUString & sDefault )
169 rtl_bootstrap_get( sName.pData , &(outValue.pData) , sDefault.pData );
172 inline void Bootstrap::set( ::rtl::OUString const & name, ::rtl::OUString const & value )
173 SAL_THROW(())
175 rtl_bootstrap_set( name.pData, value.pData );
178 inline Bootstrap::Bootstrap()
180 _handle = 0;
183 inline Bootstrap::Bootstrap(const OUString & iniName)
185 if(!iniName.isEmpty())
186 _handle = rtl_bootstrap_args_open(iniName.pData);
188 else
189 _handle = 0;
192 inline Bootstrap::~Bootstrap()
194 rtl_bootstrap_args_close(_handle);
198 inline sal_Bool Bootstrap::getFrom(const ::rtl::OUString &sName,
199 ::rtl::OUString &outValue) const
201 return rtl_bootstrap_get_from_handle(_handle, sName.pData, &outValue.pData, 0);
204 inline void Bootstrap::getFrom(const ::rtl::OUString &sName,
205 ::rtl::OUString &outValue,
206 const ::rtl::OUString &aDefault) const
208 rtl_bootstrap_get_from_handle(_handle, sName.pData, &outValue.pData, aDefault.pData);
211 inline void Bootstrap::getIniName(::rtl::OUString & iniName) const
213 rtl_bootstrap_get_iniName_from_handle(_handle, &iniName.pData);
216 inline ::rtl::OUString Bootstrap::encode( ::rtl::OUString const & value )
217 SAL_THROW(())
219 ::rtl::OUString encoded;
220 rtl_bootstrap_encode(value.pData, &encoded.pData);
221 return encoded;
224 #endif
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */