LibreOffice: osl/profile.hxx Source File

LibreOffice LibreOffice 7.3 SDK C/C++ API Reference

profile.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20/*
21 * This file is part of LibreOffice published API.
22 */
23
24#ifndef INCLUDED_OSL_PROFILE_HXX
25#define INCLUDED_OSL_PROFILE_HXX
26
27#include "osl/profile.h"
28#include "rtl/ustring.hxx"
29
30#include <string.h>
31#include <exception>
32#include <list>
33
34namespace osl {
35
36 typedef oslProfileOption ProfileOption;
37
38 const int Profile_DEFAULT = osl_Profile_DEFAULT;
39 const int Profile_SYSTEM = osl_Profile_SYSTEM; /* use system depended functionality */
40 const int Profile_READLOCK = osl_Profile_READLOCK; /* lock file for reading */
41 const int Profile_WRITELOCK = osl_Profile_WRITELOCK; /* lock file for writing */
42
46 class Profile {
47 oslProfile profile;
48
49 public:
53 Profile(const rtl::OUString & strProfileName, oslProfileOption Options = Profile_DEFAULT )
54 {
55 profile = osl_openProfile(strProfileName.pData, Options);
56 if( ! profile )
57 throw std::exception();
58 }
59
60
63 ~Profile()
64 {
65 osl_closeProfile(profile);
66 }
67
68
69 bool flush()
70 {
71 return osl_flushProfile(profile);
72 }
73
74 rtl::OString readString( const rtl::OString& rSection, const rtl::OString& rEntry,
75 const rtl::OString& rDefault)
76 {
77 char aBuf[1024];
78 return osl_readProfileString( profile,
79 rSection.getStr(),
80 rEntry.getStr(),
81 aBuf,
82 sizeof( aBuf ),
83 rDefault.getStr() ) ? rtl::OString( aBuf ) : rtl::OString();
84
85 }
86
87 bool readBool( const rtl::OString& rSection, const rtl::OString& rEntry, bool bDefault )
88 {
89 return osl_readProfileBool( profile, rSection.getStr(), rEntry.getStr(), bDefault );
90 }
91
92 sal_uInt32 readIdent(const rtl::OString& rSection, const rtl::OString& rEntry,
93 sal_uInt32 nFirstId, const std::list< rtl::OString >& rStrings,
94 sal_uInt32 nDefault)
95 {
96 size_t nItems = rStrings.size();
97 const char** pStrings = new const char*[ nItems+1 ];
98 std::list< rtl::OString >::const_iterator it = rStrings.begin();
99 nItems = 0;
100 while( it != rStrings.end() )
101 {
102 pStrings[ nItems++ ] = it->getStr();
103 ++it;
104 }
105 pStrings[ nItems ] = NULL;
106 sal_uInt32 nRet = osl_readProfileIdent(profile, rSection.getStr(), rEntry.getStr(), nFirstId, pStrings, nDefault);
107 delete[] pStrings;
108 return nRet;
109 }
110
111 bool writeString(const rtl::OString& rSection, const rtl::OString& rEntry,
112 const rtl::OString& rString)
113 {
114 return osl_writeProfileString(profile, rSection.getStr(), rEntry.getStr(), rString.getStr());
115 }
116
117 bool writeBool(const rtl::OString& rSection, const rtl::OString& rEntry, bool Value)
118 {
119 return osl_writeProfileBool(profile, rSection.getStr(), rEntry.getStr(), Value);
120 }
121
122 bool writeIdent(const rtl::OString& rSection, const rtl::OString& rEntry,
123 sal_uInt32 nFirstId, const std::list< rtl::OString >& rStrings,
124 sal_uInt32 nValue)
125 {
126 size_t nItems = rStrings.size();
127 const char** pStrings = new const char*[ nItems+1 ];
128 std::list< rtl::OString >::const_iterator it = rStrings.begin();
129 nItems = 0;
130 while( it != rStrings.end() )
131 {
132 pStrings[ nItems++ ] = it->getStr();
133 ++it;
134 }
135 pStrings[ nItems ] = NULL;
136 bool bRet =
137 osl_writeProfileIdent(profile, rSection.getStr(), rEntry.getStr(), nFirstId, pStrings, nValue );
138 delete[] pStrings;
139 return bRet;
140 }
141
147 bool removeEntry(const rtl::OString& rSection, const rtl::OString& rEntry)
148 {
149 return osl_removeProfileEntry(profile, rSection.getStr(), rEntry.getStr());
150 }
151
156 std::list< rtl::OString > getSectionEntries(const rtl::OString& rSection )
157 {
158 std::list< rtl::OString > aEntries;
159
160 // count buffer size necessary
161 size_t n = osl_getProfileSectionEntries( profile, rSection.getStr(), NULL, 0 );
162 if( n > 1 )
163 {
164 char* pBuf = new char[ n+1 ];
165 osl_getProfileSectionEntries( profile, rSection.getStr(), pBuf, n+1 );
166 size_t nLen;
167 for( n = 0; ; n += nLen+1 )
168 {
169 nLen = strlen( pBuf+n );
170 if (!nLen)
171 break;
172 aEntries.push_back( rtl::OString( pBuf+n ) );
173 }
174 delete[] pBuf;
175 }
176
177 return aEntries;
178 }
179
183 std::list< rtl::OString > getSections()
184 {
185 std::list< rtl::OString > aSections;
186
187 // count buffer size necessary
188 size_t n = osl_getProfileSections( profile, NULL, 0 );
189 if( n > 1 )
190 {
191 char* pBuf = new char[ n+1 ];
192 osl_getProfileSections( profile, pBuf, n+1 );
193 size_t nLen;
194 for( n = 0; ; n += nLen+1 )
195 {
196 nLen = strlen( pBuf+n );
197 if (!nLen)
198 break;
199 aSections.push_back( rtl::OString( pBuf+n ) );
200 }
201 delete[] pBuf;
202 }
203
204 return aSections;
205 }
206 };
207}
208
209#endif // INCLUDED_OSL_PROFILE_HXX
210
211
212/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ustring.hxx
string.h
profile.h
oslProfileOption
sal_uInt32 oslProfileOption
Definition: profile.h:37
osl_writeProfileString
SAL_DLLPUBLIC sal_Bool osl_writeProfileString(oslProfile Profile, const char *pszSection, const char *pszEntry, const char *pszString) SAL_COLD
Deprecated API.
osl_Profile_READLOCK
#define osl_Profile_READLOCK
Definition: profile.h:41
osl_openProfile
SAL_DLLPUBLIC oslProfile osl_openProfile(rtl_uString *strProfileName, oslProfileOption Options) SAL_COLD
Deprecated API.
osl_readProfileIdent
SAL_DLLPUBLIC sal_uInt32 osl_readProfileIdent(oslProfile Profile, const char *pszSection, const char *pszEntry, sal_uInt32 FirstId, const char *Strings[], sal_uInt32 Default) SAL_COLD
Deprecated API.
osl_removeProfileEntry
SAL_DLLPUBLIC sal_Bool osl_removeProfileEntry(oslProfile Profile, const char *pszSection, const char *pszEntry) SAL_COLD
Deprecated API.
osl_getProfileSectionEntries
SAL_DLLPUBLIC sal_uInt32 osl_getProfileSectionEntries(oslProfile Profile, const char *pszSection, char *pszBuffer, sal_uInt32 MaxLen) SAL_COLD
Deprecated API.
oslProfile
void * oslProfile
Definition: profile.h:46
osl_Profile_WRITELOCK
#define osl_Profile_WRITELOCK
Definition: profile.h:42
osl_Profile_SYSTEM
#define osl_Profile_SYSTEM
Definition: profile.h:40
osl_readProfileBool
SAL_DLLPUBLIC sal_Bool osl_readProfileBool(oslProfile Profile, const char *pszSection, const char *pszEntry, sal_Bool Default) SAL_COLD
Deprecated API.
osl_writeProfileIdent
SAL_DLLPUBLIC sal_Bool osl_writeProfileIdent(oslProfile Profile, const char *pszSection, const char *pszEntry, sal_uInt32 FirstId, const char *Strings[], sal_uInt32 Value) SAL_COLD
Deprecated API.
osl_readProfileString
SAL_DLLPUBLIC sal_Bool osl_readProfileString(oslProfile Profile, const char *pszSection, const char *pszEntry, char *pszString, sal_uInt32 MaxLen, const char *pszDefault) SAL_COLD
Deprecated API.
osl_Profile_DEFAULT
#define osl_Profile_DEFAULT
Definition: profile.h:39
osl_closeProfile
SAL_DLLPUBLIC sal_Bool osl_closeProfile(oslProfile Profile) SAL_COLD
Deprecated API.
osl_writeProfileBool
SAL_DLLPUBLIC sal_Bool osl_writeProfileBool(oslProfile Profile, const char *pszSection, const char *pszEntry, sal_Bool Value) SAL_COLD
Deprecated API.
osl_flushProfile
SAL_DLLPUBLIC sal_Bool osl_flushProfile(oslProfile Profile) SAL_COLD
Deprecated API.
osl_getProfileSections
SAL_DLLPUBLIC sal_uInt32 osl_getProfileSections(oslProfile Profile, char *pszBuffer, sal_uInt32 MaxLen) SAL_COLD
Deprecated API.
osl
Definition: component.hxx:34
osl::ProfileOption
oslProfileOption ProfileOption
Definition: profile.hxx:36
osl::Profile_READLOCK
const int Profile_READLOCK
Definition: profile.hxx:40
osl::Profile_DEFAULT
const int Profile_DEFAULT
Definition: profile.hxx:38
osl::Profile_SYSTEM
const int Profile_SYSTEM
Definition: profile.hxx:39
osl::Profile_WRITELOCK
const int Profile_WRITELOCK
Definition: profile.hxx:41
osl::Profile
Deprecated API.
Definition: profile.hxx:46
osl::Profile::writeString
bool writeString(const rtl::OString &rSection, const rtl::OString &rEntry, const rtl::OString &rString)
Definition: profile.hxx:111
osl::Profile::writeBool
bool writeBool(const rtl::OString &rSection, const rtl::OString &rEntry, bool Value)
Definition: profile.hxx:117
osl::Profile::removeEntry
bool removeEntry(const rtl::OString &rSection, const rtl::OString &rEntry)
Remove an entry from a section.
Definition: profile.hxx:147
osl::Profile::readBool
bool readBool(const rtl::OString &rSection, const rtl::OString &rEntry, bool bDefault)
Definition: profile.hxx:87
osl::Profile::flush
bool flush()
Definition: profile.hxx:69
osl::Profile::readString
rtl::OString readString(const rtl::OString &rSection, const rtl::OString &rEntry, const rtl::OString &rDefault)
Definition: profile.hxx:74
osl::Profile::getSections
std::list< rtl::OString > getSections()
Get all section entries.
Definition: profile.hxx:183
osl::Profile::readIdent
sal_uInt32 readIdent(const rtl::OString &rSection, const rtl::OString &rEntry, sal_uInt32 nFirstId, const std::list< rtl::OString > &rStrings, sal_uInt32 nDefault)
Definition: profile.hxx:92
osl::Profile::~Profile
~Profile()
Close the opened profile an flush all data to the disk.
Definition: profile.hxx:63
osl::Profile::getSectionEntries
std::list< rtl::OString > getSectionEntries(const rtl::OString &rSection)
Get all entries belonging to the specified section.
Definition: profile.hxx:156
osl::Profile::Profile
Profile(const rtl::OUString &strProfileName, oslProfileOption Options=Profile_DEFAULT)
Open or create a configuration profile.
Definition: profile.hxx:53
osl::Profile::writeIdent
bool writeIdent(const rtl::OString &rSection, const rtl::OString &rEntry, sal_uInt32 nFirstId, const std::list< rtl::OString > &rStrings, sal_uInt32 nValue)
Definition: profile.hxx:122
rtl::OString
This String class provide base functionality for C++ like 8-Bit character array handling.
Definition: string.hxx:181
rtl::OString::getStr
const char * getStr() const SAL_RETURNS_NONNULL
Returns a pointer to the characters of this string.
Definition: string.hxx:603
rtl::OUString
This String class provides base functionality for C++ like Unicode character array handling.
Definition: ustring.hxx:204