Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
Loading...
Searching...
No Matches
ToyMaker::ResourceConstructor< TResource, TResourceFactoryMethod > Class Template Reference

An object representing one method for creating a resource of a given kind. More...

#include <resource_database.hpp>

Inheritance diagram for ToyMaker::ResourceConstructor< TResource, TResourceFactoryMethod >:
ToyMaker::IResourceConstructor

Public Member Functions

std::string getResourceConstructorName_ () const override
 Gets the resource constructor type string of the constructor.
 
- Public Member Functions inherited from ToyMaker::IResourceConstructor
virtual std::shared_ptr< IResourcecreateResource (const nlohmann::json &methodParameters)=0
 Creates a resource object using the parameters specified in methodParameters.
 
virtual ~IResourceConstructor ()=default
 Destroys this resource constructor (when the application is terminated.)
 

Protected Member Functions

 ResourceConstructor (int explicitlyInitializeMe)
 Construct a new ResourceConstructor object.
 
- Protected Member Functions inherited from ToyMaker::IResourceConstructor
 IResourceConstructor ()=default
 Construct a new IResourceConstructor object.
 

Static Private Member Functions

static void registerSelf ()
 A helper function that informs the ResourceDatabase that this constructor type exists.
 

Static Private Attributes

static Registrator< ResourceConstructor< TResource, TResourceFactoryMethod > > s_registrator
 A helper class responsible for calling this class' registerSelf() method at during the static initialization phase of a program.
 

Friends

class Registrator< ResourceConstructor< TResource, TResourceFactoryMethod > >
 
class ResourceFactory< TResource >
 

Additional Inherited Members

- Static Protected Member Functions inherited from ToyMaker::IResourceConstructor
template<typename TResource, typename TResourceConstructor>
static void RegisterResourceConstructor ()
 Registers this resource constructor against its respective ResourceFactory during static initialization.
 

Detailed Description

template<typename TResource, typename TResourceFactoryMethod>
class ToyMaker::ResourceConstructor< TResource, TResourceFactoryMethod >

An object representing one method for creating a resource of a given kind.

A single resource may be created in multiple ways. A texture resource, for example, may be loaded from an image file, or procedurally generated, or simply allocated.

Each method that results in a Texture implements ResourceConstructor, and is recorded in the Resource's ResourceFactory, which is in turn used by a ResourceDatabase.

Usage

An example of a ResourceConstructor definition is given below:

// NOTE: TConstructor is derived from ResourceConstructor<TResource, TConstructor>
class NineSlicePanelFromDescription: public ToyMaker::ResourceConstructor<NineSlicePanel, NineSlicePanelFromDescription> {
public:
// NOTE: explicit call to the ResourceConstructor base class' constructor
// NOTE: static method returning the name of the resource constructor
inline static std::string getResourceConstructorName() { return "fromDescription"; }
private:
// NOTE: The actual method responsible for constructing an instance of the resource
std::shared_ptr<ToyMaker::IResource> createResource(const nlohmann::json& methodParameters) override;
};
Resource constructor for creating new NineSlicePanel resources from their descriptions in JSON.
Definition nine_slice_panel.hpp:156
Resource responsible for resizing a texture using the 9-slice technique, for use in UI elements.
Definition nine_slice_panel.hpp:38
An object representing one method for creating a resource of a given kind.
Definition resource_database.hpp:474
ResourceConstructor(int explicitlyInitializeMe)
Construct a new ResourceConstructor object.
Definition resource_database.hpp:491
Namespace containing all class definitions and functions related to the ToyMaker engine.
Definition camera_system.hpp:20
Template Parameters
TResourceThe type of resource this constructor creates.
TResourceFactoryMethodThe derived class, the resource constructor itself.
See also
Resource
ResourceFactory
ResourceDatabase

Constructor & Destructor Documentation

◆ ResourceConstructor()

template<typename TResource, typename TResourceFactoryMethod>
ToyMaker::ResourceConstructor< TResource, TResourceFactoryMethod >::ResourceConstructor ( int explicitlyInitializeMe)
inlineexplicitprotected

Construct a new ResourceConstructor object.

Parameters
explicitlyInitializeMeA dummy parameter that should have been removed a long time ago when the author discovered explicit

Member Function Documentation

◆ getResourceConstructorName_()

template<typename TResource, typename TResourceFactoryMethod>
std::string ToyMaker::ResourceConstructor< TResource, TResourceFactoryMethod >::getResourceConstructorName_ ( ) const
inlineoverridevirtual

Gets the resource constructor type string of the constructor.

Remarks
requires static std::string TResourceFactoryMethod::getResourceConstructorName() to be defined.
Returns
std::string The resource constructor's type string.

Implements ToyMaker::IResourceConstructor.

Member Data Documentation

◆ s_registrator

template<typename TResource, typename TResourceFactoryMethod>
Registrator<ResourceConstructor<TResource, TResourceFactoryMethod> > ToyMaker::ResourceConstructor< TResource, TResourceFactoryMethod >::s_registrator
inlinestaticprivate
Initial value:
{
}
Helper class for registering a class at program startup.
Definition registrator.hpp:64

A helper class responsible for calling this class' registerSelf() method at during the static initialization phase of a program.

See also
Registrator<T>

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