home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tlx501.zip / SRC / PROFILE.CPP < prev    next >
C/C++ Source or Header  |  1996-07-08  |  2KB  |  78 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // (C) Copyright 1991, 1994 by Borland International, All Rights Reserved
  4. //
  5. //   Implementation of TProfile class
  6. //----------------------------------------------------------------------------
  7.  
  8. #include <tlx\501\_build.h>
  9.  
  10. TLX_MODULE_INFO("$Revision: 501.0 $");
  11.  
  12. #include <stdlib.h>
  13.  
  14. #include <tlx\501\profile.h>
  15. #include <tlx\501\util.h>
  16.  
  17. #ifdef OS_WINXXX
  18. #include <windows.h>
  19.  
  20. //
  21. // Use system profile for filename==0
  22. //
  23. TProfile::TProfile(const char* section, const char* filename)
  24. {
  25.   Section = section ? tlStrDup(section) : 0;
  26.   if (filename) {
  27.     OFSTRUCT ofs;
  28.     ofs.cBytes = sizeof ofs;
  29.     OpenFile(filename, &ofs, OF_EXIST);
  30.     FileName = tlStrDup(ofs.szPathName);
  31.   }
  32.   else
  33.     FileName = 0;
  34. }
  35.  
  36. TProfile::~TProfile()
  37. {
  38.   delete [] FileName;
  39.   delete [] Section;
  40. }
  41.  
  42. int
  43. TProfile::GetInt(const char* key, int defaultInt)
  44. {
  45.   return FileName
  46.     ? ::GetPrivateProfileInt(Section, key, defaultInt, FileName)
  47.     : ::GetProfileInt(Section, key, defaultInt);
  48. }
  49.  
  50. //
  51. // returns all section values if key==0
  52. //
  53. bool
  54. TProfile::GetString(const char* key, char buff[], unsigned buffSize,
  55.                     const char* defaultString)
  56. {
  57.   return FileName
  58.     ? ::GetPrivateProfileString(Section, key, defaultString, buff, buffSize, FileName)
  59.     : ::GetProfileString(Section, key, defaultString, buff, buffSize);
  60. }
  61.  
  62. bool
  63. TProfile::WriteInt(const char* key, int value)
  64. {
  65.   char buf[16];
  66.   itoa(value, buf, 10);
  67.   return WriteString(key, buf);
  68. }
  69.  
  70. bool
  71. TProfile::WriteString(const char* key, const char* str)
  72. {
  73.   return FileName
  74.     ? ::WritePrivateProfileString(Section, key, str, FileName)
  75.     : ::WriteProfileString(Section, key, str);
  76. }
  77. #endif    //OS_WINXXX
  78.