xref: /AOO41X/main/sal/inc/rtl/bootstrap.hxx (revision 565d668c30d8a6cacc881c774c5068be5401257d)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _RTL_BOOTSTRAP_HXX_
24 #define _RTL_BOOTSTRAP_HXX_
25 #include <rtl/ustring.hxx>
26 #include <rtl/bootstrap.h>
27 
28 namespace rtl
29 {
30     class Bootstrap
31     {
32         void * _handle;
33 
34         /** @internal */
35         inline Bootstrap( Bootstrap const & ); // not impl
36         /** @internal */
37         inline Bootstrap & operator = ( Bootstrap const & ); // not impl
38 
39     public:
40         /**
41            @see rtl_bootstrap_setIniFileName()
42          */
43         static inline void SAL_CALL setIniFilename( const ::rtl::OUString &sFile );
44 
45         /** Retrieves a bootstrap parameter
46            @param sName name of the bootstrap value. case insensitive.
47            @param outValue (out parameter). On success contains the value, otherwise
48                   an empty string.
49            @return sal_False, if no value could be retrieved, otherwise sal_True
50            @see rtl_bootstrap_get()
51          */
52         static inline sal_Bool get(
53             const ::rtl::OUString &sName,
54             ::rtl::OUString &outValue );
55 
56         /** Retrieves a bootstrap parameter
57 
58            @param sName name of the bootstrap value. case insensitive.
59            @param outValue (out parameter). Contains the value associated with sName.
60            @param aDefault if none of the other methods retrieved a value, outValue
61                            is assigned to a Default.
62 
63            @see rtl_bootstrap_get()
64          */
65         static inline void get(
66             const ::rtl::OUString &sName,
67             ::rtl::OUString &outValue,
68             const ::rtl::OUString &aDefault );
69 
70         /** Sets a bootstrap parameter.
71 
72             @param pName
73                    name of bootstrap parameter
74             @param pValue
75                    value of bootstrap parameter
76 
77             @see rtl_bootstrap_set()
78         */
79         static inline void set( ::rtl::OUString const & name, ::rtl::OUString const & value )
80             SAL_THROW( () );
81 
82         /** default ctor.
83          */
84         inline Bootstrap();
85 
86         /** Opens a bootstrap argment container
87             @see rtl_bootstrap_args_open()
88          */
89         inline Bootstrap(const OUString & iniName);
90 
91         /** Closes a bootstrap argument container
92             @see rtl_bootstrap_args_close()
93         */
94         inline ~Bootstrap();
95 
96         /** Retrieves a bootstrap argument.
97 
98             It is first tried to retrieve the value via the global function
99             and second via the special bootstrap container.
100             @see rtl_bootstrap_get_from_handle()
101         */
102 
103         inline sal_Bool getFrom(const ::rtl::OUString &sName,
104                                 ::rtl::OUString &outValue) const;
105 
106         /** Retrieves a bootstrap argument.
107 
108             It is first tried to retrieve the value via the global function
109             and second via the special bootstrap container.
110             @see rtl_bootstrap_get_from_handle()
111         */
112         inline void getFrom(const ::rtl::OUString &sName,
113                             ::rtl::OUString &outValue,
114                             const ::rtl::OUString &aDefault) const;
115 
116         /** Retrieves the name of the underlying ini-file.
117             @see rtl_bootstrap_get_iniName_from_handle()
118          */
119         inline void getIniName(::rtl::OUString & iniName) const;
120 
121         /** Expands a macro using bootstrap variables.
122 
123             @param macro    [inout]  The macro to be expanded
124         */
expandMacrosFrom(::rtl::OUString & macro) const125         inline void expandMacrosFrom( ::rtl::OUString & macro ) const SAL_THROW( () )
126             { rtl_bootstrap_expandMacros_from_handle( _handle, &macro.pData ); }
127 
128         /** Expands a macro using default bootstrap variables.
129 
130             @param macro    [inout]  The macro to be expanded
131         */
expandMacros(::rtl::OUString & macro)132         static inline void expandMacros( ::rtl::OUString & macro ) SAL_THROW( () )
133             { rtl_bootstrap_expandMacros( &macro.pData ); }
134 
135         /** Provides the bootstrap internal handle.
136 
137             @return bootstrap handle
138         */
getHandle() const139         inline rtlBootstrapHandle getHandle() const SAL_THROW( () )
140             { return _handle; }
141 
142         /** Escapes special characters ("$" and "\").
143 
144             @param value
145             an arbitrary value
146 
147             @return
148             the given value, with all occurences of special characters ("$" and
149             "\") escaped
150 
151             @since UDK 3.2.9
152         */
153         static inline ::rtl::OUString encode( ::rtl::OUString const & value )
154             SAL_THROW( () );
155     };
156 
157     //----------------------------------------------------------------------------
158     // IMPLEMENTATION
159     //----------------------------------------------------------------------------
setIniFilename(const::rtl::OUString & sFile)160     inline void Bootstrap::setIniFilename( const ::rtl::OUString &sFile )
161     {
162         rtl_bootstrap_setIniFileName( sFile.pData );
163     }
164 
get(const::rtl::OUString & sName,::rtl::OUString & outValue)165     inline sal_Bool Bootstrap::get( const ::rtl::OUString &sName,
166                                     ::rtl::OUString & outValue )
167     {
168         return rtl_bootstrap_get( sName.pData , &(outValue.pData) , 0 );
169     }
170 
get(const::rtl::OUString & sName,::rtl::OUString & outValue,const::rtl::OUString & sDefault)171     inline void Bootstrap::get( const ::rtl::OUString &sName,
172                                 ::rtl::OUString & outValue,
173                                 const ::rtl::OUString & sDefault )
174     {
175         rtl_bootstrap_get( sName.pData , &(outValue.pData) , sDefault.pData );
176     }
177 
set(::rtl::OUString const & name,::rtl::OUString const & value)178     inline void Bootstrap::set( ::rtl::OUString const & name, ::rtl::OUString const & value )
179         SAL_THROW( () )
180     {
181         rtl_bootstrap_set( name.pData, value.pData );
182     }
183 
Bootstrap()184     inline Bootstrap::Bootstrap()
185     {
186         _handle = 0;
187     }
188 
Bootstrap(const OUString & iniName)189     inline Bootstrap::Bootstrap(const OUString & iniName)
190     {
191         if(iniName.getLength())
192             _handle = rtl_bootstrap_args_open(iniName.pData);
193 
194         else
195             _handle = 0;
196     }
197 
~Bootstrap()198     inline Bootstrap::~Bootstrap()
199     {
200         rtl_bootstrap_args_close(_handle);
201     }
202 
203 
getFrom(const::rtl::OUString & sName,::rtl::OUString & outValue) const204     inline sal_Bool Bootstrap::getFrom(const ::rtl::OUString &sName,
205                                        ::rtl::OUString &outValue) const
206     {
207         return rtl_bootstrap_get_from_handle(_handle, sName.pData, &outValue.pData, 0);
208     }
209 
getFrom(const::rtl::OUString & sName,::rtl::OUString & outValue,const::rtl::OUString & aDefault) const210     inline void Bootstrap::getFrom(const ::rtl::OUString &sName,
211                                    ::rtl::OUString &outValue,
212                                    const ::rtl::OUString &aDefault) const
213     {
214         rtl_bootstrap_get_from_handle(_handle, sName.pData, &outValue.pData, aDefault.pData);
215     }
216 
getIniName(::rtl::OUString & iniName) const217     inline void Bootstrap::getIniName(::rtl::OUString & iniName) const
218     {
219         rtl_bootstrap_get_iniName_from_handle(_handle, &iniName.pData);
220     }
221 
encode(::rtl::OUString const & value)222     inline ::rtl::OUString Bootstrap::encode( ::rtl::OUString const & value )
223         SAL_THROW( () )
224     {
225         ::rtl::OUString encoded;
226         rtl_bootstrap_encode(value.pData, &encoded.pData);
227         return encoded;
228     }
229 }
230 #endif
231