home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
tlx501.zip
/
SRC
/
PROFILE.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1996-07-08
|
2KB
|
78 lines
//----------------------------------------------------------------------------
// ObjectWindows
// (C) Copyright 1991, 1994 by Borland International, All Rights Reserved
//
// Implementation of TProfile class
//----------------------------------------------------------------------------
#include <tlx\501\_build.h>
TLX_MODULE_INFO("$Revision: 501.0 $");
#include <stdlib.h>
#include <tlx\501\profile.h>
#include <tlx\501\util.h>
#ifdef OS_WINXXX
#include <windows.h>
//
// Use system profile for filename==0
//
TProfile::TProfile(const char* section, const char* filename)
{
Section = section ? tlStrDup(section) : 0;
if (filename) {
OFSTRUCT ofs;
ofs.cBytes = sizeof ofs;
OpenFile(filename, &ofs, OF_EXIST);
FileName = tlStrDup(ofs.szPathName);
}
else
FileName = 0;
}
TProfile::~TProfile()
{
delete [] FileName;
delete [] Section;
}
int
TProfile::GetInt(const char* key, int defaultInt)
{
return FileName
? ::GetPrivateProfileInt(Section, key, defaultInt, FileName)
: ::GetProfileInt(Section, key, defaultInt);
}
//
// returns all section values if key==0
//
bool
TProfile::GetString(const char* key, char buff[], unsigned buffSize,
const char* defaultString)
{
return FileName
? ::GetPrivateProfileString(Section, key, defaultString, buff, buffSize, FileName)
: ::GetProfileString(Section, key, defaultString, buff, buffSize);
}
bool
TProfile::WriteInt(const char* key, int value)
{
char buf[16];
itoa(value, buf, 10);
return WriteString(key, buf);
}
bool
TProfile::WriteString(const char* key, const char* str)
{
return FileName
? ::WritePrivateProfileString(Section, key, str, FileName)
: ::WriteProfileString(Section, key, str);
}
#endif //OS_WINXXX