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