LCOV - code coverage report
Current view: top level - solver/unxlngi6.pro/inc/osl - profile.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 9 10 90.0 %
Date: 2012-08-25 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 4 8 50.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef _OSL_PROFILE_HXX_
      30                 :            : #define _OSL_PROFILE_HXX_
      31                 :            : 
      32                 :            : #include "profile.h"
      33                 :            : #include <rtl/ustring.hxx>
      34                 :            : #include <string.h>
      35                 :            : #include <list>
      36                 :            : 
      37                 :            : namespace osl {
      38                 :            : 
      39                 :            :     typedef oslProfileOption ProfileOption;
      40                 :            : 
      41                 :            :     const int Profile_DEFAULT   = osl_Profile_DEFAULT;
      42                 :            :     const int Profile_SYSTEM    = osl_Profile_SYSTEM;    /* use system depended functinality */
      43                 :            :     const int Profile_READLOCK  = osl_Profile_READLOCK;  /* lock file for reading            */
      44                 :            :     const int Profile_WRITELOCK = osl_Profile_WRITELOCK; /* lock file for writing            */
      45                 :            : 
      46                 :            :     /** Deprecated API.
      47                 :            :         @deprecated
      48                 :            :     */
      49                 :            :     class Profile {
      50                 :            :         oslProfile profile;
      51                 :            : 
      52                 :            :     public:
      53                 :            :         /** Open or create a configuration profile.
      54                 :            :             @return 0 if the profile could not be created, otherwise a handle to the profile.
      55                 :            :         */
      56                 :        496 :         Profile(const rtl::OUString strProfileName, oslProfileOption Options = Profile_DEFAULT )
      57                 :            :         {
      58                 :        496 :             profile = osl_openProfile(strProfileName.pData, Options);
      59         [ -  + ]:        496 :             if( ! profile )
      60                 :          0 :                 throw std::exception();
      61                 :        496 :         }
      62                 :            : 
      63                 :            : 
      64                 :            :         /** Close the opened profile an flush all data to the disk.
      65                 :            :         */
      66                 :        496 :         ~Profile()
      67                 :            :         {
      68                 :        496 :             osl_closeProfile(profile);
      69                 :        496 :         }
      70                 :            : 
      71                 :            : 
      72                 :            :         sal_Bool flush()
      73                 :            :         {
      74                 :            :             return osl_flushProfile(profile);
      75                 :            :         }
      76                 :            : 
      77                 :        496 :         rtl::OString readString( const rtl::OString& rSection, const rtl::OString& rEntry,
      78                 :            :                                  const rtl::OString& rDefault)
      79                 :            :         {
      80                 :            :             sal_Char aBuf[1024];
      81                 :            :             return osl_readProfileString( profile,
      82                 :            :                                           rSection.getStr(),
      83                 :            :                                           rEntry.getStr(),
      84                 :            :                                           aBuf,
      85                 :            :                                           sizeof( aBuf ),
      86 [ +  - ][ +  - ]:        496 :                                           rDefault.getStr() ) ? rtl::OString( aBuf ) : rtl::OString();
                 [ +  - ]
      87                 :            : 
      88                 :            :         }
      89                 :            : 
      90                 :            :         sal_Bool readBool( const rtl::OString& rSection, const rtl::OString& rEntry, sal_Bool bDefault )
      91                 :            :         {
      92                 :            :             return osl_readProfileBool( profile, rSection.getStr(), rEntry.getStr(), bDefault );
      93                 :            :         }
      94                 :            : 
      95                 :            :         sal_uInt32 readIdent(const rtl::OString& rSection, const rtl::OString& rEntry,
      96                 :            :                              sal_uInt32 nFirstId, const std::list< rtl::OString >& rStrings,
      97                 :            :                              sal_uInt32 nDefault)
      98                 :            :         {
      99                 :            :             int nItems = rStrings.size();
     100                 :            :             const sal_Char** pStrings = new const sal_Char*[ nItems+1 ];
     101                 :            :             std::list< rtl::OString >::const_iterator it = rStrings.begin();
     102                 :            :             nItems = 0;
     103                 :            :             while( it != rStrings.end() )
     104                 :            :             {
     105                 :            :                 pStrings[ nItems++ ] = it->getStr();
     106                 :            :                 ++it;
     107                 :            :             }
     108                 :            :             pStrings[ nItems ] = NULL;
     109                 :            :             sal_uInt32 nRet = osl_readProfileIdent(profile, rSection.getStr(), rEntry.getStr(), nFirstId, pStrings, nDefault);
     110                 :            :             delete pStrings;
     111                 :            :             return nRet;
     112                 :            :         }
     113                 :            : 
     114                 :            :         sal_Bool writeString(const rtl::OString& rSection, const rtl::OString& rEntry,
     115                 :            :                              const rtl::OString& rString)
     116                 :            :         {
     117                 :            :             return osl_writeProfileString(profile, rSection.getStr(), rEntry.getStr(), rString.getStr());
     118                 :            :         }
     119                 :            : 
     120                 :            :         sal_Bool writeBool(const rtl::OString& rSection, const rtl::OString& rEntry, sal_Bool Value)
     121                 :            :         {
     122                 :            :             return osl_writeProfileBool(profile, rSection.getStr(), rEntry.getStr(), Value);
     123                 :            :         }
     124                 :            : 
     125                 :            :         sal_Bool writeIdent(const rtl::OString& rSection, const rtl::OString& rEntry,
     126                 :            :                             sal_uInt32 nFirstId, const std::list< rtl::OString >& rStrings,
     127                 :            :                             sal_uInt32 nValue)
     128                 :            :         {
     129                 :            :             int nItems = rStrings.size();
     130                 :            :             const sal_Char** pStrings = new const sal_Char*[ nItems+1 ];
     131                 :            :             std::list< rtl::OString >::const_iterator it = rStrings.begin();
     132                 :            :             nItems = 0;
     133                 :            :             while( it != rStrings.end() )
     134                 :            :             {
     135                 :            :                 pStrings[ nItems++ ] = it->getStr();
     136                 :            :                 ++it;
     137                 :            :             }
     138                 :            :             pStrings[ nItems ] = NULL;
     139                 :            :             sal_Bool bRet =
     140                 :            :                 osl_writeProfileIdent(profile, rSection.getStr(), rEntry.getStr(), nFirstId, pStrings, nValue );
     141                 :            :             delete pStrings;
     142                 :            :             return bRet;
     143                 :            :         }
     144                 :            : 
     145                 :            :         /** Remove an entry from a section.
     146                 :            :             @param rSection Name of the section.
     147                 :            :             @param rEntry Name of the entry to remove.
     148                 :            :             @return False if section or entry could not be found.
     149                 :            :         */
     150                 :            :         sal_Bool removeEntry(const rtl::OString& rSection, const rtl::OString& rEntry)
     151                 :            :         {
     152                 :            :             return osl_removeProfileEntry(profile, rSection.getStr(), rEntry.getStr());
     153                 :            :         }
     154                 :            : 
     155                 :            :         /** Get all entries belonging to the specified section.
     156                 :            :             @param rSection Name of the section.
     157                 :            :             @return Pointer to a array of pointers.
     158                 :            :         */
     159                 :            :         std::list< rtl::OString > getSectionEntries(const rtl::OString& rSection )
     160                 :            :         {
     161                 :            :             std::list< rtl::OString > aEntries;
     162                 :            : 
     163                 :            :             // count buffer size necessary
     164                 :            :             int n = osl_getProfileSectionEntries( profile, rSection.getStr(), NULL, 0 );
     165                 :            :             if( n > 1 )
     166                 :            :             {
     167                 :            :                 sal_Char* pBuf = new sal_Char[ n+1 ];
     168                 :            :                 osl_getProfileSectionEntries( profile, rSection.getStr(), pBuf, n+1 );
     169                 :            :                 int nLen;
     170                 :            :                 for( n = 0; ( nLen = strlen( pBuf+n ) ); n += nLen+1 )
     171                 :            :                     aEntries.push_back( rtl::OString( pBuf+n ) );
     172                 :            :                 delete pBuf;
     173                 :            :             }
     174                 :            : 
     175                 :            :             return aEntries;
     176                 :            :         }
     177                 :            : 
     178                 :            :         /** Get all section entries
     179                 :            :             @return Pointer to a array of pointers.
     180                 :            :         */
     181                 :            :         std::list< rtl::OString > getSections()
     182                 :            :         {
     183                 :            :             std::list< rtl::OString > aSections;
     184                 :            : 
     185                 :            :             // count buffer size necessary
     186                 :            :             int n = osl_getProfileSections( profile, NULL, 0 );
     187                 :            :             if( n > 1 )
     188                 :            :             {
     189                 :            :                 sal_Char* pBuf = new sal_Char[ n+1 ];
     190                 :            :                 osl_getProfileSections( profile, pBuf, n+1 );
     191                 :            :                 int nLen;
     192                 :            :                 for( n = 0; ( nLen = strlen( pBuf+n ) ); n += nLen+1 )
     193                 :            :                     aSections.push_back( rtl::OString( pBuf+n ) );
     194                 :            :                 delete pBuf;
     195                 :            :             }
     196                 :            : 
     197                 :            :             return aSections;
     198                 :            :         }
     199                 :            :     };
     200                 :            : }
     201                 :            : 
     202                 :            : #endif  /* _OSL_PROFILE_HXX_ */
     203                 :            : 
     204                 :            : 
     205                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10