bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / osl / profile.hxx
blob48b6b8c861f4204782582cd43c3a8510a8cae6c0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_OSL_PROFILE_HXX
21 #define INCLUDED_OSL_PROFILE_HXX
23 #include "osl/profile.h"
24 #include "rtl/ustring.hxx"
26 #include <string.h>
27 #include <exception>
28 #include <list>
30 namespace osl {
32 typedef oslProfileOption ProfileOption;
34 const int Profile_DEFAULT = osl_Profile_DEFAULT;
35 const int Profile_SYSTEM = osl_Profile_SYSTEM; /* use system depended functinality */
36 const int Profile_READLOCK = osl_Profile_READLOCK; /* lock file for reading */
37 const int Profile_WRITELOCK = osl_Profile_WRITELOCK; /* lock file for writing */
39 /** Deprecated API.
40 @deprecated
42 class Profile {
43 oslProfile profile;
45 public:
46 /** Open or create a configuration profile.
47 @retval 0 if the profile could not be created, otherwise a handle to the profile.
49 Profile(const rtl::OUString & strProfileName, oslProfileOption Options = Profile_DEFAULT )
51 profile = osl_openProfile(strProfileName.pData, Options);
52 if( ! profile )
53 throw std::exception();
57 /** Close the opened profile an flush all data to the disk.
59 ~Profile()
61 osl_closeProfile(profile);
65 bool flush()
67 return osl_flushProfile(profile);
70 rtl::OString readString( const rtl::OString& rSection, const rtl::OString& rEntry,
71 const rtl::OString& rDefault)
73 sal_Char aBuf[1024];
74 return osl_readProfileString( profile,
75 rSection.getStr(),
76 rEntry.getStr(),
77 aBuf,
78 sizeof( aBuf ),
79 rDefault.getStr() ) ? rtl::OString( aBuf ) : rtl::OString();
83 bool readBool( const rtl::OString& rSection, const rtl::OString& rEntry, bool bDefault )
85 return osl_readProfileBool( profile, rSection.getStr(), rEntry.getStr(), bDefault );
88 sal_uInt32 readIdent(const rtl::OString& rSection, const rtl::OString& rEntry,
89 sal_uInt32 nFirstId, const std::list< rtl::OString >& rStrings,
90 sal_uInt32 nDefault)
92 size_t nItems = rStrings.size();
93 const sal_Char** pStrings = new const sal_Char*[ nItems+1 ];
94 std::list< rtl::OString >::const_iterator it = rStrings.begin();
95 nItems = 0;
96 while( it != rStrings.end() )
98 pStrings[ nItems++ ] = it->getStr();
99 ++it;
101 pStrings[ nItems ] = NULL;
102 sal_uInt32 nRet = osl_readProfileIdent(profile, rSection.getStr(), rEntry.getStr(), nFirstId, pStrings, nDefault);
103 delete[] pStrings;
104 return nRet;
107 bool writeString(const rtl::OString& rSection, const rtl::OString& rEntry,
108 const rtl::OString& rString)
110 return osl_writeProfileString(profile, rSection.getStr(), rEntry.getStr(), rString.getStr());
113 bool writeBool(const rtl::OString& rSection, const rtl::OString& rEntry, bool Value)
115 return osl_writeProfileBool(profile, rSection.getStr(), rEntry.getStr(), Value);
118 bool writeIdent(const rtl::OString& rSection, const rtl::OString& rEntry,
119 sal_uInt32 nFirstId, const std::list< rtl::OString >& rStrings,
120 sal_uInt32 nValue)
122 size_t nItems = rStrings.size();
123 const sal_Char** pStrings = new const sal_Char*[ nItems+1 ];
124 std::list< rtl::OString >::const_iterator it = rStrings.begin();
125 nItems = 0;
126 while( it != rStrings.end() )
128 pStrings[ nItems++ ] = it->getStr();
129 ++it;
131 pStrings[ nItems ] = NULL;
132 bool bRet =
133 osl_writeProfileIdent(profile, rSection.getStr(), rEntry.getStr(), nFirstId, pStrings, nValue );
134 delete[] pStrings;
135 return bRet;
138 /** Remove an entry from a section.
139 @param rSection Name of the section.
140 @param rEntry Name of the entry to remove.
141 @retval False if section or entry could not be found.
143 bool removeEntry(const rtl::OString& rSection, const rtl::OString& rEntry)
145 return osl_removeProfileEntry(profile, rSection.getStr(), rEntry.getStr());
148 /** Get all entries belonging to the specified section.
149 @param rSection Name of the section.
150 @return Pointer to a array of pointers.
152 std::list< rtl::OString > getSectionEntries(const rtl::OString& rSection )
154 std::list< rtl::OString > aEntries;
156 // count buffer size necessary
157 size_t n = osl_getProfileSectionEntries( profile, rSection.getStr(), NULL, 0 );
158 if( n > 1 )
160 sal_Char* pBuf = new sal_Char[ n+1 ];
161 osl_getProfileSectionEntries( profile, rSection.getStr(), pBuf, n+1 );
162 size_t nLen;
163 for( n = 0; ( nLen = strlen( pBuf+n ) ); n += nLen+1 )
164 aEntries.push_back( rtl::OString( pBuf+n ) );
165 delete[] pBuf;
168 return aEntries;
171 /** Get all section entries
172 @return Pointer to a array of pointers.
174 std::list< rtl::OString > getSections()
176 std::list< rtl::OString > aSections;
178 // count buffer size necessary
179 size_t n = osl_getProfileSections( profile, NULL, 0 );
180 if( n > 1 )
182 sal_Char* pBuf = new sal_Char[ n+1 ];
183 osl_getProfileSections( profile, pBuf, n+1 );
184 size_t nLen;
185 for( n = 0; ( nLen = strlen( pBuf+n ) ); n += nLen+1 )
186 aSections.push_back( rtl::OString( pBuf+n ) );
187 delete[] pBuf;
190 return aSections;
195 #endif // INCLUDED_OSL_PROFILE_HXX
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */