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