/* PARAMETER.hpp - generic parameter values Copyright (C) 2008,2026 Hermann Vosseler   **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 "lib/meta/typelist-util.hpp" #include "lib/util.hpp" #include namespace lib { namespace par { namespace { static constexpr size_t BUFF_SIZ = sizeof(ParamData); using ParameterImplAPI = Disposition; using CopySupportMarker = polyvalue::CopySupport; using ParamContainer = PolymorphicValue; } using util::unConst; /** * 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 class Builder; template VAL getVal() const; template void setVal (VAL&&); /* === Builder API === */ template static Builder forType() { return {}; } template static Builder> forValue (VAL&& initVal) { using PayloadType = std::decay_t; return forType() .withValue (std::forward (initVal)); } protected: template Parameter (IMP* typeTag, ARGS&&... args) : PolymorphicValue (typeTag, std::forward(args)...) { } }; template class Parameter::Builder { static_assert (meta::isInList() ,"Only some fixed base data types are supported as Parameter value type."); VAL initVal_{}; public: Parameter build() { using ImplPackage = ParamData; ImplPackage* typeTag{nullptr}; Parameter resParam{typeTag, std::move (initVal_)}; return resParam; } template Builder&& withValue (X&& initVal) { initVal_ = std::forward (initVal); return std::move(this); } }; template VAL Parameter::getVal() const { return unConst(this)->getPayload().extract(); } template void Parameter::setVal (VAL&& changedVal) { getPayload().setVal (changedVal); } }} // namespace lib::par #endif /*LIB_PAR_PARAMETER_H*/