home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / owlsrc.pak / PROFILE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-24  |  1.7 KB  |  68 lines

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