home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
IBMCLASS
/
IPROFILE.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-22
|
14KB
|
272 lines
#ifndef _IPROFILE_
#define _IPROFILE_
/*******************************************************************************
* FILE NAME: iprofile.hpp *
* *
* DESCRIPTION: *
* This file contains the declaration(s) of the class(es): *
* IProfile - Class providing interface to OS/2 .ini files. *
* *
* COPYRIGHT: *
* Licensed Materials - Property of IBM *
* (C) Copyright IBM Corporation 1992, 1993 *
* All Rights Reserved *
* US Government Users Restricted Rights - Use, duplication, or *
* disclosure *
* restricted by GSA ADP Schedule Contract with IBM Corp. *
* *
*******************************************************************************/
#ifndef _IVBASE_
#include <ivbase.hpp>
#endif
#ifndef _IHANDLE_
#include <ihandle.hpp>
#endif
#ifndef _ISTRING_
#include <istring.hpp>
#endif
/*----------------------------------------------------------------------------*/
/* Align classes on four byte boundary. */
/*----------------------------------------------------------------------------*/
#pragma pack(4)
class IProfile : public IVBase {
typedef IVBase
Inherited;
/*******************************************************************************
| The IProfile class's objects represent profile data sets (.ini files). |
| They provide functions to query and set persistent application data based |
| on application-defined keys. |
| |
| The profile data set stores information by two keys. The first key is the |
| application name, which is stored as a string. The second key is the key |
| name, which is stored as either a string or an integer. Profile data can |
| be stored as text, binary and integer by the keys. |
| |
| Example: |
| |
| IProfile* pProf = new IProfile("MySystem"); |
| pProf->setDefaultApplicationName("MyApp"); |
| |
| //To write data |
| pProf->addOrReplaceElementWithKey("My_Name", //key is My_Name |
| "Kevin"); //text data |
| pProf->addOrReplaceElementWithKey("My_Age", //key is My_Age |
| 25); //integer data |
| //To read data |
| IString myName = pProf->elementWithKey("My_Name"); //read text date |
| long myAge = pProf->integerWithKey("My_Name"); //read text date |
*******************************************************************************/
public:
/*------------------------- Constructors/Destructor ----------------------------
| You can construct instances of this class from the name of the profile data |
| set. |
| |
| NOTE: You can only open six data sets at one time. This is a system |
| restriction. |
------------------------------------------------------------------------------*/
IProfile ( const char *profileName );
IProfile ( const IProfile& aProfile );
virtual
~IProfile ( );
/*-------------------------------- Assignment ----------------------------------
| This operator is used for assignment: |
| operator = - Assignment operator used to track references to the resource. |
------------------------------------------------------------------------------*/
IProfile
&operator = ( const IProfile &aProfile );
/*----------------------------- Special Profiles -------------------------------
There are two special instances of this class corresponding to the "system"
and "user" profiles. These objects are obtained using the following static
functions:
systemProfile - Returns the system profile.
userProfile - Returns the user profile.
------------------------------------------------------------------------------*/
static IProfile
systemProfile ( ),
userProfile ( );
/*-------------------------------- Accessors -----------------------------------
| These functions provide a means of getting the profile information of |
| instances of this class: |
| name - Returns the profile file name. |
| handle - Returns the profile handle. |
| numberOfKeys - Returns the number of keys for the application |
| name. |
| numberOfApplications - Returns the number of application names in the |
| profile. |
------------------------------------------------------------------------------*/
IString
name ( ) const;
IProfileHandle
handle() const;
unsigned long
numberOfKeys ( const char *applName = 0 ) const,
numberOfApplications ( ) const;
/*----------------------------- Application Name -------------------------------
| These functions control the default "application name" component of the |
| keys used to access the profile. This application name will be used by |
| default for all reads and writes to the profile. |
| defaultApplicationName - Returns the current default application name. |
| setDefaultApplicationName - Sets the default application name. All |
| subsequent calls with a null application name |
| will use this default name. |
------------------------------------------------------------------------------*/
const IString&
defaultApplicationName ( ) const;
IProfile
&setDefaultApplicationName ( const char *applName );
/*----------------------------- Reading/Writing --------------------------------
| The following function read and write application data for a given |
| appName/keyName: |
| elementWithKey - Reads the application data and returns it |
| as an IString. |
| integerWithKey - Reads the application data and returns it |
| as a long integer. |
| addOrReplaceElementWithKey - Writes the argument number, text or binary |
| data. Text and binary is passed as |
| IString. |
| deleteElementWithKey - Removes the data at a given application |
| and key pair. |
| deleteElementWithApplication - Removes data for all keys for the argument |
| application name. |
------------------------------------------------------------------------------*/
IString
elementWithKey ( const char *key,
const char *applName = 0 ) const;
long
integerWithKey ( const char *key,
const char *applName = 0 ) const;
IProfile
&addOrReplaceElementWithKey ( const char *key,
const IString& data,
const char *applName = 0 ),
&addOrReplaceElementWithKey ( const char *key,
long data,
const char *applName = 0 );
IProfile
&deleteElementWithKey ( const char *key,
const char *applName = 0 ),
&deleteElementWithApplication ( const char *applName = 0 );
/*--------------------------------- Testing ------------------------------------
| The following functions test whether a given application name and/or key |
| exist in the profile: |
| containsApplication - Returns true if the profile contains data for the |
| argument application name. |
| containsKeyName - Returns true if the profile contains data for the |
| argument application and key pair. |
------------------------------------------------------------------------------*/
Boolean
containsApplication ( const char *applName ) const,
containsKeyName ( const char *key,
const char *applName = 0 ) const;
class Cursor : public IVBase {
/*******************************************************************************
* The IProfile::Cursor nested class is used to iterate over the appliction *
* names or keys in a profile. *
*******************************************************************************/
public:
/*-------------------------- Constructor/Destructor ----------------------------
| You can construct an instance of IProfile::Cursor for the following |
| purposes: |
| - To create a cursor to iterate over the application names. This |
| instance is constructed from a reference to the profile. |
| - To create a cursor to iterate over the keys. This instance is |
| constructed from a reference to the profile with an application name. |
| |
| NOTE: The cursor object is invalidated to the current state of application |
| names or key names in the profile file. |
------------------------------------------------------------------------------*/
Cursor ( IProfile &profile);
Cursor ( IProfile &profile,
const char *applName);
~Cursor ( );
/*-------------------------------- Overrides -----------------------------------
| The nested Cursor class overrides the following functions to |
| provide the appropriate cursor behavior: |
| setToFirst - Resets the position to the first application or key. |
| setToNext - Advances the position to the next application or key. |
| setToPrevious - Backs up the position to the previous application or key. |
| setToLast - Sets the position to the last application or key. |
| isValid - Returns true if the cursor is not off the end. If |
| checkFile is set to true, isValid checks to see if the |
| file application and key information has been changed by |
| another application while your application still has it |
| open. |
| invalidate - Marks the cursor as invalid. |
------------------------------------------------------------------------------*/
Boolean
setToFirst ( ),
setToNext ( ),
setToPrevious ( ),
setToLast ( ),
isValid ( Boolean checkFile = false ) const;
void
invalidate ( );
private: /*------------------------ PRIVATE ----------------------------------*/
unsigned
pos;
IString
strCl,
applNameCl;
IProfileHandle
hProfileCl;
void
initCursor ( const IProfileHandle &hProfile,
const char *appName );
friend class IProfile;
}; //Cursor
/*---------------------- Enumerating Applications/Keys -------------------------
applicationOrKeyAt - Returns the application name or key at the argument
cursor.
------------------------------------------------------------------------------*/
IString
applicationOrKeyAt ( const Cursor &cursor ) const;
/*------------------------ PRIVATE ----------------------------------*/
private:
IProfile ( const IProfileHandle& profile );
unsigned long
length( const char *keyName,
const char *applName = 0 ) const;
IProfileHandle
hIni;
IString
defApplName,
profileName;
}; // class IProfile
/*----------------------------------------------------------------------------*/
/* Resume compiler default packing. */
/*----------------------------------------------------------------------------*/
#pragma pack()
#ifndef I_NO_INLINES
#include <iprofile.inl>
#endif
#endif // _IPROFILE_