The Sparta Modeling Framework
Loading...
Searching...
No Matches
sparta::ResourceFactory< ResourceT, ParamsT > Class Template Reference

Templated ResourceFactoryBase implementation which can be used to trivially define Resource Factories. More...

#include <ResourceFactory.hpp>

Inheritance diagram for sparta::ResourceFactory< ResourceT, ParamsT >:
Collaboration diagram for sparta::ResourceFactory< ResourceT, ParamsT >:

Public Types

typedef ResourceT resource_type
 
typedef ParamsT params_type
 

Public Member Functions

 ResourceFactory (const ResourceFactory &rhp)=delete
 
ResourceFactoryoperator= (const ResourceFactory &rhp)=delete
 
virtual std::string getResourceType () const override
 Returns the resource type-name for this resource, demangled.
 
virtual std::string getResourceTypeRaw () const override
 Returns the resource type-name for this resource as in the typeid.
 
virtual ParameterSetcreateParameters (TreeNode *node) override
 Creates a new set of parameters associated with the resource that can be created by this factory.
 
virtual void deleteParameters (ParameterSet *params) override
 Deletes a ParameterSet created by the createParameters method of this ResourceFactory.
 
virtual void createSubtree (sparta::ResourceTreeNode *n) override
 Optionally creates a subtree of TreeNodes for this TreeNode by attaching children to this node. These children may be regular TreeNode or ResourceTreeNodes.
 
virtual void deleteSubtree (sparta::ResourceTreeNode *n) override
 Optionally deletes the TreeNodes created by createSubtee (if any).
 
virtual void onBuilding (sparta::ResourceTreeNode *n) override
 Hook for additional building on ResourceTreeNode constructing.
 
virtual void onConfiguring (sparta::ResourceTreeNode *n) override
 Hook for additional configuring on resource node configure.
 
ResourcecreateResource (TreeNode *node, const ParameterSet *params) override
 Finally instantiates the resource with its set of Parameters.
 
void deleteResource (Resource *res) override final
 Deletes a resource created by the createResource method of this ResourceFactory.
 
void bindEarly (TreeNode *) override
 Allows contents to be bound together if desired.
 
void bindLate (TreeNode *) override
 Allows contents to be bound together if desired.
 
- Public Member Functions inherited from sparta::ResourceFactoryBase
virtual ~ResourceFactoryBase ()
 Destructor.
 

Detailed Description

template<typename ResourceT, typename ParamsT = typename ResourceT::ParameterSet>
class sparta::ResourceFactory< ResourceT, ParamsT >

Templated ResourceFactoryBase implementation which can be used to trivially define Resource Factories.

Template Parameters
ResourceTType of Resource that this factory will instantiate. This type must inherit from sparta::Resource and contain a constructor with the signature: (sparta::TreeNode*, const ParamsT*).
ParamsTParameterSet class type that this factory will instantiate. This type must inherit from sparta::ParameterSet and provide a constructor with the signature: (sparta::TreeNode*)
Note
This class is noncopyable.

Creating a ResourceFactory a ResourceClass is done by instantiating this class with appropriate template arguments.

Example 1 - Explicit Parameter Set types

class MyResource : sparta::Resource { ... }
class MyParamSet : sparta::ParameterSet { ... };
typedef ResourceFactory<MyResource, MyParamsSet> MyResourceFactory;
Generic container of Parameters.
The is the base class for all types of resources used by the SPARTA framework.
Definition Resource.hpp:44

Example 2 - Implicit nested Parameter Set types

class MyResource : sparta::Resource {
public:
// ctor
...
};
// Looks for MyResource::ParameterSet types.
// ParameterSet are required nested classes in this case.
typedef ResourceFactory<MyResource> MyResourceFactory;

Definition at line 213 of file ResourceFactory.hpp.

Member Typedef Documentation

◆ params_type

template<typename ResourceT , typename ParamsT = typename ResourceT::ParameterSet>
typedef ParamsT sparta::ResourceFactory< ResourceT, ParamsT >::params_type

Definition at line 218 of file ResourceFactory.hpp.

◆ resource_type

template<typename ResourceT , typename ParamsT = typename ResourceT::ParameterSet>
typedef ResourceT sparta::ResourceFactory< ResourceT, ParamsT >::resource_type

Definition at line 217 of file ResourceFactory.hpp.

Constructor & Destructor Documentation

◆ ResourceFactory()

template<typename ResourceT , typename ParamsT = typename ResourceT::ParameterSet>
sparta::ResourceFactory< ResourceT, ParamsT >::ResourceFactory ( )
inline

Definition at line 223 of file ResourceFactory.hpp.

◆ ~ResourceFactory()

template<typename ResourceT , typename ParamsT = typename ResourceT::ParameterSet>
sparta::ResourceFactory< ResourceT, ParamsT >::~ResourceFactory ( )
inline

Definition at line 230 of file ResourceFactory.hpp.

Member Function Documentation

◆ bindEarly()

template<typename ResourceT , typename ParamsT = typename ResourceT::ParameterSet>
void sparta::ResourceFactory< ResourceT, ParamsT >::bindEarly ( TreeNode node)
inlineoverridevirtual

Allows contents to be bound together if desired.

Precondition
Tree will be finalized

Subclasses can use this to bind ports together if needed, which can also be done in Resource::bind* methods or at the Simulation level

This happens before the top-level simulator class has a chance to bind anything

Implements sparta::ResourceFactoryBase.

Definition at line 294 of file ResourceFactory.hpp.

◆ bindLate()

template<typename ResourceT , typename ParamsT = typename ResourceT::ParameterSet>
void sparta::ResourceFactory< ResourceT, ParamsT >::bindLate ( TreeNode node)
inlineoverridevirtual

Allows contents to be bound together if desired.

Precondition
Tree will be finalized
Top-level simulator class will have had a chance to bind

Subclasses can use this to bind ports together if needed, which can also be done in Resource::bind* methods or at the Simulation level

Implements sparta::ResourceFactoryBase.

Definition at line 296 of file ResourceFactory.hpp.

◆ createParameters()

template<typename ResourceT , typename ParamsT = typename ResourceT::ParameterSet>
virtual ParameterSet * sparta::ResourceFactory< ResourceT, ParamsT >::createParameters ( TreeNode node)
inlineoverridevirtual

Creates a new set of parameters associated with the resource that can be created by this factory.

Parameters
nodeTreeNode which which the newly-created parameters will be permanently associated.
Returns
new ParameterSet that must be deallocated by caller via deleteParameters.

Each ParameterSet created by this parameter set must contain identical parameters down to types and default values.

Implements sparta::ResourceFactoryBase.

Definition at line 240 of file ResourceFactory.hpp.

◆ createResource()

template<typename ResourceT , typename ParamsT = typename ResourceT::ParameterSet>
Resource * sparta::ResourceFactory< ResourceT, ParamsT >::createResource ( TreeNode node,
const ParameterSet params 
)
inlineoverridevirtual

Finally instantiates the resource with its set of Parameters.

Note
Cannot be overridden further

Params are cast to ParamsT*. This class would not compile if this cast were impossible.

Implements sparta::ResourceFactoryBase.

Definition at line 275 of file ResourceFactory.hpp.

Here is the call graph for this function:

◆ createSubtree()

template<typename ResourceT , typename ParamsT = typename ResourceT::ParameterSet>
virtual void sparta::ResourceFactory< ResourceT, ParamsT >::createSubtree ( sparta::ResourceTreeNode n)
inlineoverridevirtual

Optionally creates a subtree of TreeNodes for this TreeNode by attaching children to this node. These children may be regular TreeNode or ResourceTreeNodes.

Because this occurs during the tree construction phase, adding child ResourceTreeNodes is valid

Implements sparta::ResourceFactoryBase.

Definition at line 251 of file ResourceFactory.hpp.

◆ deleteParameters()

template<typename ResourceT , typename ParamsT = typename ResourceT::ParameterSet>
virtual void sparta::ResourceFactory< ResourceT, ParamsT >::deleteParameters ( ParameterSet params)
inlineoverridevirtual

Deletes a ParameterSet created by the createParameters method of this ResourceFactory.

Parameters
paramsParameterSet to deallocate

Implements sparta::ResourceFactoryBase.

Definition at line 245 of file ResourceFactory.hpp.

◆ deleteResource()

template<typename ResourceT , typename ParamsT = typename ResourceT::ParameterSet>
void sparta::ResourceFactory< ResourceT, ParamsT >::deleteResource ( Resource res)
inlinefinaloverridevirtual

Deletes a resource created by the createResource method of this ResourceFactory.

Parameters
resResource to deallocate.

Implements sparta::ResourceFactoryBase.

Definition at line 289 of file ResourceFactory.hpp.

◆ deleteSubtree()

template<typename ResourceT , typename ParamsT = typename ResourceT::ParameterSet>
virtual void sparta::ResourceFactory< ResourceT, ParamsT >::deleteSubtree ( sparta::ResourceTreeNode n)
inlineoverridevirtual

Optionally deletes the TreeNodes created by createSubtee (if any).

An implementation of ResourceFactoryBase should generally keep a vector of nodes that it allocated and delete them when this method is invoked.

Implements sparta::ResourceFactoryBase.

Definition at line 255 of file ResourceFactory.hpp.

◆ getResourceType()

template<typename ResourceT , typename ParamsT = typename ResourceT::ParameterSet>
virtual std::string sparta::ResourceFactory< ResourceT, ParamsT >::getResourceType ( ) const
inlineoverridevirtual

Returns the resource type-name for this resource, demangled.

Returns
Resource type as a std::string. This value must be constant for the lifetime of this class.

Implements sparta::ResourceFactoryBase.

Definition at line 232 of file ResourceFactory.hpp.

◆ getResourceTypeRaw()

template<typename ResourceT , typename ParamsT = typename ResourceT::ParameterSet>
virtual std::string sparta::ResourceFactory< ResourceT, ParamsT >::getResourceTypeRaw ( ) const
inlineoverridevirtual

Returns the resource type-name for this resource as in the typeid.

Returns
Resource type as a std::string. This value must be constant for the lifetime of this class.

Implements sparta::ResourceFactoryBase.

Definition at line 236 of file ResourceFactory.hpp.

◆ onBuilding()

template<typename ResourceT , typename ParamsT = typename ResourceT::ParameterSet>
virtual void sparta::ResourceFactory< ResourceT, ParamsT >::onBuilding ( sparta::ResourceTreeNode n)
inlineoverridevirtual

Hook for additional building on ResourceTreeNode constructing.

Tap into hook for creating more resource nodes, subtrees, etc.

Implements sparta::ResourceFactoryBase.

Definition at line 260 of file ResourceFactory.hpp.

◆ onConfiguring()

template<typename ResourceT , typename ParamsT = typename ResourceT::ParameterSet>
virtual void sparta::ResourceFactory< ResourceT, ParamsT >::onConfiguring ( sparta::ResourceTreeNode n)
inlineoverridevirtual

Hook for additional configuring on resource node configure.

Tap into hook to configure any resources.

Implements sparta::ResourceFactoryBase.

Definition at line 264 of file ResourceFactory.hpp.


The documentation for this class was generated from the following file: