2012-04-29 20:52:25 +02:00
|
|
|
//
|
|
|
|
// Instantiator.h
|
|
|
|
//
|
|
|
|
// Library: Foundation
|
|
|
|
// Package: Core
|
|
|
|
// Module: Instantiator
|
|
|
|
//
|
|
|
|
// Definition of the Instantiator class.
|
|
|
|
//
|
|
|
|
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
|
|
|
// and Contributors.
|
|
|
|
//
|
2014-05-04 21:02:42 +02:00
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
2012-04-29 20:52:25 +02:00
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef Foundation_Instantiator_INCLUDED
|
|
|
|
#define Foundation_Instantiator_INCLUDED
|
|
|
|
|
|
|
|
|
|
|
|
#include "Poco/Foundation.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace Poco {
|
|
|
|
|
|
|
|
|
|
|
|
template <class Base>
|
|
|
|
class AbstractInstantiator
|
|
|
|
/// The common base class for all Instantiator instantiations.
|
|
|
|
/// Used by DynamicFactory.
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AbstractInstantiator()
|
|
|
|
/// Creates the AbstractInstantiator.
|
|
|
|
{
|
|
|
|
}
|
2022-07-07 11:18:20 +02:00
|
|
|
|
2012-04-29 20:52:25 +02:00
|
|
|
virtual ~AbstractInstantiator()
|
|
|
|
/// Destroys the AbstractInstantiator.
|
|
|
|
{
|
|
|
|
}
|
2022-07-07 11:18:20 +02:00
|
|
|
|
2012-04-29 20:52:25 +02:00
|
|
|
virtual Base* createInstance() const = 0;
|
2022-07-07 11:18:20 +02:00
|
|
|
/// Creates an instance of a concrete subclass of Base.
|
2012-04-29 20:52:25 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
AbstractInstantiator(const AbstractInstantiator&);
|
|
|
|
AbstractInstantiator& operator = (const AbstractInstantiator&);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <class C, class Base>
|
|
|
|
class Instantiator: public AbstractInstantiator<Base>
|
2022-07-07 11:18:20 +02:00
|
|
|
/// A template class for the easy instantiation of
|
|
|
|
/// instantiators.
|
2012-04-29 20:52:25 +02:00
|
|
|
///
|
|
|
|
/// For the Instantiator to work, the class of which
|
|
|
|
/// instances are to be instantiated must have a no-argument
|
|
|
|
/// constructor.
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Instantiator()
|
|
|
|
/// Creates the Instantiator.
|
|
|
|
{
|
|
|
|
}
|
2022-07-07 11:18:20 +02:00
|
|
|
|
2012-04-29 20:52:25 +02:00
|
|
|
virtual ~Instantiator()
|
|
|
|
/// Destroys the Instantiator.
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Base* createInstance() const
|
|
|
|
{
|
|
|
|
return new C;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace Poco
|
|
|
|
|
|
|
|
|
|
|
|
#endif // Foundation_Instantiator_INCLUDED
|