Update ooo320-m1
[ooovba.git] / sal / inc / rtl / bootstrap.hxx
blob5fd85ba9a091b4940cdef5968622fc6d82404572
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bootstrap.hxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _RTL_BOOTSTRAP_HXX_
31 #define _RTL_BOOTSTRAP_HXX_
32 #include <rtl/ustring.hxx>
33 #include <rtl/bootstrap.h>
35 namespace rtl
37 class Bootstrap
39 void * _handle;
41 /** @internal */
42 inline Bootstrap( Bootstrap const & ); // not impl
43 /** @internal */
44 inline Bootstrap & operator = ( Bootstrap const & ); // not impl
46 public:
47 /**
48 @see rtl_bootstrap_setIniFileName()
50 static inline void SAL_CALL setIniFilename( const ::rtl::OUString &sFile );
52 /** Retrieves a bootstrap parameter
53 @param sName name of the bootstrap value. case insensitive.
54 @param outValue (out parameter). On success contains the value, otherwise
55 an empty string.
56 @return sal_False, if no value could be retrieved, otherwise sal_True
57 @see rtl_bootstrap_get()
59 static inline sal_Bool get(
60 const ::rtl::OUString &sName,
61 ::rtl::OUString &outValue );
63 /** Retrieves a bootstrap parameter
65 @param sName name of the bootstrap value. case insensitive.
66 @param outValue (out parameter). Contains the value associated with sName.
67 @param aDefault if none of the other methods retrieved a value, outValue
68 is assigned to a Default.
70 @see rtl_bootstrap_get()
72 static inline void get(
73 const ::rtl::OUString &sName,
74 ::rtl::OUString &outValue,
75 const ::rtl::OUString &aDefault );
77 /** Sets a bootstrap parameter.
79 @param pName
80 name of bootstrap parameter
81 @param pValue
82 value of bootstrap parameter
84 @see rtl_bootstrap_set()
86 static inline void set( ::rtl::OUString const & name, ::rtl::OUString const & value )
87 SAL_THROW( () );
89 /** default ctor.
91 inline Bootstrap();
93 /** Opens a bootstrap argment container
94 @see rtl_bootstrap_args_open()
96 inline Bootstrap(const OUString & iniName);
98 /** Closes a bootstrap argument container
99 @see rtl_bootstrap_args_close()
101 inline ~Bootstrap();
103 /** Retrieves a bootstrap argument.
105 It is first tried to retrieve the value via the global function
106 and second via the special bootstrap container.
107 @see rtl_bootstrap_get_from_handle()
110 inline sal_Bool getFrom(const ::rtl::OUString &sName,
111 ::rtl::OUString &outValue) const;
113 /** Retrieves a bootstrap argument.
115 It is first tried to retrieve the value via the global function
116 and second via the special bootstrap container.
117 @see rtl_bootstrap_get_from_handle()
119 inline void getFrom(const ::rtl::OUString &sName,
120 ::rtl::OUString &outValue,
121 const ::rtl::OUString &aDefault) const;
123 /** Retrieves the name of the underlying ini-file.
124 @see rtl_bootstrap_get_iniName_from_handle()
126 inline void getIniName(::rtl::OUString & iniName) const;
128 /** Expands a macro using bootstrap variables.
130 @param macro [inout] The macro to be expanded
132 inline void expandMacrosFrom( ::rtl::OUString & macro ) const SAL_THROW( () )
133 { rtl_bootstrap_expandMacros_from_handle( _handle, &macro.pData ); }
135 /** Expands a macro using default bootstrap variables.
137 @param macro [inout] The macro to be expanded
139 static inline void expandMacros( ::rtl::OUString & macro ) SAL_THROW( () )
140 { rtl_bootstrap_expandMacros( &macro.pData ); }
142 /** Provides the bootstrap internal handle.
144 @return bootstrap handle
146 inline rtlBootstrapHandle getHandle() const SAL_THROW( () )
147 { return _handle; }
149 /** Escapes special characters ("$" and "\").
151 @param value
152 an arbitrary value
154 @return
155 the given value, with all occurences of special characters ("$" and
156 "\") escaped
158 @since UDK 3.2.9
160 static inline ::rtl::OUString encode( ::rtl::OUString const & value )
161 SAL_THROW( () );
164 //----------------------------------------------------------------------------
165 // IMPLEMENTATION
166 //----------------------------------------------------------------------------
167 inline void Bootstrap::setIniFilename( const ::rtl::OUString &sFile )
169 rtl_bootstrap_setIniFileName( sFile.pData );
172 inline sal_Bool Bootstrap::get( const ::rtl::OUString &sName,
173 ::rtl::OUString & outValue )
175 return rtl_bootstrap_get( sName.pData , &(outValue.pData) , 0 );
178 inline void Bootstrap::get( const ::rtl::OUString &sName,
179 ::rtl::OUString & outValue,
180 const ::rtl::OUString & sDefault )
182 rtl_bootstrap_get( sName.pData , &(outValue.pData) , sDefault.pData );
185 inline void Bootstrap::set( ::rtl::OUString const & name, ::rtl::OUString const & value )
186 SAL_THROW( () )
188 rtl_bootstrap_set( name.pData, value.pData );
191 inline Bootstrap::Bootstrap()
193 _handle = 0;
196 inline Bootstrap::Bootstrap(const OUString & iniName)
198 if(iniName.getLength())
199 _handle = rtl_bootstrap_args_open(iniName.pData);
201 else
202 _handle = 0;
205 inline Bootstrap::~Bootstrap()
207 rtl_bootstrap_args_close(_handle);
211 inline sal_Bool Bootstrap::getFrom(const ::rtl::OUString &sName,
212 ::rtl::OUString &outValue) const
214 return rtl_bootstrap_get_from_handle(_handle, sName.pData, &outValue.pData, 0);
217 inline void Bootstrap::getFrom(const ::rtl::OUString &sName,
218 ::rtl::OUString &outValue,
219 const ::rtl::OUString &aDefault) const
221 rtl_bootstrap_get_from_handle(_handle, sName.pData, &outValue.pData, aDefault.pData);
224 inline void Bootstrap::getIniName(::rtl::OUString & iniName) const
226 rtl_bootstrap_get_iniName_from_handle(_handle, &iniName.pData);
229 inline ::rtl::OUString Bootstrap::encode( ::rtl::OUString const & value )
230 SAL_THROW( () )
232 ::rtl::OUString encoded;
233 rtl_bootstrap_encode(value.pData, &encoded.pData);
234 return encoded;
237 #endif