ACF $AcfVersion:0$
Public Types | Public Member Functions | List of all members
istd::IFactoryInfo Class Referenceabstract

Base interface providing information about factory-producible objects. More...

#include <IFactoryInfo.h>

Inheritance diagram for istd::IFactoryInfo:
istd::IPolymorphic istd::TIFactory< icomp::IComponent > istd::TIFactory< InterfaceType > istd::TIFactory< InterfaceClass > istd::TInterfaceFactory< Interface > istd::TIFactory< Interface > istd::TInterfaceFactory< InterfaceType > icomp::TSimComponentsFactory< Base > istd::TComposedFactory< InterfaceType > icomp::TFactoryMember< Interface > istd::TComposedFactory< Interface > i2d::CObject2dFactory iattr::CStandardAttributesFactory istd::TSingleFactory< Interface, Implementation > ibase::TComposedFactoryComp< Interface >

Public Types

typedef QSet< QByteArray > KeyList
 

Public Member Functions

virtual KeyList GetFactoryKeys () const =0
 Returns all possible keys for this factory.
 
- Public Member Functions inherited from istd::IPolymorphic
virtual ~IPolymorphic ()
 

Detailed Description

Base interface providing information about factory-producible objects.

Purpose

IFactoryInfo is part of the ACF factory pattern implementation. It provides metadata about objects that can be created by factory classes, specifically the keys (identifiers) that can be used to instantiate different types of objects through the factory.

Usage Context

This interface is typically implemented by factory classes to advertise which object types they can create. The keys returned by GetFactoryKeys() serve as identifiers that clients can use with the factory's CreateInstance() or similar methods.

Example

// Factory interface for creating shapes
class IShapeFactory: virtual public istd::IFactoryInfo
{
public:
virtual IShape* CreateShape(const QByteArray& shapeType) = 0;
};
// Concrete factory implementation
class CShapeFactory: public IShapeFactory
{
public:
// Reimplemented from IFactoryInfo
virtual KeyList GetFactoryKeys() const override
{
KeyList keys;
keys.insert("circle");
keys.insert("rectangle");
keys.insert("triangle");
keys.insert("polygon");
return keys;
}
virtual IShape* CreateShape(const QByteArray& shapeType) override
{
if (shapeType == "circle") {
return new CCircle();
} else if (shapeType == "rectangle") {
return new CRectangle();
} else if (shapeType == "triangle") {
return new CTriangle();
} else if (shapeType == "polygon") {
return new CPolygon();
}
return nullptr;
}
};
// Usage example
CShapeFactory factory;
// Query available shape types
IFactoryInfo::KeyList availableShapes = factory.GetFactoryKeys();
for (const QByteArray& shapeType : availableShapes) {
qDebug() << "Factory can create:" << shapeType;
}
// Create shapes using the factory
if (availableShapes.contains("circle")) {
IShape* circle = factory.CreateShape("circle");
// Use the circle...
delete circle;
}
Base interface providing information about factory-producible objects.
QSet< QByteArray > KeyList

Key Format

Factory keys are QByteArray values that uniquely identify object types within the factory. The format and naming convention for keys is typically defined by the specific factory implementation, but common practices include:

See also
istd::IFactory, istd::TIFactory

Definition at line 98 of file IFactoryInfo.h.

Member Typedef Documentation

◆ KeyList

typedef QSet<QByteArray> istd::IFactoryInfo::KeyList

Definition at line 101 of file IFactoryInfo.h.

Member Function Documentation

◆ GetFactoryKeys()

virtual KeyList istd::IFactoryInfo::GetFactoryKeys ( ) const
pure virtual

Returns all possible keys for this factory.

Retrieves the complete set of keys (identifiers) that this factory can use to create objects. Each key corresponds to a specific object type or variant that the factory knows how to instantiate.

Returns
A QSet containing all valid factory keys. The set may be empty if the factory cannot currently create any objects, but typically contains at least one key for factories that are properly configured.
Note
The returned set represents a snapshot of available keys at the time of the call. For dynamic factories, the available keys may change over time (e.g., through plugin loading).
Keys are typically case-sensitive QByteArray values. Clients should use exact string matching when working with factory keys.
// Example usage
IFactoryInfo* factory = GetFactory();
// Check if a specific type is available
if (keys.contains("mytype")) {
// Create object using "mytype" key
}
// List all available types
for (const QByteArray& key : keys) {
qDebug() << "Available type:" << key;
}
virtual KeyList GetFactoryKeys() const =0
Returns all possible keys for this factory.
See also
istd::IFactory::CreateInstance()

Implemented in i2d::CObject2dFactory, iattr::CStandardAttributesFactory, icomp::TFactoryMember< Interface >, icomp::TSimComponentsFactory< Base >, istd::TComposedFactory< InterfaceType >, istd::TComposedFactory< Interface >, and istd::TSingleFactory< Interface, Implementation >.


The documentation for this class was generated from the following file: