ALPS Home Libraries License Support People ALPS Web Site

PrevUpHomeNext

Class template factory

alps::factory

Synopsis

// In header: <alps/factory.h>

template<typename KEY, typename BASE> 
class factory {
public:
  // types
  typedef BASE base_type;  // the type of the base class from which all objects created by the factory are derived 
  typedef KEY  key_type;   // the type of the key used to identify derived classes 

  // construct/copy/destruct
  factory();
  ~factory();

  // public member functions
  template<typename T> bool register_type(key_type);
  bool unregister_type(key_type);
  base_type * create(key_type) const;
};

Description

a factory class

factory public construct/copy/destruct

  1. factory();
    there is only a default constructor
  2. ~factory();

factory public member functions

  1. template<typename T> bool register_type(key_type k);
    register a type

    a new derived type is registered by passing the type as template parameter and the key as argument. A second call with the same key will override the registration done by the previous call.

    Parameters:

    k

    the key associated with the type

    Returns:

    true if a type was already associated with the key

  2. bool unregister_type(key_type k);
    unregister a type

    the registration information for the key given is deleted

    Parameters:

    k

    the key to be deleted

    Returns:

    true if there was a type associated with the key.

  3. base_type * create(key_type k) const;
    create an object

    attempts to create an object of the type previously associated with the key.

    Parameters:

    k

    the key referring to the object type

    Returns:

    a pointer to a new object of the type registered with the key

    Throws:

    \c
Copyright © 1994, 2002-2005 Matthias Troyer, Synge Todo

PrevUpHomeNext