[KLF Application][KLF Tools][KLF Backend][KLF Home]
KLatexFormula Project
Public Member Functions

KLFFactoryManager Class Reference

A base abstract factory manager class. More...

#include <klffactory.h>

Collaboration diagram for KLFFactoryManager:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 KLFFactoryManager ()
virtual ~KLFFactoryManager ()
KLFFactoryBasefindFactoryFor (const QString &objType)
QStringList allSupportedTypes ()
QList< KLFFactoryBase * > registeredFactories ()

Detailed Description

A base abstract factory manager class.

An abstract class that provides base common functions for factories of different kinds.

A Factory is a class that can instantiate another class of given types. For example, you may have a factory that can create objects of the correct sub-class of KLFLibResourceEngine depending on the URL to open. Multiple factories can be installed, each capable of opening one or more subtypes of the given object, a library resource in our example.

Factories need to be explicitely registered and unregistered, they are done so in the KLFFactoryBase constructor and destructor.

The usage of KLFFactoryManager and KLFFactoryBase is for example:

  // in .h:
  class MyFactory : public KLFFactoryBase {
  public:
    MyFactory() : KLFFactoryBase(&pFactoryManager) { }

    virtual QStringList supportedTypes() const { ..... }

    ... virtual MyObject * createMyObject(const QString& ofThisObjectType) = 0; ...

    ...

    MyFactory * findFactoryFor(...) {
      return dynamic_cast<MyFactory*>(pFactoryManager.findFactoryFor(...));
    }

  private:
    static KLFFactoryManager pFactoryManager;
  };

  // in .cpp:
  KLFFactoryManager MyFactory::pFactoryManager ;

Definition at line 90 of file klffactory.h.


Constructor & Destructor Documentation

KLFFactoryManager::KLFFactoryManager ( )

Constructor. does nothing

Definition at line 40 of file klffactory.cpp.

KLFFactoryManager::~KLFFactoryManager ( ) [virtual]

Destructor. This function unregisters the factory.

Definition at line 43 of file klffactory.cpp.


Member Function Documentation

QStringList KLFFactoryManager::allSupportedTypes ( )

Returns a combined list of all object types all registered factories combined support. (ie. a list of all object types we're capable of instantiating)

Definition at line 62 of file klffactory.cpp.

References QList::size().

KLFFactoryBase * KLFFactoryManager::findFactoryFor ( const QString objType)

Returns the first factory in registered factory list that is capable of creating an object of type objType.

Definition at line 47 of file klffactory.cpp.

References QStringList::contains(), QList::size(), and KLFFactoryBase::supportedTypes().

QList<KLFFactoryBase*> KLFFactoryManager::registeredFactories ( ) [inline]

Returns a list of all registered factories.

Definition at line 106 of file klffactory.h.


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

Generated by doxygen 1.7.3