31 lines
696 B
C++
31 lines
696 B
C++
/*
|
|
* File: Factory.h
|
|
* Description: Provides a generic factory utility to create shared_ptr instances of objects.
|
|
* Author: Ajmal J S
|
|
* Created: 01-Apr-2026
|
|
*/
|
|
|
|
#pragma once
|
|
#include <utility>
|
|
|
|
class Factory
|
|
{
|
|
public:
|
|
|
|
/*
|
|
* Function: getObject
|
|
* Description: Creates and returns a shared_ptr to an object of type T.
|
|
* Parameters:
|
|
* T - the type of object to be created
|
|
* Args - constructor arguments forwarded to T's constructor
|
|
* Returns:
|
|
* std::shared_ptr<T> - a shared pointer managing the newly created object
|
|
*/
|
|
|
|
template<typename T, typename... Args>
|
|
static T* getObject(Args&&... args)
|
|
{
|
|
return T*(std::forward<Args>(args)...);
|
|
}
|
|
};
|