summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/core/param.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/netlist/core/param.h')
-rw-r--r--src/lib/netlist/core/param.h127
1 files changed, 76 insertions, 51 deletions
diff --git a/src/lib/netlist/core/param.h b/src/lib/netlist/core/param.h
index 388ccebc1ba..34e6c3b1b1e 100644
--- a/src/lib/netlist/core/param.h
+++ b/src/lib/netlist/core/param.h
@@ -9,7 +9,6 @@
#define NL_CORE_PARAM_H_
#include "../nltypes.h"
-
#include "base_objects.h"
#include "core_device.h"
#include "setup.h"
@@ -30,16 +29,17 @@ namespace netlist
class param_t : public detail::device_object_t
{
public:
-
- enum param_type_t {
+ enum param_type_t
+ {
STRING,
DOUBLE,
INTEGER,
LOGIC,
- POINTER // Special-case which is always initialized at MAME startup time
+ POINTER // Special-case which is always initialized at MAME startup
+ // time
};
- //device-less, it's the responsibility of the owner to register!
+ // device-less, it's the responsibility of the owner to register!
param_t(const pstring &name);
param_t(core_device_t &device, const pstring &name);
@@ -52,7 +52,6 @@ namespace netlist
virtual pstring value_string() const = 0;
protected:
-
pstring get_initial(const core_device_t *dev, bool *found) const;
template <typename C>
@@ -64,7 +63,6 @@ namespace netlist
device().update_param();
}
}
-
};
// -----------------------------------------------------------------------------
@@ -72,17 +70,21 @@ namespace netlist
// -----------------------------------------------------------------------------
template <typename T>
- class param_num_t final: public param_t
+ class param_num_t final : public param_t
{
public:
using value_type = T;
- param_num_t(core_device_t &device, const pstring &name, T val) noexcept(false);
+ param_num_t(core_device_t &device, const pstring &name, T val) noexcept(
+ false);
constexpr const T &operator()() const noexcept { return m_param; }
- constexpr operator const T& () const noexcept { return m_param; }
+ constexpr operator const T &() const noexcept { return m_param; }
- void set(const T &param) noexcept { set_and_update_param(m_param, param); }
+ void set(const T &param) noexcept
+ {
+ set_and_update_param(m_param, param);
+ }
pstring value_string() const override
{
@@ -94,22 +96,27 @@ namespace netlist
};
template <typename T>
- class param_enum_t final: public param_t
+ class param_enum_t final : public param_t
{
public:
using value_type = T;
- param_enum_t(core_device_t &device, const pstring &name, T val) noexcept(false);
+ param_enum_t(core_device_t &device, const pstring &name,
+ T val) noexcept(false);
constexpr T operator()() const noexcept { return m_param; }
- constexpr operator T() const noexcept { return m_param; }
- void set(const T &param) noexcept { set_and_update_param(m_param, param); }
+ constexpr operator T() const noexcept { return m_param; }
+ void set(const T &param) noexcept
+ {
+ set_and_update_param(m_param, param);
+ }
pstring value_string() const override
{
// returns the numerical value
return plib::pfmt("{}")(static_cast<int>(m_param));
}
+
private:
T m_param;
};
@@ -119,21 +126,25 @@ namespace netlist
// -----------------------------------------------------------------------------
// FIXME: not a core component -> legacy
- class param_ptr_t final: public param_t
+ class param_ptr_t final : public param_t
{
public:
- param_ptr_t(core_device_t &device, const pstring &name, std::uint8_t* val);
- std::uint8_t * operator()() const noexcept { return m_param; }
- void set(std::uint8_t *param) noexcept { set_and_update_param(m_param, param); }
+ param_ptr_t(core_device_t &device, const pstring &name,
+ std::uint8_t *val);
+ std::uint8_t *operator()() const noexcept { return m_param; }
+ void set(std::uint8_t *param) noexcept
+ {
+ set_and_update_param(m_param, param);
+ }
pstring value_string() const override
{
// returns something which errors
- return { "PTRERROR" };
+ return {"PTRERROR"};
}
private:
- std::uint8_t* m_param;
+ std::uint8_t *m_param;
};
// -----------------------------------------------------------------------------
@@ -143,11 +154,16 @@ namespace netlist
class param_str_t : public param_t
{
public:
- param_str_t(core_device_t &device, const pstring &name, const pstring &val);
- param_str_t(netlist_state_t &state, const pstring &name, const pstring &val);
+ param_str_t(core_device_t &device, const pstring &name,
+ const pstring &val);
+ // FIXME: The device less constructor is only used by macro parameters
+ // Every macro device gets a nld_wrapper object as the owner.
+ // Use this as the owner and get rid of this constructor.
+ param_str_t(netlist_state_t &state, const pstring &name,
+ const pstring &val);
pstring operator()() const noexcept { return str(); }
- void set(const pstring &param)
+ void set(const pstring &param)
{
if (*m_param != param)
{
@@ -156,14 +172,12 @@ namespace netlist
device().update_param();
}
}
- pstring value_string() const override
- {
- return *m_param;
- }
+ pstring value_string() const override { return *m_param; }
protected:
virtual void changed() noexcept;
- pstring str() const noexcept { return *m_param; }
+ pstring str() const noexcept { return *m_param; }
+
private:
host_arena::unique_ptr<pstring> m_param;
};
@@ -175,23 +189,26 @@ namespace netlist
class param_model_t : public param_str_t
{
public:
-
template <typename T>
class value_base_t
{
public:
- template <typename P, typename Y=T, typename DUMMY = std::enable_if_t<plib::is_arithmetic<Y>::value>>
+ template <typename P, typename Y = T,
+ typename DUMMY = std::enable_if_t<
+ plib::is_arithmetic<Y>::value>>
value_base_t(P &param, const pstring &name)
: m_value(gsl::narrow<T>(param.value(name)))
{
}
- template <typename P, typename Y=T, std::enable_if_t<!plib::is_arithmetic<Y>::value, int> = 0>
+ template <typename P, typename Y = T,
+ std::enable_if_t<!plib::is_arithmetic<Y>::value, int> = 0>
value_base_t(P &param, const pstring &name)
: m_value(static_cast<T>(param.value_str(name)))
{
}
T operator()() const noexcept { return m_value; }
- operator T() const noexcept { return m_value; }
+ operator T() const noexcept { return m_value; }
+
private:
const T m_value;
};
@@ -199,18 +216,21 @@ namespace netlist
using value_t = value_base_t<nl_fptype>;
using value_str_t = value_base_t<pstring>;
- param_model_t(core_device_t &device, const pstring &name, const pstring &val)
+ param_model_t(core_device_t &device, const pstring &name,
+ const pstring &val)
: param_str_t(device, name, val)
{
}
- pstring value_str(const pstring &entity);
+ pstring value_str(const pstring &entity);
nl_fptype value(const pstring &entity);
- pstring type();
+ pstring type();
// hide this
void set(const pstring &param) = delete;
+
protected:
void changed() noexcept override;
+
private:
};
@@ -227,8 +247,9 @@ namespace netlist
}
plib::istream_uptr stream();
+
protected:
- void changed() noexcept override { }
+ void changed() noexcept override {}
};
// -----------------------------------------------------------------------------
@@ -236,17 +257,17 @@ namespace netlist
// -----------------------------------------------------------------------------
template <typename ST, std::size_t AW, std::size_t DW>
- class param_rom_t final: public param_data_t
+ class param_rom_t final : public param_data_t
{
public:
-
param_rom_t(core_device_t &device, const pstring &name);
- const ST & operator[] (std::size_t n) const noexcept { return m_data[n]; }
+ const ST &operator[](std::size_t n) const noexcept { return m_data[n]; }
+
protected:
void changed() noexcept override
{
- plib::istream_read(*stream(), m_data.data(), 1<<AW);
+ plib::istream_read(*stream(), m_data.data(), 1 << AW);
}
private:
@@ -254,11 +275,12 @@ namespace netlist
};
template <typename T>
- param_num_t<T>::param_num_t(core_device_t &device, const pstring &name, const T val)
+ param_num_t<T>::param_num_t(core_device_t &device, const pstring &name,
+ const T val)
: param_t(device, name)
, m_param(val)
{
- bool found = false;
+ bool found = false;
pstring p = this->get_initial(&device, &found);
if (found)
{
@@ -267,7 +289,8 @@ namespace netlist
auto valx = func.evaluate();
if (plib::is_integral<T>::value)
if (plib::abs(valx - plib::trunc(valx)) > nlconst::magic(1e-6))
- throw nl_exception(MF_INVALID_NUMBER_CONVERSION_1_2(device.name() + "." + name, p));
+ throw nl_exception(MF_INVALID_NUMBER_CONVERSION_1_2(
+ device.name() + "." + name, p));
m_param = plib::narrow_cast<T>(valx);
}
@@ -275,19 +298,21 @@ namespace netlist
}
template <typename T>
- param_enum_t<T>::param_enum_t(core_device_t &device, const pstring &name, const T val)
+ param_enum_t<T>::param_enum_t(core_device_t &device, const pstring &name,
+ const T val)
: param_t(device, name)
, m_param(val)
{
- bool found = false;
+ bool found = false;
pstring p = this->get_initial(&device, &found);
if (found)
{
- T temp(val);
+ T temp(val);
bool ok = temp.set_from_string(p);
if (!ok)
{
- device.state().log().fatal(MF_INVALID_ENUM_CONVERSION_1_2(name, p));
+ device.state().log().fatal(
+ MF_INVALID_ENUM_CONVERSION_1_2(name, p));
throw nl_exception(MF_INVALID_ENUM_CONVERSION_1_2(name, p));
}
m_param = temp;
@@ -297,13 +322,14 @@ namespace netlist
}
template <typename ST, std::size_t AW, std::size_t DW>
- param_rom_t<ST, AW, DW>::param_rom_t(core_device_t &device, const pstring &name)
+ param_rom_t<ST, AW, DW>::param_rom_t(core_device_t &device,
+ const pstring & name)
: param_data_t(device, name)
{
auto f = this->stream();
if (!f.empty())
{
- plib::istream_read(*f, m_data.data(), 1<<AW);
+ plib::istream_read(*f, m_data.data(), 1 << AW);
// FIXME: check for failbit if not in validation.
}
else
@@ -338,5 +364,4 @@ namespace netlist
} // namespace netlist
-
#endif // NL_CORE_PARAM_H_