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