Jump to content

KrProfile: Difference between revisions

From EDM2
Ak120 (talk | contribs)
mNo edit summary
 
(4 intermediate revisions by 2 users not shown)
Line 2: Line 2:
'''#include "krprof.hpp"'''
'''#include "krprof.hpp"'''


Using this class, you can read and write data from/to os2.ini, os2sys.ini, or any other OS/2 style ini file that you choose, using the common << and >> operators.  
Using this class, you can read and write data from/to os2.ini, os2sys.ini, or any other OS/2 style ini file that you choose, using the common << and >> operators.


==Derivation ==
==Derivation ==
Line 17: Line 17:
Use this constructor to open the system ini file aProfile for reading and writing data of the application which is identified by the name aApp in the ini file.  
Use this constructor to open the system ini file aProfile for reading and writing data of the application which is identified by the name aApp in the ini file.  


By default, the object acts like a unit-buffered iostream, i.e. you can simply do your input output using the operators << and >>. If you want to avoid the slight overhead created by unit-buffering, and you want full buffering instead, set iBuffered=true If you do so, however, don't forget that you are now responsible for flushing the stream yourself using the manipulator flush.  
By default, the object acts like a unit-buffered iostream, i.e. you can simply do your input output using the operators << and >>. If you want to avoid the slight overhead created by unit-buffering, and you want full buffering instead, set iBuffered=true If you do so, however, don't forget that you are now responsible for flushing the stream yourself using the manipulator flush.
 


'''Overload 2'''   
'''Overload 2'''   
Line 25: Line 24:
           Boolean iBuffered = false);
           Boolean iBuffered = false);


This is identical to overload 1, except that aProfile is now not neccessarily a system ini file, but the file name of any ini file. If it doesn't already exist, this constructor creates this ini file.  
This is identical to overload 1, except that aProfile is now not necessarily a system ini file, but the file name of any ini file. If it doesn't already exist, this constructor creates this ini file.


==Public Functions==
==Public Functions==
===Application control===  
===Application control===  
====exists====  
====exists====  
Line 50: Line 48:
           Boolean iBuffered = false);  
           Boolean iBuffered = false);  


Use this constructor to open the system ini file aProfile for reading and writing data of the application which is identified by the name aApp in the ini file.
Use this constructor to open the system ini file aProfile for reading and writing data of the application which is identified by the name aApp in the ini file.
 
By default, the object acts like a unit-buffered iostream, i.e. you can simply do your input output using the operators << and >>. If you want to avoid the slight overhead created by unit-buffering, and you want full buffering instead, set iBuffered=true If you do so, however, don't forget that you are now responsible for flushing the stream yourself using the manipulator flush.  


By default, the object acts like a unit-buffered iostream, i.e. you can simply do your input output using the operators << and >>. If you want to avoid the slight overhead created by unit-buffering, and you want full buffering instead, set iBuffered=true If you do so, however, don't forget that you are now responsible for flushing the stream yourself using the manipulator flush.


'''Overload 2'''   
'''Overload 2'''   
Line 60: Line 57:
           Boolean iBuffered = false);
           Boolean iBuffered = false);


This is identical to overload 1, except that aProfile is now not neccessarily a system ini file, but the file name of any ini file. If it doesn't already exist, this constructor creates this ini file.  
This is identical to overload 1, except that aProfile is now not necessarily a system ini file, but the file name of any ini file. If it doesn't already exist, this constructor creates this ini file.  
====~KrProfile====  
====~KrProfile====  
  public:  
  public:  
Line 67: Line 64:
===I/O functions===  
===I/O functions===  
====clearBuffer ====
====clearBuffer ====
Do not use this function, since it might become private in a later version. Use the manipulator clear instead.  
Do not use this function, since it might become private in a later version. Use the manipulator clear instead.
 
  public:  
  public:  
  void clearBuffer ();  
  void clearBuffer ();  
====readData ====
====readData ====
This function appends the contents of the ini file associated to the current key to the stream. Its direct use may be confusing; it is recommended to use the >> operator instead, which will call this function only when neccessary. This function may become private in a later version.  
This function appends the contents of the ini file associated to the current key to the stream. Its direct use may be confusing; it is recommended to use the >> operator instead, which will call this function only when necessary. This function may become private in a later version.
 
  public:  
  public:  
  virtual void readData ();  
  virtual void readData ();  
Line 133: Line 128:
             user ini file.
             user ini file.


==Manipulators==
===Key control===
====clear====
Use this manipulator to clear the stream. This is necessary if you have already read from or written to the stream, but want to discard that data and write completely new data to that key instead of appending to the old data.


public:
KrProfile & clear (KrProfile & aProfile);
====flush====
Use this manipulator to flush the stream. This is only necessary if you have constructed the KrProfile object as a fully buffered stream.


 
public:
==Manipulators ==
KrProfile & flush (KrProfile & aProfile); 
 
===Key control===
====clear====
====flush====


===Stream handling===  
===Stream handling===  
====remove====  
====remove====  
This manipulator is a convenient way to call removeKey.
public:
KrProfile & remove (KrProfile & aProfile);


[[Category:The OS/2 API Project]]
[[Category:Kronis Classes]]

Latest revision as of 03:05, 2 March 2018

Description

#include "krprof.hpp"

Using this class, you can read and write data from/to os2.ini, os2sys.ini, or any other OS/2 style ini file that you choose, using the common << and >> operators.

Derivation

KrProfile inherits from iostream. It also inherits from the non-public class _KrProfileBase, but this is only for technical reasons.

Constructors

You can construct and destruct objects of this class.

Overload 1

public: 
KrProfile (const IString & aApp, profile aProfile = user, 
          Boolean iBuffered = false); 

Use this constructor to open the system ini file aProfile for reading and writing data of the application which is identified by the name aApp in the ini file.

By default, the object acts like a unit-buffered iostream, i.e. you can simply do your input output using the operators << and >>. If you want to avoid the slight overhead created by unit-buffering, and you want full buffering instead, set iBuffered=true If you do so, however, don't forget that you are now responsible for flushing the stream yourself using the manipulator flush.

Overload 2

public:
KrProfile (const IString & aApp, const IString & aProfile,
          Boolean iBuffered = false);

This is identical to overload 1, except that aProfile is now not necessarily a system ini file, but the file name of any ini file. If it doesn't already exist, this constructor creates this ini file.

Public Functions

Application control

exists

Returns true if any data of the application already exists in the ini file, and false otherwise.

public: 
Boolean exists (); 

removeApp

Removes all data of the application from the ini file.

public: 
void removeApp (); 

Constructors

KrProfile

You can construct and destruct objects of this class.

Overload 1

public: 
KrProfile (const IString & aApp, profile aProfile = user, 
         Boolean iBuffered = false); 

Use this constructor to open the system ini file aProfile for reading and writing data of the application which is identified by the name aApp in the ini file.

By default, the object acts like a unit-buffered iostream, i.e. you can simply do your input output using the operators << and >>. If you want to avoid the slight overhead created by unit-buffering, and you want full buffering instead, set iBuffered=true If you do so, however, don't forget that you are now responsible for flushing the stream yourself using the manipulator flush.

Overload 2

public:
KrProfile (const IString & aApp, const IString & aProfile,
          Boolean iBuffered = false);

This is identical to overload 1, except that aProfile is now not necessarily a system ini file, but the file name of any ini file. If it doesn't already exist, this constructor creates this ini file.

~KrProfile

public: 
~KrProfile (); 

I/O functions

clearBuffer

Do not use this function, since it might become private in a later version. Use the manipulator clear instead.

public: 
void clearBuffer (); 

readData

This function appends the contents of the ini file associated to the current key to the stream. Its direct use may be confusing; it is recommended to use the >> operator instead, which will call this function only when necessary. This function may become private in a later version.

public: 
virtual void readData (); 

writeData

Do not use this function, since it might become private in a later version. Use the manipulator flush instead.

public: 
virtual void writeData (Boolean callFromBuff); 

Key control

existsKey

Returns true if any data associated to the current key already exists in the ini file, and false otherwise.

public: 
Boolean existsKey (); 

key

Returns the currently set key.

public: 
IString & key (); 

removeKey

Removes all data associated to the currently set key from the ini file.

public: 
void removeKey ();  

setKey

Clears the stream and sets a new key. Before setKey is called for the first time, the key "Default" is set.

public: 
void setKey (const IString & aKey = "Default"); 

Retrieving information

good

Returns true if the ini file was successfully opened, and false otherwise.

public: 
Boolean good (); 

size

Returns the number of bytes currently stored in the ini file under the current key.

public: 
long size ();

Enumerations

Profile

public: enum profile { system, user, both };

If a system ini file is to be opened, a member of this enumeration should be passed to the constructor. These are their meanings:


system     Read and write to the OS/2 system ini file
           (usually called os2sys.ini)
user       Read and write to the OS/2 user ini file (usually
           called os2.ini)
both       Read from both above ini files, write to the OS/2
           user ini file.

Manipulators

Key control

clear

Use this manipulator to clear the stream. This is necessary if you have already read from or written to the stream, but want to discard that data and write completely new data to that key instead of appending to the old data.

public: 
KrProfile & clear (KrProfile & aProfile); 

flush

Use this manipulator to flush the stream. This is only necessary if you have constructed the KrProfile object as a fully buffered stream.

public: 
KrProfile & flush (KrProfile & aProfile);  

Stream handling

remove

This manipulator is a convenient way to call removeKey.

public:
KrProfile & remove (KrProfile & aProfile);