Builder.hpp
#if !defined(__BUILDER_HPP)
#define __BUILDER_HPP
/*
CoreLinux++
Copyright (C) 1999,2000 CoreLinux Consortium
The CoreLinux++ Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The CoreLinux++ Library Library is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#if !defined(__COMMON_HPP)
#include <Common.hpp>
#endif
#if !defined(__ABSTRACTFACTORY_HPP)
#include <AbstractFactory.hpp>
#endif
namespace corelinux
{
template< class ProductImpl, class UniqueId >
class Builder
{
public:
//
// Constructors and destructor
//
Builder
(
AbstractFactory<UniqueId> *aAbstractFactory
)
throw( Assertion )
:
theCurrentProduct( NULLPTR ),
theFactory( NULLPTR ),
theProductCreates( 0 ),
theProductDestroys( 0 )
{
REQUIRE( aAbstractFactory != NULLPTR );
theFactory = aAbstractFactory ;
}
Builder( const Builder &aBuilder )
throw( Assertion )
:
theCurrentProduct( NULLPTR ),
theFactory( aBuilder.getFactory() ),
theProductCreates( 0 ),
theProductDestroys( 0 )
{
REQUIRE( theFactory != NULLPTR );
}
virtual ~Builder( void )
{
; // do nothing
}
//
// Operator overloads
//
Builder & operator=( const Builder &aRef )
{
if( this != &aRef )
{
this->destroy( theCurrentProduct );
theFactory = aRef.getFactory();
theCurrentProduct = NULLPTR;
theProductCreates = 0;
theProductDestroys = 0;
}
else
{
; // do nothing
}
return ( *this );
}
bool operator==( const Builder &aRef )
{
return ( this == &aRef );
}
//
// Accessors
//
virtual ProductImpl * getCurrentProduct( void ) const
{
return theCurrentProduct;
}
virtual CountCref getProductCreates( void ) const
{
return theProductCreates;
}
virtual CountCref getProductDestroys( void ) const
{
return theProductDestroys;
}
virtual AbstractFactory<UniqueId> * getFactory( void ) const
{
return theFactory;
}
//
// Builder methods
//
virtual ProductImpl * create( void )
{
ProductImpl *aPtr( NULLPTR );
try
{
aPtr = createProduct();
CHECK( aPtr != NULLPTR );
theCurrentProduct = aPtr;
incrementCreates();
}
catch( ... )
{
throw;
}
return aPtr;
}
virtual void destroy( ProductImpl * aPtr )
{
REQUIRE( aPtr != NULLPTR );
try
{
destroyProduct( aPtr );
incrementDestroys();
}
catch( ... )
{
throw;
}
if( aPtr == theCurrentProduct )
{
theCurrentProduct = NULLPTR;
}
else
{
; // do nothing
}
}
protected:
//
// Constructor
//
Builder( void ) throw(Assertion)
:
theCurrentProduct( NULLPTR ),
theFactory( NULLPTR ),
theProductCreates( 0 ),
theProductDestroys( 0 )
{
NEVER_GET_HERE;
}
//
// Mutators
//
void incrementCreates( void )
{
++theProductCreates;
}
void incrementDestroys( void )
{
++theProductDestroys;
}
//
// Factory methods
//
virtual ProductImpl * createProduct( void ) const = 0;
virtual void destroyProduct( ProductImpl * ) const = 0;
protected:
//
// Data members
//
ProductImpl *theCurrentProduct;
AbstractFactory<UniqueId> *theFactory;
Count theProductCreates;
Count theProductDestroys;
};
}
#endif // if !defined(__BUILDER_HPP)
/*
Common rcs information do not modify
$Author: prudhomm $
$Revision: 1.1 $
$Date: 2000/04/23 20:43:13 $
$Locker: $
*/
corelinux::Builder::theProductCreates
Count theProductCreates
The count of creates.
Definition: Builder.hpp:295
corelinux::Builder::Builder
Builder(void)
Default constructor not supported.
Definition: Builder.hpp:239
corelinux::Builder::operator=
Builder & operator=(const Builder &aRef)
Operation assignment.
Definition: Builder.hpp:108
corelinux::Builder::getProductDestroys
virtual CountCref getProductDestroys(void) const
Retrieve the product destroy counts.
Definition: Builder.hpp:161
corelinux::Builder::incrementCreates
void incrementCreates(void)
Increment the creates.
Definition: Builder.hpp:255
corelinux::Builder::destroy
virtual void destroy(ProductImpl *aPtr)
Default destroy routine invokes the implementation destroyProduct method.
Definition: Builder.hpp:209
corelinux::Builder::Builder
Builder(const Builder &aBuilder)
Copy constructor creates a new instance of the reference abstract factory.
Definition: Builder.hpp:79
corelinux::Builder::getFactory
virtual AbstractFactory< UniqueId > * getFactory(void) const
Retrieve the AbstractFactory.
Definition: Builder.hpp:168
corelinux::Builder::theCurrentProduct
ProductImpl * theCurrentProduct
The product that was most recently built.
Definition: Builder.hpp:287
corelinux::Builder::theProductDestroys
Count theProductDestroys
The count of destroys.
Definition: Builder.hpp:299
corelinux
Forward reference the various common classes.
Definition: AbstractAllocator.hpp:32
corelinux::Builder::createProduct
virtual ProductImpl * createProduct(void) const =0
Pure virtual createProduct.
corelinux::Builder::~Builder
virtual ~Builder(void)
Virtual destructor.
Definition: Builder.hpp:92
corelinux::Builder::destroyProduct
virtual void destroyProduct(ProductImpl *) const =0
Pure virtual destroyProduct.
corelinux::Builder::theFactory
AbstractFactory< UniqueId > * theFactory
The factory for creating parts.
Definition: Builder.hpp:291
corelinux::Builder::operator==
bool operator==(const Builder &aRef)
Equality operator.
Definition: Builder.hpp:134
corelinux::Builder::create
virtual ProductImpl * create(void)
Default create routine invokes the implementation createProduct method.
Definition: Builder.hpp:181
corelinux::Assertion
Assertion is-a Exception created when an assertion fails.
Definition: Assertion.hpp:423
corelinux::Builder::getCurrentProduct
virtual ProductImpl * getCurrentProduct(void) const
Retrieves the current product.
Definition: Builder.hpp:147
corelinux::Builder::incrementDestroys
void incrementDestroys(void)
Increment the destroys.
Definition: Builder.hpp:262
corelinux::AbstractFactory
AbstractFactory provides an interface for creating families of related or dependent objects without s...
Definition: AbstractFactory.hpp:60
corelinux::Builder
Builder seperates the construction of a complex object from its representation so that the same const...
Definition: Builder.hpp:44
corelinux::Builder::getProductCreates
virtual CountCref getProductCreates(void) const
Retrieve the product create counts.
Definition: Builder.hpp:154

This is the CoreLinux++ reference manual
Provided by The CoreLinux Consortium