xref: /aoo42x/main/sal/inc/rtl/bootstrap.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _RTL_BOOTSTRAP_HXX_
28 #define _RTL_BOOTSTRAP_HXX_
29 #include <rtl/ustring.hxx>
30 #include <rtl/bootstrap.h>
31 
32 namespace rtl
33 {
34 	class Bootstrap
35 	{
36 		void * _handle;
37 
38         /** @internal */
39         inline Bootstrap( Bootstrap const & ); // not impl
40         /** @internal */
41         inline Bootstrap & operator = ( Bootstrap const & ); // not impl
42 
43 	public:
44 		/**
45 		   @see rtl_bootstrap_setIniFileName()
46 		 */
47 		static inline void SAL_CALL setIniFilename( const ::rtl::OUString &sFile );
48 
49 		/** Retrieves a bootstrap parameter
50 		   @param sName name of the bootstrap value. case insensitive.
51 		   @param outValue (out parameter). On success contains the value, otherwise
52 		          an empty string.
53 		   @return sal_False, if no value could be retrieved, otherwise sal_True
54 		   @see rtl_bootstrap_get()
55 		 */
56 		static inline sal_Bool get(
57 			const ::rtl::OUString &sName,
58 			::rtl::OUString &outValue );
59 
60 		/** Retrieves a bootstrap parameter
61 
62 		   @param sName name of the bootstrap value. case insensitive.
63 		   @param outValue (out parameter). Contains the value associated with sName.
64 		   @param aDefault if none of the other methods retrieved a value, outValue
65 		                   is assigned to a Default.
66 
67 		   @see rtl_bootstrap_get()
68 		 */
69 		static inline void get(
70 			const ::rtl::OUString &sName,
71 			::rtl::OUString &outValue,
72 			const ::rtl::OUString &aDefault );
73 
74         /** Sets a bootstrap parameter.
75 
76             @param pName
77                    name of bootstrap parameter
78             @param pValue
79                    value of bootstrap parameter
80 
81             @see rtl_bootstrap_set()
82         */
83         static inline void set( ::rtl::OUString const & name, ::rtl::OUString const & value )
84             SAL_THROW( () );
85 
86         /** default ctor.
87          */
88 		inline Bootstrap();
89 
90 		/** Opens a bootstrap argment container
91 			@see rtl_bootstrap_args_open()
92 		 */
93 		inline Bootstrap(const OUString & iniName);
94 
95 		/** Closes a bootstrap argument container
96 			@see rtl_bootstrap_args_close()
97 		*/
98 		inline ~Bootstrap();
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 
107 		inline sal_Bool getFrom(const ::rtl::OUString &sName,
108 								::rtl::OUString &outValue) const;
109 
110 		/** Retrieves a bootstrap argument.
111 
112 		    It is first tried to retrieve the value via the global function
113 			and second via the special bootstrap container.
114 			@see rtl_bootstrap_get_from_handle()
115 		*/
116 		inline void getFrom(const ::rtl::OUString &sName,
117 							::rtl::OUString &outValue,
118 							const ::rtl::OUString &aDefault) const;
119 
120 		/** Retrieves the name of the underlying ini-file.
121 			@see rtl_bootstrap_get_iniName_from_handle()
122 		 */
123 		inline void getIniName(::rtl::OUString & iniName) const;
124 
125         /** Expands a macro using bootstrap variables.
126 
127             @param macro    [inout]  The macro to be expanded
128         */
129         inline void expandMacrosFrom( ::rtl::OUString & macro ) const SAL_THROW( () )
130             { rtl_bootstrap_expandMacros_from_handle( _handle, &macro.pData ); }
131 
132         /** Expands a macro using default bootstrap variables.
133 
134             @param macro    [inout]  The macro to be expanded
135         */
136         static inline void expandMacros( ::rtl::OUString & macro ) SAL_THROW( () )
137             { rtl_bootstrap_expandMacros( &macro.pData ); }
138 
139         /** Provides the bootstrap internal handle.
140 
141             @return bootstrap handle
142         */
143         inline rtlBootstrapHandle getHandle() const SAL_THROW( () )
144             { return _handle; }
145 
146         /** Escapes special characters ("$" and "\").
147 
148             @param value
149             an arbitrary value
150 
151             @return
152             the given value, with all occurences of special characters ("$" and
153             "\") escaped
154 
155             @since UDK 3.2.9
156         */
157         static inline ::rtl::OUString encode( ::rtl::OUString const & value )
158             SAL_THROW( () );
159 	};
160 
161 	//----------------------------------------------------------------------------
162 	// IMPLEMENTATION
163 	//----------------------------------------------------------------------------
164 	inline void Bootstrap::setIniFilename( const ::rtl::OUString &sFile )
165 	{
166 		rtl_bootstrap_setIniFileName( sFile.pData );
167 	}
168 
169 	inline sal_Bool Bootstrap::get( const ::rtl::OUString &sName,
170 									::rtl::OUString & outValue )
171 	{
172 		return rtl_bootstrap_get( sName.pData , &(outValue.pData) , 0 );
173 	}
174 
175 	inline void Bootstrap::get( const ::rtl::OUString &sName,
176 								::rtl::OUString & outValue,
177 								const ::rtl::OUString & sDefault )
178 	{
179 		rtl_bootstrap_get( sName.pData , &(outValue.pData) , sDefault.pData );
180 	}
181 
182     inline void Bootstrap::set( ::rtl::OUString const & name, ::rtl::OUString const & value )
183         SAL_THROW( () )
184     {
185         rtl_bootstrap_set( name.pData, value.pData );
186     }
187 
188 	inline Bootstrap::Bootstrap()
189 	{
190 		_handle = 0;
191 	}
192 
193 	inline Bootstrap::Bootstrap(const OUString & iniName)
194 	{
195 		if(iniName.getLength())
196 			_handle = rtl_bootstrap_args_open(iniName.pData);
197 
198 		else
199 			_handle = 0;
200 	}
201 
202 	inline Bootstrap::~Bootstrap()
203 	{
204 		rtl_bootstrap_args_close(_handle);
205 	}
206 
207 
208 	inline sal_Bool Bootstrap::getFrom(const ::rtl::OUString &sName,
209 									   ::rtl::OUString &outValue) const
210 	{
211 		return rtl_bootstrap_get_from_handle(_handle, sName.pData, &outValue.pData, 0);
212 	}
213 
214 	inline void Bootstrap::getFrom(const ::rtl::OUString &sName,
215 								   ::rtl::OUString &outValue,
216 								   const ::rtl::OUString &aDefault) const
217 	{
218 		rtl_bootstrap_get_from_handle(_handle, sName.pData, &outValue.pData, aDefault.pData);
219 	}
220 
221 	inline void Bootstrap::getIniName(::rtl::OUString & iniName) const
222 	{
223 		rtl_bootstrap_get_iniName_from_handle(_handle, &iniName.pData);
224 	}
225 
226     inline ::rtl::OUString Bootstrap::encode( ::rtl::OUString const & value )
227         SAL_THROW( () )
228     {
229         ::rtl::OUString encoded;
230         rtl_bootstrap_encode(value.pData, &encoded.pData);
231         return encoded;
232     }
233 }
234 #endif
235