template<typename T>
DartsFactory class

A specialization of the Factory for darts objects read from json.

Template parameters
T This factory will create objects of type shared_ptr<T>.

Additionally, DartsFactory allows storing previously parsed/created instances into a registry with register_instance() and retrieving them with their name using find().

Base classes

template<typename Object, typename... Args>
class Factory<shared_ptr<T>, const nlohmann::json&>
Abstract factory used to construct objects by name.

Public types

using SharedT = shared_ptr<T>
Shared pointer to the created type #T.

Public static functions

static auto create(const nlohmann::json& j) -> SharedT
Allows creating a shared_ptr to a darts object, deducing the type from a "type" field in j.
static auto find(const nlohmann::json& jp, const std::string& key) -> SharedT
Find a previously parsed/created SharedT, or create a new one.
static auto find(const nlohmann::json& jp) -> SharedT
Find a previously parsed/created SharedT, or create a new one using the default key for this type of object.
static void register_instance(const std::string& name, SharedT o)
Associate and store a shared_ptr to an object instance o with the name name.

Protected static functions

static auto instance_registry() -> std::map<std::string, SharedT>&
Global map of SharedT instances that have been create/parsed.

Function documentation

template<typename T>
static SharedT DartsFactory<T>::find(const nlohmann::json& jp, const std::string& key)

Find a previously parsed/created SharedT, or create a new one.

Parameters
jp The json object for the parent
key Look for this json field in jp
Returns SharedT The newly created or retrieved object instance.

Return a SharedT pointer by parsing a JSON specification. If j is a string key: "name", then try to find a previously parsed SharedT with name "name". If j is a json object key: {}, then create a new SharedT with the specified parameters by calling create().

template<typename T>
static SharedT DartsFactory<T>::find(const nlohmann::json& jp)

Find a previously parsed/created SharedT, or create a new one using the default key for this type of object.

Parameters
jp The json object for the parent
Returns SharedT The newly created or retrieved object instance.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.