MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::Portal::Forma::FactoryTable< Source, Access > Class Template Reference

Named factories that turn a template's factory element and an instance into placed Forma elements, as a plain value. More...

#include <FactoryTable.hpp>

Inheritance diagram for MayaFlux::Portal::Forma::FactoryTable< Source, Access >:
Collaboration diagram for MayaFlux::Portal::Forma::FactoryTable< Source, Access >:

Public Types

using BulkInstantiator
 Decodes a factory element and typed placement rows into one Placer per row.
using Instantiator
 Decodes a factory element and an instance into a Placer, or nullopt with an error.
using Placer = std::function<std::optional<uint32_t>(Surface&, std::string&)>
 Places one prepared element, or several, onto a Surface.

Public Member Functions

bool contains (std::string_view name) const
 Whether a factory of this name is registered.
void expose_placement (std::string name, Instantiator instantiator)
 Register a whole placement.
template<typename T, Reflect::Described Input, Reflect::Described Placement, typename Factory, typename Initial>
void expose_typed (std::string name, Reflect::RecordBinding< Input, Source, Access > input, Reflect::RecordBinding< Placement, Source, Access > placement, Factory factory, Initial initial, std::type_identity_t< std::function< void(const Input &, const Placement &, Tend< T > &)> > placed={})
 Expose a factory whose inputs and placement are described types.
const Instantiator * find (std::string_view name) const
 The factory of this name, or nullptr.
const BulkInstantiator * find_bulk (std::string_view name) const
 The bulk path of this name, or nullptr when it was not registered with expose_typed.
bool merge (const FactoryTable &other, std::string_view prefix, std::string &error, bool replace=false)
 Add every factory of another table under a name prefix.
std::vector< std::string > names () const
 Registered names in sorted order.

Static Public Member Functions

static std::string located (uint64_t row, std::string_view message)
 The message prefixed with the row it concerns.

Static Private Member Functions

template<typename T>
static Placer make_placer (Geometry::Form< T > form, T initial, std::function< void(Tend< T > &)> after)

Private Attributes

Memory::FlatMap< std::string, BulkInstantiator, std::less<> > m_bulk
Memory::FlatMap< std::string, Instantiator, std::less<> > m_factories

Detailed Description

template<typename Source, typename Access = Reflect::RecordAccess<Source>>
class MayaFlux::Portal::Forma::FactoryTable< Source, Access >

Named factories that turn a template's factory element and an instance into placed Forma elements, as a plain value.

A table is a plain value. It holds only what its builder registers, and nothing is pre-registered or privileged: a host, a library or a user each build their own and combine them with merge(). A factory is a preparation that decodes everything and returns a Placer, so a document can be checked completely before anything is placed.

Source is any element type with a Reflect::RecordAccess specialization and value semantics, so the same table serves XML, a script or any other document tree.

Two ways to register:

  • expose_typed: described input and placement types. The factory also gets a bulk path that decodes its inputs once and makes one element per row of typed placements.
  • expose_placement: any placement at all, with any number of elements, composed primitives or bindings, onto the Surface it is given.

Errors name the row of the failing element.

Usage:

mine.expose_typed<float>("dial", dial_input, dial_placement, make_dial, dial_initial);
std::string error;
shared.merge(mine, "studio.", error);
void expose_typed(std::string name, Reflect::RecordBinding< Input, Source, Access > input, Reflect::RecordBinding< Placement, Source, Access > placement, Factory factory, Initial initial, std::type_identity_t< std::function< void(const Input &, const Placement &, Tend< T > &)> > placed={})
Expose a factory whose inputs and placement are described types.
Named factories that turn a template's factory element and an instance into placed Forma elements,...

Definition at line 62 of file FactoryTable.hpp.


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