bump product version to 4.2.0.1
[LibreOffice.git] / include / osl / profile.hxx
blobbd4794e04951a20dd63c0ef033b4d05fa1d9f596
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>
25 #include <string.h>
26 #include <list>
28 namespace osl {
30 typedef oslProfileOption ProfileOption;
32 const int Profile_DEFAULT = osl_Profile_DEFAULT;
33 const int Profile_SYSTEM = osl_Profile_SYSTEM; /* use system depended functinality */
34 const int Profile_READLOCK = osl_Profile_READLOCK; /* lock file for reading */
35 const int Profile_WRITELOCK = osl_Profile_WRITELOCK; /* lock file for writing */
37 /** Deprecated API.
38 @deprecated
40 class Profile {
41 oslProfile profile;
43 public:
44 /** Open or create a configuration profile.
45 @return 0 if the profile could not be created, otherwise a handle to the profile.
47 Profile(const rtl::OUString strProfileName, oslProfileOption Options = Profile_DEFAULT )
49 profile = osl_openProfile(strProfileName.pData, Options);
50 if( ! profile )
51 throw std::exception();
55 /** Close the opened profile an flush all data to the disk.
57 ~Profile()
59 osl_closeProfile(profile);
63 sal_Bool flush()
65 return osl_flushProfile(profile);
68 rtl::OString readString( const rtl::OString& rSection, const rtl::OString& rEntry,
69 const rtl::OString& rDefault)
71 sal_Char aBuf[1024];
72 return osl_readProfileString( profile,
73 rSection.getStr(),
74 rEntry.getStr(),
75 aBuf,
76 sizeof( aBuf ),
77 rDefault.getStr() ) ? rtl::OString( aBuf ) : rtl::OString();
81 sal_Bool readBool( const rtl::OString& rSection, const rtl::OString& rEntry, sal_Bool bDefault )
83 return osl_readProfileBool( profile, rSection.getStr(), rEntry.getStr(), bDefault );
86 sal_uInt32 readIdent(const rtl::OString& rSection, const rtl::OString& rEntry,
87 sal_uInt32 nFirstId, const std::list< rtl::OString >& rStrings,
88 sal_uInt32 nDefault)
90 size_t nItems = rStrings.size();
91 const sal_Char** pStrings = new const sal_Char*[ nItems+1 ];
92 std::list< rtl::OString >::const_iterator it = rStrings.begin();
93 nItems = 0;
94 while( it != rStrings.end() )
96 pStrings[ nItems++ ] = it->getStr();
97 ++it;
99 pStrings[ nItems ] = NULL;
100 sal_uInt32 nRet = osl_readProfileIdent(profile, rSection.getStr(), rEntry.getStr(), nFirstId, pStrings, nDefault);
101 delete pStrings;
102 return nRet;
105 sal_Bool writeString(const rtl::OString& rSection, const rtl::OString& rEntry,
106 const rtl::OString& rString)
108 return osl_writeProfileString(profile, rSection.getStr(), rEntry.getStr(), rString.getStr());
111 sal_Bool writeBool(const rtl::OString& rSection, const rtl::OString& rEntry, sal_Bool Value)
113 return osl_writeProfileBool(profile, rSection.getStr(), rEntry.getStr(), Value);
116 sal_Bool writeIdent(const rtl::OString& rSection, const rtl::OString& rEntry,
117 sal_uInt32 nFirstId, const std::list< rtl::OString >& rStrings,
118 sal_uInt32 nValue)
120 size_t nItems = rStrings.size();
121 const sal_Char** pStrings = new const sal_Char*[ nItems+1 ];
122 std::list< rtl::OString >::const_iterator it = rStrings.begin();
123 nItems = 0;
124 while( it != rStrings.end() )
126 pStrings[ nItems++ ] = it->getStr();
127 ++it;
129 pStrings[ nItems ] = NULL;
130 sal_Bool bRet =
131 osl_writeProfileIdent(profile, rSection.getStr(), rEntry.getStr(), nFirstId, pStrings, nValue );
132 delete pStrings;
133 return bRet;
136 /** Remove an entry from a section.
137 @param rSection Name of the section.
138 @param rEntry Name of the entry to remove.
139 @return False if section or entry could not be found.
141 sal_Bool removeEntry(const rtl::OString& rSection, const rtl::OString& rEntry)
143 return osl_removeProfileEntry(profile, rSection.getStr(), rEntry.getStr());
146 /** Get all entries belonging to the specified section.
147 @param rSection Name of the section.
148 @return Pointer to a array of pointers.
150 std::list< rtl::OString > getSectionEntries(const rtl::OString& rSection )
152 std::list< rtl::OString > aEntries;
154 // count buffer size necessary
155 size_t n = osl_getProfileSectionEntries( profile, rSection.getStr(), NULL, 0 );
156 if( n > 1 )
158 sal_Char* pBuf = new sal_Char[ n+1 ];
159 osl_getProfileSectionEntries( profile, rSection.getStr(), pBuf, n+1 );
160 size_t nLen;
161 for( n = 0; ( nLen = strlen( pBuf+n ) ); n += nLen+1 )
162 aEntries.push_back( rtl::OString( pBuf+n ) );
163 delete pBuf;
166 return aEntries;
169 /** Get all section entries
170 @return Pointer to a array of pointers.
172 std::list< rtl::OString > getSections()
174 std::list< rtl::OString > aSections;
176 // count buffer size necessary
177 size_t n = osl_getProfileSections( profile, NULL, 0 );
178 if( n > 1 )
180 sal_Char* pBuf = new sal_Char[ n+1 ];
181 osl_getProfileSections( profile, pBuf, n+1 );
182 size_t nLen;
183 for( n = 0; ( nLen = strlen( pBuf+n ) ); n += nLen+1 )
184 aSections.push_back( rtl::OString( pBuf+n ) );
185 delete pBuf;
188 return aSections;
193 #endif // INCLUDED_OSL_PROFILE_HXX
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */