AlterOffice
AlterOffice 3.4 SDK C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
4 #ifndef INCLUDED_OSL_PROFILE_HXX
5 #define INCLUDED_OSL_PROFILE_HXX
6 
7 #include "osl/profile.h"
8 #include "rtl/ustring.hxx"
9 
10 #include <string.h>
11 #include <exception>
12 #include <list>
13 
14 namespace osl {
15 
17 
19  const int Profile_SYSTEM = osl_Profile_SYSTEM; /* use system depended functionality */
20  const int Profile_READLOCK = osl_Profile_READLOCK; /* lock file for reading */
21  const int Profile_WRITELOCK = osl_Profile_WRITELOCK; /* lock file for writing */
22 
26  class Profile {
27  oslProfile profile;
28 
29  public:
34  Profile(const rtl::OUString & strProfileName, oslProfileOption Options = Profile_DEFAULT )
35  {
36  profile = osl_openProfile(strProfileName.pData, Options);
37  if( ! profile )
38  throw std::exception();
39  }
40 
41 
45  {
46  osl_closeProfile(profile);
47  }
48 
49 
50  bool flush()
51  {
52  return osl_flushProfile(profile);
53  }
54 
55  rtl::OString readString( const rtl::OString& rSection, const rtl::OString& rEntry,
56  const rtl::OString& rDefault)
57  {
58  char aBuf[1024];
59  return osl_readProfileString( profile,
60  rSection.getStr(),
61  rEntry.getStr(),
62  aBuf,
63  sizeof( aBuf ),
64  rDefault.getStr() ) ? rtl::OString( aBuf ) : rtl::OString();
65 
66  }
67 
68  bool readBool( const rtl::OString& rSection, const rtl::OString& rEntry, bool bDefault )
69  {
70  return osl_readProfileBool( profile, rSection.getStr(), rEntry.getStr(), bDefault );
71  }
72 
73  sal_uInt32 readIdent(const rtl::OString& rSection, const rtl::OString& rEntry,
74  sal_uInt32 nFirstId, const std::list< rtl::OString >& rStrings,
75  sal_uInt32 nDefault)
76  {
77  size_t nItems = rStrings.size();
78  const char** pStrings = new const char*[ nItems+1 ];
79  std::list< rtl::OString >::const_iterator it = rStrings.begin();
80  nItems = 0;
81  while( it != rStrings.end() )
82  {
83  pStrings[ nItems++ ] = it->getStr();
84  ++it;
85  }
86  pStrings[ nItems ] = NULL;
87  sal_uInt32 nRet = osl_readProfileIdent(profile, rSection.getStr(), rEntry.getStr(), nFirstId, pStrings, nDefault);
88  delete[] pStrings;
89  return nRet;
90  }
91 
92  bool writeString(const rtl::OString& rSection, const rtl::OString& rEntry,
93  const rtl::OString& rString)
94  {
95  return osl_writeProfileString(profile, rSection.getStr(), rEntry.getStr(), rString.getStr());
96  }
97 
98  bool writeBool(const rtl::OString& rSection, const rtl::OString& rEntry, bool Value)
99  {
100  return osl_writeProfileBool(profile, rSection.getStr(), rEntry.getStr(), Value);
101  }
102 
103  bool writeIdent(const rtl::OString& rSection, const rtl::OString& rEntry,
104  sal_uInt32 nFirstId, const std::list< rtl::OString >& rStrings,
105  sal_uInt32 nValue)
106  {
107  size_t nItems = rStrings.size();
108  const char** pStrings = new const char*[ nItems+1 ];
109  std::list< rtl::OString >::const_iterator it = rStrings.begin();
110  nItems = 0;
111  while( it != rStrings.end() )
112  {
113  pStrings[ nItems++ ] = it->getStr();
114  ++it;
115  }
116  pStrings[ nItems ] = NULL;
117  bool bRet =
118  osl_writeProfileIdent(profile, rSection.getStr(), rEntry.getStr(), nFirstId, pStrings, nValue );
119  delete[] pStrings;
120  return bRet;
121  }
122 
128  bool removeEntry(const rtl::OString& rSection, const rtl::OString& rEntry)
129  {
130  return osl_removeProfileEntry(profile, rSection.getStr(), rEntry.getStr());
131  }
132 
137  std::list< rtl::OString > getSectionEntries(const rtl::OString& rSection )
138  {
139  std::list< rtl::OString > aEntries;
140 
141  // count buffer size necessary
142  size_t n = osl_getProfileSectionEntries( profile, rSection.getStr(), NULL, 0 );
143  if( n > 1 )
144  {
145  char* pBuf = new char[ n+1 ];
146  osl_getProfileSectionEntries( profile, rSection.getStr(), pBuf, n+1 );
147  size_t nLen;
148  for( n = 0; ; n += nLen+1 )
149  {
150  nLen = strlen( pBuf+n );
151  if (!nLen)
152  break;
153  aEntries.push_back( rtl::OString( pBuf+n ) );
154  }
155  delete[] pBuf;
156  }
157 
158  return aEntries;
159  }
160 
164  std::list< rtl::OString > getSections()
165  {
166  std::list< rtl::OString > aSections;
167 
168  // count buffer size necessary
169  size_t n = osl_getProfileSections( profile, NULL, 0 );
170  if( n > 1 )
171  {
172  char* pBuf = new char[ n+1 ];
173  osl_getProfileSections( profile, pBuf, n+1 );
174  size_t nLen;
175  for( n = 0; ; n += nLen+1 )
176  {
177  nLen = strlen( pBuf+n );
178  if (!nLen)
179  break;
180  aSections.push_back( rtl::OString( pBuf+n ) );
181  }
182  delete[] pBuf;
183  }
184 
185  return aSections;
186  }
187  };
188 }
189 
190 #endif // INCLUDED_OSL_PROFILE_HXX
191 
192 
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const int Profile_SYSTEM
Definition: profile.hxx:19
bool removeEntry(const rtl::OString &rSection, const rtl::OString &rEntry)
Remove an entry from a section.
Definition: profile.hxx:128
SAL_DLLPUBLIC sal_Bool osl_flushProfile(oslProfile Profile) SAL_COLD
Deprecated API.
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:182
SAL_DLLPUBLIC sal_Bool osl_writeProfileBool(oslProfile Profile, const char *pszSection, const char *pszEntry, sal_Bool Value) SAL_COLD
Deprecated API.
const char * getStr() const SAL_RETURNS_NONNULL
Returns a pointer to the characters of this string.
Definition: string.hxx:644
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:103
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.
const int Profile_DEFAULT
Definition: profile.hxx:18
SAL_DLLPUBLIC sal_Bool osl_readProfileBool(oslProfile Profile, const char *pszSection, const char *pszEntry, sal_Bool Default) SAL_COLD
Deprecated API.
SAL_DLLPUBLIC sal_uInt32 osl_getProfileSectionEntries(oslProfile Profile, const char *pszSection, char *pszBuffer, sal_uInt32 MaxLen) SAL_COLD
Deprecated API.
This String class provide base functionality for C++ like 8-Bit character array handling.
Definition: string.hxx:196
const int Profile_WRITELOCK
Definition: profile.hxx:21
SAL_DLLPUBLIC oslProfile osl_openProfile(rtl_uString *strProfileName, oslProfileOption Options) SAL_COLD
Deprecated API.
bool writeString(const rtl::OString &rSection, const rtl::OString &rEntry, const rtl::OString &rString)
Definition: profile.hxx:92
const int Profile_READLOCK
Definition: profile.hxx:20
SAL_DLLPUBLIC sal_Bool osl_writeProfileString(oslProfile Profile, const char *pszSection, const char *pszEntry, const char *pszString) SAL_COLD
Deprecated API.
pData
Definition: ustring.hxx:334
void * oslProfile
Definition: profile.h:26
std::list< rtl::OString > getSections()
Get all section entries.
Definition: profile.hxx:164
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.
bool flush()
Definition: profile.hxx:50
#define osl_Profile_DEFAULT
Definition: profile.h:19
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:73
std::list< rtl::OString > getSectionEntries(const rtl::OString &rSection)
Get all entries belonging to the specified section.
Definition: profile.hxx:137
rtl::OString readString(const rtl::OString &rSection, const rtl::OString &rEntry, const rtl::OString &rDefault)
Definition: profile.hxx:55
~Profile()
Close the opened profile an flush all data to the disk.
Definition: profile.hxx:44
#define osl_Profile_SYSTEM
Definition: profile.h:20
SAL_DLLPUBLIC sal_Bool osl_closeProfile(oslProfile Profile) SAL_COLD
Deprecated API.
sal_uInt32 oslProfileOption
Definition: profile.h:17
bool readBool(const rtl::OString &rSection, const rtl::OString &rEntry, bool bDefault)
Definition: profile.hxx:68
bool writeBool(const rtl::OString &rSection, const rtl::OString &rEntry, bool Value)
Definition: profile.hxx:98
Deprecated API.
Definition: profile.hxx:26
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.
#define osl_Profile_READLOCK
Definition: profile.h:21
oslProfileOption ProfileOption
Definition: profile.hxx:16
SAL_DLLPUBLIC sal_Bool osl_removeProfileEntry(oslProfile Profile, const char *pszSection, const char *pszEntry) SAL_COLD
Deprecated API.
SAL_DLLPUBLIC sal_uInt32 osl_getProfileSections(oslProfile Profile, char *pszBuffer, sal_uInt32 MaxLen) SAL_COLD
Deprecated API.
Profile(const rtl::OUString &strProfileName, oslProfileOption Options=Profile_DEFAULT)
Open or create a configuration profile.
Definition: profile.hxx:34
#define osl_Profile_WRITELOCK
Definition: profile.h:22