IStringGenerator

The IStringGenerator class manages the translation of objects to their IString form. Use the IStringGenerator::stringFor member function to translate an object to its IString representation. Call it on an object-by-object basis. In the default case ( no IStringGeneratorFn ), the object should support the operator-> or be an Object*, where the Object class has an asString member function.

The IStringGenerator::stringFor member function processes as follows:

  1. If no IStringGeneratorFn object has been set (the default), then it uses an object's asString member function for translation.
  2. If an optional IStringGeneratorFn has been set, it uses the IStringGeneratorFn::stringFor member function.


Note: IStringGeneratorFn objects represent functions. Objects of the IStringGeneratorMemberFn and IStringGeneratorRefMemberFn classes represent member functions and differ in how they treat the object parameter in the stringFor member function.

Create and use IStringGenerator objects by following these steps:


Note: IStringGeneratorFn, as an abstract base class, establishes the protocol for specifying a function to translate an object to an IString. Inherit from this class and implement the stringFor member function to define the calling convention and call the stored function.


IStringGenerator - Member Functions and Data by Group

Constructors & Destructor

You can construct and destruct objects of this class. The copy constructor and operator= ensure that the contained generator function objects are reference-counted properly.


[view class]
~IStringGenerator
public:
virtual ~IStringGenerator()

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


[view class]
IStringGenerator

Use the constructor to create an instance of a string generator object.


Overload 1
public:
IStringGenerator( const ICountedPointerTo < IStringGeneratorFn < Element > >& generatorFunction = 0 )

You create a string generator object using an optional IStringGeneratorFn.

generatorFunction
A pointer (ICountedPointerTo) to an existing IStringGeneratorFn subclass object. If it is specified, subsequent calls to stringFor will use this function to produce strings for the given object.

If you do not specify a generator function, calls to stringFor will return an empty string.

If you want the same behavior as was provided by IBase::asString() in previous releases of Open Class Library, then you should specify an ICountedPointerTo pointer to an instance of IStringGeneratorasString for this parameter.
Note: The pointer object (ICountedPointerTo) ensures the generator function is reference counted properly.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


Overload 2
public:
IStringGenerator( const IStringGenerator < Element >& stringGenerator )

You can create a string generator object using another IStringGenerator. This ensures that the reference-counting of the IStringGeneratorFn object is done properly.

stringGenerator
A string generator.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


[view class]
operator =
public:
IStringGenerator < Element >& operator =( const IStringGenerator < Element >& stringGenerator )

Assign one string generator to another. This ensures that the reference-counting of the IStringGeneratorFn object is done properly.

stringGenerator
A string generator.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


Generate String

Use this member to translate an object to its IString form.


[view class]
stringFor
public:
IString stringFor(const Element& element) const

Obtains an IString version of the element. If a local IStringGeneratorFn has been set, then it is used. Otherwise, the element's asString member function generates the IString.

element
Reference to the object for which it generates the string.
Note: For the default case (no IStringGeneratorFn), the element should natively support operator-> or the element must be an Object*, where the Object class has an asString member function.

IStringGeneratorRefMemberFn and IStringGeneratorMemberFn (IStringGeneratorFn derived classes) contain member functions that take no parameters. They support invoking these member functions on Object* elements (element is a pointer) and concrete Object elements (element is not a pointer), respectively. If you need additional string generation support, create your own IStringGeneratorFn derived class.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


IStringGenerator - Inherited Member Functions and Data

Inherited Public Functions

Inherited Public Data

Inherited Protected Functions

Inherited Protected Data