Update ooo320-m1
[ooovba.git] / sal / inc / osl / profile.hxx
blob8032a5d467866ea64ff187a0ad3bab87a04fc540
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: profile.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 ************************************************************************/
31 #ifndef _OSL_PROFILE_HXX_
32 #define _OSL_PROFILE_HXX_
34 #include "profile.h"
35 #include <rtl/ustring.hxx>
36 #include <string.h>
37 #include <list>
39 namespace osl {
41 typedef oslProfileOption ProfileOption;
43 const int Profile_DEFAULT = osl_Profile_DEFAULT;
44 const int Profile_SYSTEM = osl_Profile_SYSTEM; /* use system depended functinality */
45 const int Profile_READLOCK = osl_Profile_READLOCK; /* lock file for reading */
46 const int Profile_WRITELOCK = osl_Profile_WRITELOCK; /* lock file for writing */
48 /** Deprecated API.
49 @deprecated
51 class Profile {
52 oslProfile profile;
54 public:
55 /** Open or create a configuration profile.
56 @return 0 if the profile could not be created, otherwise a handle to the profile.
58 Profile(const rtl::OUString strProfileName, oslProfileOption Options = Profile_DEFAULT )
60 profile = osl_openProfile(strProfileName.pData, Options);
61 if( ! profile )
62 throw std::exception();
66 /** Close the opened profile an flush all data to the disk.
67 @param Profile handle to a opened profile.
69 ~Profile()
71 osl_closeProfile(profile);
75 sal_Bool flush()
77 return osl_flushProfile(profile);
80 rtl::OString readString( const rtl::OString& rSection, const rtl::OString& rEntry,
81 const rtl::OString& rDefault)
83 sal_Char aBuf[1024];
84 return osl_readProfileString( profile,
85 rSection,
86 rEntry,
87 aBuf,
88 sizeof( aBuf ),
89 rDefault ) ? rtl::OString( aBuf ) : rtl::OString();
93 sal_Bool readBool( const rtl::OString& rSection, const rtl::OString& rEntry, sal_Bool bDefault )
95 return osl_readProfileBool( profile, rSection, rEntry, bDefault );
98 sal_uInt32 readIdent(const rtl::OString& rSection, const rtl::OString& rEntry,
99 sal_uInt32 nFirstId, const std::list< rtl::OString >& rStrings,
100 sal_uInt32 nDefault)
102 int nItems = rStrings.size();
103 const sal_Char** pStrings = new const sal_Char*[ nItems+1 ];
104 std::list< rtl::OString >::const_iterator it = rStrings.begin();
105 nItems = 0;
106 while( it != rStrings.end() )
108 pStrings[ nItems++ ] = *it;
109 ++it;
111 pStrings[ nItems ] = NULL;
112 sal_uInt32 nRet = osl_readProfileIdent(profile, rSection, rEntry, nFirstId, pStrings, nDefault);
113 delete pStrings;
114 return nRet;
117 sal_Bool writeString(const rtl::OString& rSection, const rtl::OString& rEntry,
118 const rtl::OString& rString)
120 return osl_writeProfileString(profile, rSection, rEntry, rString);
123 sal_Bool writeBool(const rtl::OString& rSection, const rtl::OString& rEntry, sal_Bool Value)
125 return osl_writeProfileBool(profile, rSection, rEntry, Value);
128 sal_Bool writeIdent(const rtl::OString& rSection, const rtl::OString& rEntry,
129 sal_uInt32 nFirstId, const std::list< rtl::OString >& rStrings,
130 sal_uInt32 nValue)
132 int nItems = rStrings.size();
133 const sal_Char** pStrings = new const sal_Char*[ nItems+1 ];
134 std::list< rtl::OString >::const_iterator it = rStrings.begin();
135 nItems = 0;
136 while( it != rStrings.end() )
138 pStrings[ nItems++ ] = *it;
139 ++it;
141 pStrings[ nItems ] = NULL;
142 sal_Bool bRet =
143 osl_writeProfileIdent(profile, rSection, rEntry, nFirstId, pStrings, nValue );
144 delete pStrings;
145 return bRet;
148 /** Acquire the mutex, block if already acquired by another thread.
149 @param Profile handle to a opened profile.
150 @return False if section or entry could not be found.
152 sal_Bool removeEntry(const rtl::OString& rSection, const rtl::OString& rEntry)
154 return osl_removeProfileEntry(profile, rSection, rEntry);
157 /** Get all entries belonging to the specified section.
158 @param Profile handle to a opened profile.
159 @return Pointer to a array of pointers.
161 std::list< rtl::OString > getSectionEntries(const rtl::OString& rSection )
163 std::list< rtl::OString > aEntries;
165 // count buffer size necessary
166 int n = osl_getProfileSectionEntries( profile, rSection, NULL, 0 );
167 if( n > 1 )
169 sal_Char* pBuf = new sal_Char[ n+1 ];
170 osl_getProfileSectionEntries( profile, rSection, pBuf, n+1 );
171 int nLen;
172 for( n = 0; ( nLen = strlen( pBuf+n ) ); n += nLen+1 )
173 aEntries.push_back( rtl::OString( pBuf+n ) );
174 delete pBuf;
177 return aEntries;
180 /** Get all section entries
181 @param Profile handle to a opened profile.
182 @return Pointer to a array of pointers.
184 std::list< rtl::OString > getSections()
186 std::list< rtl::OString > aSections;
188 // count buffer size necessary
189 int n = osl_getProfileSections( profile, NULL, 0 );
190 if( n > 1 )
192 sal_Char* pBuf = new sal_Char[ n+1 ];
193 osl_getProfileSections( profile, pBuf, n+1 );
194 int nLen;
195 for( n = 0; ( nLen = strlen( pBuf+n ) ); n += nLen+1 )
196 aSections.push_back( rtl::OString( pBuf+n ) );
197 delete pBuf;
200 return aSections;
205 #endif /* _OSL_PROFILE_HXX_ */