2023-02-08 11:04:11 +00: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.
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef Foundation_Instantiator_INCLUDED
|
|
|
|
#define Foundation_Instantiator_INCLUDED
|
|
|
|
|
|
|
|
|
|
|
|
#include "Poco/Foundation.h"
|
|
|
|
|
|
|
|
|
2023-02-13 09:22:33 +00:00
|
|
|
namespace Poco
|
|
|
|
{
|
2023-02-08 11:04:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
template <class Base>
|
|
|
|
class AbstractInstantiator
|
2023-02-13 09:22:33 +00:00
|
|
|
/// The common base class for all Instantiator instantiations.
|
|
|
|
/// Used by DynamicFactory.
|
2023-02-08 11:04:11 +00:00
|
|
|
{
|
|
|
|
public:
|
2023-02-13 09:22:33 +00:00
|
|
|
AbstractInstantiator()
|
|
|
|
/// Creates the AbstractInstantiator.
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~AbstractInstantiator()
|
|
|
|
/// Destroys the AbstractInstantiator.
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Base * createInstance() const = 0;
|
|
|
|
/// Creates an instance of a concrete subclass of Base.
|
2023-02-08 11:04:11 +00:00
|
|
|
|
|
|
|
private:
|
2023-02-13 09:22:33 +00:00
|
|
|
AbstractInstantiator(const AbstractInstantiator &);
|
|
|
|
AbstractInstantiator & operator=(const AbstractInstantiator &);
|
2023-02-08 11:04:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <class C, class Base>
|
2023-02-13 09:22:33 +00:00
|
|
|
class Instantiator : public AbstractInstantiator<Base>
|
|
|
|
/// A template class for the easy instantiation of
|
|
|
|
/// instantiators.
|
|
|
|
///
|
|
|
|
/// For the Instantiator to work, the class of which
|
|
|
|
/// instances are to be instantiated must have a no-argument
|
|
|
|
/// constructor.
|
2023-02-08 11:04:11 +00:00
|
|
|
{
|
|
|
|
public:
|
2023-02-13 09:22:33 +00:00
|
|
|
Instantiator()
|
|
|
|
/// Creates the Instantiator.
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~Instantiator()
|
|
|
|
/// Destroys the Instantiator.
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Base * createInstance() const { return new C; }
|
2023-02-08 11:04:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace Poco
|
|
|
|
|
|
|
|
|
|
|
|
#endif // Foundation_Instantiator_INCLUDED
|