LibreOffice: osl/profile.hxx Source File

LibreOffice LibreOffice 7.1 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#ifndef INCLUDED_OSL_PROFILE_HXX
21#define INCLUDED_OSL_PROFILE_HXX
22
23#include "osl/profile.h"
24#include "rtl/ustring.hxx"
25
26#include <string.h>
27#include <exception>
28#include <list>
29
30namespace osl {
31
32 typedef oslProfileOption ProfileOption;
33
34 const int Profile_DEFAULT = osl_Profile_DEFAULT;
35 const int Profile_SYSTEM = osl_Profile_SYSTEM; /* use system depended functionality */
36 const int Profile_READLOCK = osl_Profile_READLOCK; /* lock file for reading */
37 const int Profile_WRITELOCK = osl_Profile_WRITELOCK; /* lock file for writing */
38
42 class Profile {
43 oslProfile profile;
44
45 public:
49 Profile(const rtl::OUString & strProfileName, oslProfileOption Options = Profile_DEFAULT )
50 {
51 profile = osl_openProfile(strProfileName.pData, Options);
52 if( ! profile )
53 throw std::exception();
54 }
55
56
59 ~Profile()
60 {
61 osl_closeProfile(profile);
62 }
63
64
65 bool flush()
66 {
67 return osl_flushProfile(profile);
68 }
69
70 rtl::OString readString( const rtl::OString& rSection, const rtl::OString& rEntry,
71 const rtl::OString& rDefault)
72 {
73 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();
80
81 }
82
83 bool readBool( const rtl::OString& rSection, const rtl::OString& rEntry, bool bDefault )
84 {
85 return osl_readProfileBool( profile, rSection.getStr(), rEntry.getStr(), bDefault );
86 }
87
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)
91 {
92 size_t nItems = rStrings.size();
93 const char** pStrings = new const char*[ nItems+1 ];
94 std::list< rtl::OString >::const_iterator it = rStrings.begin();
95 nItems = 0;
96 while( it != rStrings.end() )
97 {
98 pStrings[ nItems++ ] = it->getStr();
99 ++it;
100 }
101 pStrings[ nItems ] = NULL;
102 sal_uInt32 nRet = osl_readProfileIdent(profile, rSection.getStr(), rEntry.getStr(), nFirstId, pStrings, nDefault);
103 delete[] pStrings;
104 return nRet;
105 }
106
107 bool writeString(const rtl::OString& rSection, const rtl::OString& rEntry,
108 const rtl::OString& rString)
109 {
110 return osl_writeProfileString(profile, rSection.getStr(), rEntry.getStr(), rString.getStr());
111 }
112
113 bool writeBool(const rtl::OString& rSection, const rtl::OString& rEntry, bool Value)
114 {
115 return osl_writeProfileBool(profile, rSection.getStr(), rEntry.getStr(), Value);
116 }
117
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)
121 {
122 size_t nItems = rStrings.size();
123 const char** pStrings = new const char*[ nItems+1 ];
124 std::list< rtl::OString >::const_iterator it = rStrings.begin();
125 nItems = 0;
126 while( it != rStrings.end() )
127 {
128 pStrings[ nItems++ ] = it->getStr();
129 ++it;
130 }
131 pStrings[ nItems ] = NULL;
132 bool bRet =
133 osl_writeProfileIdent(profile, rSection.getStr(), rEntry.getStr(), nFirstId, pStrings, nValue );
134 delete[] pStrings;
135 return bRet;
136 }
137
143 bool removeEntry(const rtl::OString& rSection, const rtl::OString& rEntry)
144 {
145 return osl_removeProfileEntry(profile, rSection.getStr(), rEntry.getStr());
146 }
147
152 std::list< rtl::OString > getSectionEntries(const rtl::OString& rSection )
153 {
154 std::list< rtl::OString > aEntries;
155
156 // count buffer size necessary
157 size_t n = osl_getProfileSectionEntries( profile, rSection.getStr(), NULL, 0 );
158 if( n > 1 )
159 {
160 char* pBuf = new char[ n+1 ];
161 osl_getProfileSectionEntries( profile, rSection.getStr(), pBuf, n+1 );
162 size_t nLen;
163 for( n = 0; ; n += nLen+1 )
164 {
165 nLen = strlen( pBuf+n );
166 if (!nLen)
167 break;
168 aEntries.push_back( rtl::OString( pBuf+n ) );
169 }
170 delete[] pBuf;
171 }
172
173 return aEntries;
174 }
175
179 std::list< rtl::OString > getSections()
180 {
181 std::list< rtl::OString > aSections;
182
183 // count buffer size necessary
184 size_t n = osl_getProfileSections( profile, NULL, 0 );
185 if( n > 1 )
186 {
187 char* pBuf = new char[ n+1 ];
188 osl_getProfileSections( profile, pBuf, n+1 );
189 size_t nLen;
190 for( n = 0; ; n += nLen+1 )
191 {
192 nLen = strlen( pBuf+n );
193 if (!nLen)
194 break;
195 aSections.push_back( rtl::OString( pBuf+n ) );
196 }
197 delete[] pBuf;
198 }
199
200 return aSections;
201 }
202 };
203}
204
205#endif // INCLUDED_OSL_PROFILE_HXX
206
207
208/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
string.h
ustring.hxx
profile.h
oslProfileOption
sal_uInt32 oslProfileOption
Definition: profile.h:33
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:37
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:42
osl_Profile_WRITELOCK
#define osl_Profile_WRITELOCK
Definition: profile.h:38
osl_Profile_SYSTEM
#define osl_Profile_SYSTEM
Definition: profile.h:36
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:35
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:30
osl::ProfileOption
oslProfileOption ProfileOption
Definition: profile.hxx:32
osl::Profile_READLOCK
const int Profile_READLOCK
Definition: profile.hxx:36
osl::Profile_DEFAULT
const int Profile_DEFAULT
Definition: profile.hxx:34
osl::Profile_SYSTEM
const int Profile_SYSTEM
Definition: profile.hxx:35
osl::Profile_WRITELOCK
const int Profile_WRITELOCK
Definition: profile.hxx:37
osl::Profile
Deprecated API.
Definition: profile.hxx:42
osl::Profile::writeString
bool writeString(const rtl::OString &rSection, const rtl::OString &rEntry, const rtl::OString &rString)
Definition: profile.hxx:107
osl::Profile::writeBool
bool writeBool(const rtl::OString &rSection, const rtl::OString &rEntry, bool Value)
Definition: profile.hxx:113
osl::Profile::removeEntry
bool removeEntry(const rtl::OString &rSection, const rtl::OString &rEntry)
Remove an entry from a section.
Definition: profile.hxx:143
osl::Profile::readBool
bool readBool(const rtl::OString &rSection, const rtl::OString &rEntry, bool bDefault)
Definition: profile.hxx:83
osl::Profile::flush
bool flush()
Definition: profile.hxx:65
osl::Profile::readString
rtl::OString readString(const rtl::OString &rSection, const rtl::OString &rEntry, const rtl::OString &rDefault)
Definition: profile.hxx:70
osl::Profile::getSections
std::list< rtl::OString > getSections()
Get all section entries.
Definition: profile.hxx:179
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:88
osl::Profile::~Profile
~Profile()
Close the opened profile an flush all data to the disk.
Definition: profile.hxx:59
osl::Profile::getSectionEntries
std::list< rtl::OString > getSectionEntries(const rtl::OString &rSection)
Get all entries belonging to the specified section.
Definition: profile.hxx:152
osl::Profile::Profile
Profile(const rtl::OUString &strProfileName, oslProfileOption Options=Profile_DEFAULT)
Open or create a configuration profile.
Definition: profile.hxx:49
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:118
rtl::OString
This String class provide base functionality for C++ like 8-Bit character array handling.
Definition: string.hxx:171
rtl::OString::getStr
const char * getStr() const SAL_RETURNS_NONNULL
Returns a pointer to the characters of this string.
Definition: string.hxx:551
rtl::OUString
This String class provides base functionality for C++ like Unicode character array handling.
Definition: ustring.hxx:161