lestes::lang::cplus::lex::encoder_factory Class Reference

Factory for encoders. More...

#include <encoder_factory.hh>

Inheritance diagram for lestes::lang::cplus::lex::encoder_factory:

lestes::std::object lestes::std::mem::keystone List of all members.

Public Types

typedef ptr< encoder >(*) encoder_create_type (void)
 Type of common encoder create methods.

Public Member Functions

void insert (const lstring &a_name, encoder_create_type a_create)
 Inserts new encoder into the database.
void remove (const lstring &a_name)
 Removes the encoder from the database.
ptr< encodersummon (const lstring &a_name) const
 Returns encoder for name.

Static Public Member Functions

template<typename Encoder>
static ptr< encoderencoder_create_adaptor (void)
 Adapts the return value of create methods.
static ptr< encoder_factoryinstance (void)
 Returns the only instance.

Protected Member Functions

 encoder_factory (void)
 Creates the object.
virtual void gc_mark (void)
 Marks the object.

Private Types

typedef ::lestes::std::map<
lstring, encoder_create_type
storage_type
 Type of storage for create functions.

Private Member Functions

 encoder_factory (const encoder_factory &)
 Hides copy constructor.
encoder_factoryoperator= (const encoder_factory &)
 Hides assignment operator.

Private Attributes

srp< storage_typestorage
 The storage for encoders.

Static Private Attributes

static ptr< encoder_factorysingleton
 The only object of the class.

Detailed Description

Factory for encoders.

Manages all encoder implementations.

Definition at line 52 of file encoder_factory.hh.


Member Typedef Documentation

typedef ptr<encoder>(* ) lestes::lang::cplus::lex::encoder_factory::encoder_create_type(void)

Type of common encoder create methods.

Definition at line 58 of file encoder_factory.hh.

typedef ::lestes::std::map< lstring, encoder_create_type > lestes::lang::cplus::lex::encoder_factory::storage_type [private]

Type of storage for create functions.

Definition at line 74 of file encoder_factory.hh.


Constructor & Destructor Documentation

lestes::lang::cplus::lex::encoder_factory::encoder_factory ( void   )  [protected]

Creates the object.

Creates the object.

Postcondition:
summon() == NULL

Definition at line 48 of file encoder_factory.cc.

Referenced by instance().

00048                                     :
00049         storage(storage_type::create())
00050 {
00051 }

lestes::lang::cplus::lex::encoder_factory::encoder_factory ( const encoder_factory  )  [private]

Hides copy constructor.


Member Function Documentation

template<typename T>
ptr< encoder > lestes::lang::cplus::lex::encoder_factory::encoder_create_adaptor ( void   )  [inline, static]

Adapts the return value of create methods.

Adapts return value of concrete encoder create() method to return base class.

Parameters:
Encoder The concrete encoder to adapt.
create The creator of the concrete encoder.

Definition at line 94 of file encoder_factory.hh.

00095 {
00096         return ptr<encoder>(T::create());
00097 }

void lestes::lang::cplus::lex::encoder_factory::insert ( const lstring &  a_name,
encoder_create_type  a_create 
)

Inserts new encoder into the database.

Inserts new encoder into the database.

Precondition:
a_create != NULL

a_create() != NULL (checked only in summon())

Postcondition:
summon(a_name) == a_create()
Parameters:
a_name The name of the encoder to insert.
a_create The method tho create the encoder.

Definition at line 61 of file encoder_factory.cc.

References lassert, and storage.

00062 {
00063         lassert(a_create);
00064         storage->insert(storage_type::value_type(a_name,a_create));
00065 }

void lestes::lang::cplus::lex::encoder_factory::remove ( const lstring &  a_name  ) 

Removes the encoder from the database.

Removes encoder from the database.

Precondition:
a_name is in the database.
Parameters:
a_name The name of the encoder to remove.

Definition at line 72 of file encoder_factory.cc.

References lassert, and storage.

00073 {
00074         storage_type::iterator it = storage->find(a_name);
00075         lassert(it != storage->end());
00076         storage->erase(it);
00077 }

ptr< encoder > lestes::lang::cplus::lex::encoder_factory::summon ( const lstring &  a_name  )  const

Returns encoder for name.

Returns new encoder for given name.

Precondition:
a_name was inserted into the factory
Postcondition:
returned != NULL or a_name was not inserted
Parameters:
a_name The name of the desired encoder.
Returns:
The new encoder or NULL if not found.

Definition at line 86 of file encoder_factory.cc.

References lassert, and storage.

00087 {
00088         storage_type::iterator it = storage->find(a_name);
00089         if (it == storage->end()) return NULL;
00090         // call the create function
00091         ptr<encoder> ret = (it->second)();
00092         // check whether the create succeeded
00093         lassert(ret);
00094         return ret;
00095 }

ptr< encoder_factory > lestes::lang::cplus::lex::encoder_factory::instance ( void   )  [static]

Returns the only instance.

Returns the only instance of the encoder_factory class.

Returns:
The singleton encoder_factory object.

Definition at line 110 of file encoder_factory.cc.

References encoder_factory(), and singleton.

Referenced by lestes::lang::cplus::lex::encoder_factory_test().

00111 {
00112         if (!singleton) {
00113                 singleton = new encoder_factory();
00114         }
00115         return singleton;
00116 }

void lestes::lang::cplus::lex::encoder_factory::gc_mark ( void   )  [protected, virtual]

Marks the object.

Marks the object.

Reimplemented from lestes::std::mem::keystone.

Definition at line 100 of file encoder_factory.cc.

References lestes::std::mem::keystone::gc_mark(), and storage.

00101 {
00102         storage.gc_mark();
00103 	::lestes::std::object::gc_mark();
00104 }

encoder_factory& lestes::lang::cplus::lex::encoder_factory::operator= ( const encoder_factory  )  [private]

Hides assignment operator.


Member Data Documentation

srp<storage_type> lestes::lang::cplus::lex::encoder_factory::storage [private]

The storage for encoders.

Definition at line 79 of file encoder_factory.hh.

Referenced by gc_mark(), insert(), remove(), and summon().

ptr< encoder_factory > lestes::lang::cplus::lex::encoder_factory::singleton [static, private]

The only object of the class.

The only instance of the class, holds all encoder registrations. Uses lazy instantiation.

Definition at line 81 of file encoder_factory.hh.

Referenced by instance().


The documentation for this class was generated from the following files:
Generated on Mon Feb 12 18:24:16 2007 for lestes by doxygen 1.5.1-20070107