LUMIERA.clone/src/lib/par/disposition.hpp
Ichthyostega 41adaa18ef Parameters: streamline automatic type conversion
Can now express the automatic conversion between all allowed `BaseTypes`
by invoking the `TypeHandler` interface directly. The interfaces were streamlined
and storage size is managed automatically at compile time.
2026-09-03 01:42:18 +02:00

154 lines
4 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.

/*
DISPOSITION.hpp - actual constitution of a parameter descriptor
Copyright (C)
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 disposition.hpp
** Concrete configuration of a parameter descriptor with type and value provision.
** This is the full definition, with all details spelled out, and what is actually
** stored within the _outer shell_ of a Parameter. The publicly visible interface
** of the latter is implemented by delegating to the constituents of the disposition.
**
** @todo WIP-WIP-WIP can be considered an initial draft and placeholder, as of 2026
*/
#ifndef LIB_PAR_DISPOSITION_H
#define LIB_PAR_DISPOSITION_H
#include "lib/par/spec.hpp"
#include "lib/par/provision.hpp"
#include "lib/par/param-type.hpp"
namespace lib {
namespace par {
using ValStorage = ValBuffStorage<BASETYPE_MAX_SIZ>;
/**
* Implementation-Service: complete Parameter functionality.
* Includes the ability to access / set a »value«, attach automation,
* identify and convert underlying value data types and handle
* trait- and identity tags and the specifics of the value scale.
*/
class Disposition
: public Domain
{
IDRecord idr_;
public:
template<typename X>
X extract() const;
template<typename X>
void setVal (X);
private:
template<typename X>
bool isBaseDomainMatch() const;
};
/**
* A complete configuration and setup of a parameter, including a type specification
* with domain and scale, and a value provision. Can be generated through a builder
* notation and stored within the Parameter object (as a container).
*/
template<typename VAL, class IFA =Disposition> /////////////////////////////////////////////////////TICKET #1197 : the second template argument is quite confusing and became necessary due to the limitations of PolymorphicValue
class ParamData
: public TypedEntity<VAL, IFA>
{
VAL val_;
Provision* src_;
/* === Provision Interface === */
void retrieveInto (ValBuff&) const override;
void setValFrom (ValBuff const&) override;
public:
ParamData (VAL initVal)
: val_{std::move (initVal)}
, src_{nullptr}
{ }
};
template<typename X>
using FullDomain = BaseDomain<X, Disposition>;
template<typename VAL, class IFA>
void
ParamData<VAL, IFA>::retrieveInto (ValBuff& target) const
{
asValue<VAL>(target) = val_;
}
template<typename VAL, class IFA>
void
ParamData<VAL, IFA>::setValFrom (ValBuff const& newVal)
{
val_ = asValue<VAL>(newVal);
}
template<typename X>
X
Disposition::extract() const
{
X result; // RVO
if (isBaseDomainMatch<X>())
{ // short-circuit by direct force-cast
retrieveInto (asValBuff (result));
}
else
{ // run full type-conversion dispatch
ValStorage valueBuffer;
this->retrieveInto (valueBuffer);
this->extractAs (result, valueBuffer);
}
return result;
}
template<typename X>
void
Disposition::setVal (X changedVal)
{
if (isBaseDomainMatch<X>())
{ // short-circuit by direct force-cast
setValFrom (asValBuff (changedVal));
}
else
{ // run full type-conversion dispatch
ValStorage valueBuffer;
this->conform (valueBuffer, changedVal);
this->setValFrom (valueBuffer);
}
}
template<typename X>
bool
Disposition::isBaseDomainMatch() const
{
return false; /////////////////////////OOO running into a dead end here? how can we possibly access a type tag marker without indirection??
}
}} // namespace lib::par
#endif /*LIB_PAR_DISPOSITION_H*/