|
UDK 3.2.7 C/C++ API Reference
|
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 00002 /* 00003 * This file is part of the LibreOffice project. 00004 * 00005 * This Source Code Form is subject to the terms of the Mozilla Public 00006 * License, v. 2.0. If a copy of the MPL was not distributed with this 00007 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 00008 * 00009 * This file incorporates work covered by the following license notice: 00010 * 00011 * Licensed to the Apache Software Foundation (ASF) under one or more 00012 * contributor license agreements. See the NOTICE file distributed 00013 * with this work for additional information regarding copyright 00014 * ownership. The ASF licenses this file to you under the Apache 00015 * License, Version 2.0 (the "License"); you may not use this file 00016 * except in compliance with the License. You may obtain a copy of 00017 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 00018 */ 00019 00020 #ifndef _OSL_PROFILE_HXX_ 00021 #define _OSL_PROFILE_HXX_ 00022 00023 #include "profile.h" 00024 #include <rtl/ustring.hxx> 00025 #include <string.h> 00026 #include <list> 00027 00028 namespace osl { 00029 00030 typedef oslProfileOption ProfileOption; 00031 00032 const int Profile_DEFAULT = osl_Profile_DEFAULT; 00033 const int Profile_SYSTEM = osl_Profile_SYSTEM; /* use system depended functinality */ 00034 const int Profile_READLOCK = osl_Profile_READLOCK; /* lock file for reading */ 00035 const int Profile_WRITELOCK = osl_Profile_WRITELOCK; /* lock file for writing */ 00036 00040 class Profile { 00041 oslProfile profile; 00042 00043 public: 00047 Profile(const rtl::OUString strProfileName, oslProfileOption Options = Profile_DEFAULT ) 00048 { 00049 profile = osl_openProfile(strProfileName.pData, Options); 00050 if( ! profile ) 00051 throw std::exception(); 00052 } 00053 00054 00057 ~Profile() 00058 { 00059 osl_closeProfile(profile); 00060 } 00061 00062 00063 sal_Bool flush() 00064 { 00065 return osl_flushProfile(profile); 00066 } 00067 00068 rtl::OString readString( const rtl::OString& rSection, const rtl::OString& rEntry, 00069 const rtl::OString& rDefault) 00070 { 00071 sal_Char aBuf[1024]; 00072 return osl_readProfileString( profile, 00073 rSection.getStr(), 00074 rEntry.getStr(), 00075 aBuf, 00076 sizeof( aBuf ), 00077 rDefault.getStr() ) ? rtl::OString( aBuf ) : rtl::OString(); 00078 00079 } 00080 00081 sal_Bool readBool( const rtl::OString& rSection, const rtl::OString& rEntry, sal_Bool bDefault ) 00082 { 00083 return osl_readProfileBool( profile, rSection.getStr(), rEntry.getStr(), bDefault ); 00084 } 00085 00086 sal_uInt32 readIdent(const rtl::OString& rSection, const rtl::OString& rEntry, 00087 sal_uInt32 nFirstId, const std::list< rtl::OString >& rStrings, 00088 sal_uInt32 nDefault) 00089 { 00090 int nItems = rStrings.size(); 00091 const sal_Char** pStrings = new const sal_Char*[ nItems+1 ]; 00092 std::list< rtl::OString >::const_iterator it = rStrings.begin(); 00093 nItems = 0; 00094 while( it != rStrings.end() ) 00095 { 00096 pStrings[ nItems++ ] = it->getStr(); 00097 ++it; 00098 } 00099 pStrings[ nItems ] = NULL; 00100 sal_uInt32 nRet = osl_readProfileIdent(profile, rSection.getStr(), rEntry.getStr(), nFirstId, pStrings, nDefault); 00101 delete pStrings; 00102 return nRet; 00103 } 00104 00105 sal_Bool writeString(const rtl::OString& rSection, const rtl::OString& rEntry, 00106 const rtl::OString& rString) 00107 { 00108 return osl_writeProfileString(profile, rSection.getStr(), rEntry.getStr(), rString.getStr()); 00109 } 00110 00111 sal_Bool writeBool(const rtl::OString& rSection, const rtl::OString& rEntry, sal_Bool Value) 00112 { 00113 return osl_writeProfileBool(profile, rSection.getStr(), rEntry.getStr(), Value); 00114 } 00115 00116 sal_Bool writeIdent(const rtl::OString& rSection, const rtl::OString& rEntry, 00117 sal_uInt32 nFirstId, const std::list< rtl::OString >& rStrings, 00118 sal_uInt32 nValue) 00119 { 00120 int nItems = rStrings.size(); 00121 const sal_Char** pStrings = new const sal_Char*[ nItems+1 ]; 00122 std::list< rtl::OString >::const_iterator it = rStrings.begin(); 00123 nItems = 0; 00124 while( it != rStrings.end() ) 00125 { 00126 pStrings[ nItems++ ] = it->getStr(); 00127 ++it; 00128 } 00129 pStrings[ nItems ] = NULL; 00130 sal_Bool bRet = 00131 osl_writeProfileIdent(profile, rSection.getStr(), rEntry.getStr(), nFirstId, pStrings, nValue ); 00132 delete pStrings; 00133 return bRet; 00134 } 00135 00141 sal_Bool removeEntry(const rtl::OString& rSection, const rtl::OString& rEntry) 00142 { 00143 return osl_removeProfileEntry(profile, rSection.getStr(), rEntry.getStr()); 00144 } 00145 00150 std::list< rtl::OString > getSectionEntries(const rtl::OString& rSection ) 00151 { 00152 std::list< rtl::OString > aEntries; 00153 00154 // count buffer size necessary 00155 int n = osl_getProfileSectionEntries( profile, rSection.getStr(), NULL, 0 ); 00156 if( n > 1 ) 00157 { 00158 sal_Char* pBuf = new sal_Char[ n+1 ]; 00159 osl_getProfileSectionEntries( profile, rSection.getStr(), pBuf, n+1 ); 00160 int nLen; 00161 for( n = 0; ( nLen = strlen( pBuf+n ) ); n += nLen+1 ) 00162 aEntries.push_back( rtl::OString( pBuf+n ) ); 00163 delete pBuf; 00164 } 00165 00166 return aEntries; 00167 } 00168 00172 std::list< rtl::OString > getSections() 00173 { 00174 std::list< rtl::OString > aSections; 00175 00176 // count buffer size necessary 00177 int n = osl_getProfileSections( profile, NULL, 0 ); 00178 if( n > 1 ) 00179 { 00180 sal_Char* pBuf = new sal_Char[ n+1 ]; 00181 osl_getProfileSections( profile, pBuf, n+1 ); 00182 int nLen; 00183 for( n = 0; ( nLen = strlen( pBuf+n ) ); n += nLen+1 ) 00184 aSections.push_back( rtl::OString( pBuf+n ) ); 00185 delete pBuf; 00186 } 00187 00188 return aSections; 00189 } 00190 }; 00191 } 00192 00193 #endif /* _OSL_PROFILE_HXX_ */ 00194 00195 00196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
1.7.3