LUMIERA.clone/src/lib/par/parameter.hpp
Ichthyostega 9f19f5d895 Parameters: build container with in-place init
turns out to be quite tricky, due to the overly convoluted implementation
of PolymorphicValue (which looks quite dated, generally speaking,
and could use a complete overhaul).

- pass the basic value type as template parameter through the Builder
- allow for the ability to define an initial value for the parameter
- invoke the protected constructor of PolymorphicValue, directly passing
  a ''type tag'' to specify the implementation data package to be placed
  into the embedded data buffer
2026-09-02 01:19:24 +02:00

115 lines
2.9 KiB
C++
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
PARAMETER.hpp - generic parameter values
Copyright (C)
2008,2026 Hermann Vosseler <Ichthyostega@web.de>
  **Lumiera** is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published by the
  Free Software Foundation; either version 2 of the License, or (at your
  option) any later version. See the file COPYING for further details.
*/
/** @file parameter.hpp
** A generic typed value that can be discovered and automated.
** The actual data type of the parameter is an opaque implementation detail,
** yet value ranges and conversions are handled automatically. It is thus
** both a descriptor and an opaque container. Parameter elements can be copied,
** yet the presence of some specific parameter at a given point in the model
** constitutes an identity -- and the parameter descriptor can be tagged
** with that identity.
**
** @todo this is a draft and placeholder, as of 2026
*/
#ifndef LIB_PAR_PARAMETER_H
#define LIB_PAR_PARAMETER_H
#include "lib/par/disposition.hpp"
#include "lib/polymorphic-value.hpp"
#include <utility>
namespace lib {
namespace par {
namespace {
static constexpr size_t BUFF_SIZ = sizeof(ParamData<double>);
using ParameterImplAPI = Disposition;
using CopySupportMarker = polyvalue::CopySupport<ParameterImplAPI>;
using ParamContainer = PolymorphicValue<ParameterImplAPI, BUFF_SIZ, CopySupportMarker>;
}
/**
* Descriptor and container to hold a generic parameter.
* The value can be fixed or supplied by an automation function.
*/
class Parameter
: protected ParamContainer
{
public:
template<typename VAL>
class Builder;
template<typename VAL>
VAL getVal();
template<typename VAL>
void setVal (VAL&&);
/* === Builder API === */
template<typename VAL>
static Builder<VAL>
forType() { return {}; }
protected:
template<class IMP, typename...ARGS>
Parameter (IMP* typeTag, ARGS&&... args)
: PolymorphicValue (typeTag, std::forward<ARGS>(args)...)
{ }
};
template<typename VAL>
class Parameter::Builder
{
VAL initVal_{};
public:
Parameter
build()
{
using ImplPackage = ParamData<VAL>;
ImplPackage* typeTag{nullptr};
Parameter resParam{typeTag, std::move (initVal_)};
return resParam;
}
};
template<typename VAL>
VAL
Parameter::getVal()
{
UNIMPLEMENTED ("extract the »value«, possibly applying suitable type conversions");
}
template<typename VAL>
void
Parameter::setVal (VAL&& changedVal)
{
UNIMPLEMENTED ("apply suitable type conversions and clamping, then transfer the new value into the Provision interface");
}
}} // namespace lib::par
#endif /*LIB_PAR_PARAMETER_H*/