home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / cppbeta / ibmcli / iprofmgr.hp_ / IPROFMGR.HPP
Encoding:
C/C++ Source or Header  |  1992-10-26  |  9.1 KB  |  174 lines

  1. #ifndef _IPROFMGR_
  2. #define _IPROFMGR_
  3. /*******************************************************************************
  4. * FILE NAME: IPROFMGR.HPP                                                      *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   Declaration of the class(es):                                              *
  8. *     IProfileMgr - Manages the .INI files.                                    *
  9. *                                                                              *
  10. * COPYRIGHT:                                                                   *
  11. *   (C) Copyright IBM Corporation 1992                                         *
  12. *   All Rights Reserved                                                        *
  13. *   Licensed Materials * Property of IBM                                       *
  14. *                                                                              *
  15. * HISTORY:                                                                     *
  16. *$Log:   R:/IBMCLASS/IBASEAPP/VCS/IPROFMGR.HPV  $                                                                         *
  17. // 
  18. //    Rev 1.3   25 Oct 1992 16:58:40   nunn
  19. // changed library name to ICLUI
  20. // 
  21. //    Rev 1.2   24 Oct 1992 17:38:50   tsuji
  22. // Format/documentation in the style of the standard header (by Tim Hertz).
  23. *******************************************************************************/
  24. #ifndef _IVBASE_
  25.   #include <ivbase.hpp>
  26. #endif
  27. #ifndef _IHANDLE_
  28.   #include <ihandle.hpp>
  29. #endif
  30.  
  31. // Forward declarations for other classes:
  32. class IString;
  33.  
  34. const unsigned long IC_PROFILE = 0;
  35. const unsigned long IC_USERPROFILE = -1;
  36. const unsigned long IC_SYSTEMPROFILE = -2;
  37.  
  38. class IProfileMgr : public IVBase
  39. /*******************************************************************************
  40. * This class encapsulates the OS/2 profile management functions.               *
  41. *                                                                              *
  42. * The profile stores information using two keys.  The major key is called the  *
  43. * application name or "appName".  The minor key is called the key name or      *
  44. * "keyName".  The appName must be set before using any call that requires      *
  45. * a keyName.  The appName is set by using the setAppName call.  The keyName    *
  46. * is passed in to all the calls that need it.                                  *
  47. *                                                                              *
  48. * EXAMPLE:                                                                     *
  49. *    pProfMgr = new IProfileMgr;                                               *
  50. *    pProfMgr->setAppName("My_Profile_Options");                               *
  51. *                                                                              *
  52. *    // To write information into the profile                                  *
  53. *    pProfMgr->write("My_Name", "Tim");                                        *
  54. *    pProfMgr->write("My_Age", 25);                                            *
  55. *                                                                              *
  56. *    // To read information from the profile                                   *
  57. *    IString Name=pProfMgr->readText("My_Name");                               *
  58. *    long Age = pProfMgr->readInteger("My_Age");                               *
  59. *******************************************************************************/
  60. {
  61. public:
  62. /*------------------------ CONSTRUCTORS/DESTRUCTORS ----------------------------
  63. | There are 4 ways to construct instances of this class:                       |
  64. |   1. default                                                                 |
  65. |     Constructs a profile manager that allows reading from both the user and  |
  66. |     the system profiles, and writes to the user profile.                     |
  67. |   2. IC_USERPROFILE                                                          |
  68. |     Constructs a profile manager that reads and writes to the user profile.  |
  69. |   3. IC_SYSTEMPROFILE                                                        |
  70. |     Constructs a profile manager that reads and writes to the system profile.|
  71. |   4. Filename                                                                |
  72. |     Constructs a profile manager that reads and writes to an application     |
  73. |     profile.  The file is created if it doesn't already exist.               |
  74. ------------------------------------------------------------------------------*/
  75.    IProfileMgr    (IProfileHandle hini = (IProfileHandle)IC_PROFILE,
  76.                    const char* pszFileName = 0);
  77. virtual
  78.    ~IProfileMgr   ();
  79.  
  80. /*-------------------------- SETTING THE APPNAME -------------------------------
  81. | This method sets the application name.  The application name is the first    |
  82. | key of two needed to access information in the profile.  The second key is   |
  83. | the keyname which is specified on each call that needs it.                   |
  84. |    setAppName - Sets the AppName to use on all the following calls.          |
  85. ------------------------------------------------------------------------------*/
  86. void
  87.    setAppName     (const char* pszAppName);
  88.  
  89. /*-------------------------- WRITING INFORMATION -------------------------------
  90. | These functions provide ways to write information into the profile.  The     |
  91. | information can be in the form of a string, number, or binary data.          |
  92. |    write - Write information into the profile.                               |
  93. ------------------------------------------------------------------------------*/
  94. void
  95.    write          (const char* pszKeyName,
  96.                    const char* pszText),
  97.    write          (const char* pszKeyName,
  98.                    long lNumber),
  99.    write          (const char* pszKeyName,
  100.                    const void* pvData,
  101.                    unsigned long ulDataLen);
  102.  
  103.  
  104. /*-------------------------- PROFILE ENTRY INFORMATION -------------------------
  105. | These functions get information about a specific profile entry.              |
  106. |    length - returns the length (in bytes) of the data stored.                |
  107. |    doesKeyNameExist - returns TRUE if an entry exists for the keyName.       |
  108. ------------------------------------------------------------------------------*/
  109. unsigned long
  110.    length         (const char* pszKeyName) const;
  111.  
  112. Boolean
  113.    doesKeyNameExist   (const char* pszKeyName) const;
  114.  
  115. /*-------------------------- READ INFORMATION ----------------------------------
  116. | These functions read information from the profile.                           |
  117. |    readText - reads the information as a string.                             |
  118. |    readInteger - reads the information as an integer.                        |
  119. |    readBinary - reads the information as binary data.                        |
  120. ------------------------------------------------------------------------------*/
  121. IString
  122.    readText       (const char* pszKeyName) const;
  123.  
  124. long
  125.    readInteger    (const char* pszKeyName) const;
  126.  
  127. void*
  128.    readBinary     (const char* pszKeyName,
  129.                    void* pvData = 0,
  130.                    unsigned long ulBufSize = 0) const;
  131.  
  132. /*-------------------------- DELETE INFORMATION --------------------------------
  133. | These functions delete information from the profile.                         |
  134. |    deleteKey - Removes a key from the profile.                               |
  135. |    deleteAllKeys - Removes all the keys in the AppName.                      |
  136. ------------------------------------------------------------------------------*/
  137. void
  138.    deleteKey      (const char* pszKeyName),
  139.    deleteAllKeys  ();
  140.  
  141. /*-------------------------- LIST INFORMATION ----------------------------------
  142. | These functions return a list of keys from the profile.                      |
  143. |    appNames - Returns a string containing all the appNames in the profile.   |
  144. |    keyNames - Returns a string containing all the keyNames in the profile.   |
  145. ------------------------------------------------------------------------------*/
  146. IString
  147.    appNames                () const,
  148.    keyNames                () const;
  149.  
  150. /*-------------------------- PROFILE NAME --------------------------------------
  151. | These functions return the names of the files used for the user and system   |
  152. | profiles.                                                                    |
  153. |    userProfileName - Returns the file name of the user profile.              |
  154. |    systemProfileName - Returns the file name of the system profile.          |
  155. ------------------------------------------------------------------------------*/
  156. IString
  157.    userProfileName         () const,
  158.    systemProfileName       () const;
  159.  
  160. private:
  161. /*------------------------------ DATA MEMBERS ----------------------------------
  162. |  pszClAppName - The application name to use.                                 |
  163. |  hiniCl - The handle of the profile being used.                              |
  164. ------------------------------------------------------------------------------*/
  165. char*
  166.    pszClAppName;
  167.  
  168. IProfileHandle
  169.    hiniCl;
  170.  
  171. };
  172.  
  173. #endif
  174.