Skip to content

Commit

Permalink
BH_DCC_DCU: Use ActionLambda from MMDevice
Browse files Browse the repository at this point in the history
  • Loading branch information
marktsuchida committed Dec 6, 2023
1 parent 5602d99 commit 8459a7c
Showing 1 changed file with 21 additions and 30 deletions.
51 changes: 21 additions & 30 deletions DeviceAdapters/BH_DCC_DCU/DCCDCUDevices.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,6 @@
#include <string>
#include <utility>

// This can be moved to DeviceBase.h to make available generally.
class ActionLambda final : public MM::ActionFunctor {
std::function<int(MM::PropertyBase*, MM::ActionType)> f_;

public:
template <typename F> explicit ActionLambda(F f) : f_(f) {}

auto Execute(MM::PropertyBase* pProp, MM::ActionType eAct) -> int {
return f_(pProp, eAct);
}
};

template <DCCOrDCU Model> inline auto ModelName() -> std::string {
if (Model == DCCOrDCU::DCC) {
return "DCC";
Expand Down Expand Up @@ -426,8 +414,9 @@ class DCCDCUModuleDevice : public CGenericBase<DCCDCUModuleDevice<Model>> {
const std::string& name) {
this->CreateStringProperty(
name.c_str(), "Off", false,
new ActionLambda([this, connNo, feature, name](
MM::PropertyBase* pProp, MM::ActionType eAct) {
new MM::ActionLambda([this, connNo, feature,
name](MM::PropertyBase* pProp,
MM::ActionType eAct) {
if (eAct == MM::BeforeGet) {
short err{};
const bool flag =
Expand Down Expand Up @@ -467,8 +456,9 @@ class DCCDCUModuleDevice : public CGenericBase<DCCDCUModuleDevice<Model>> {
float maxValue) {
this->CreateFloatProperty(
name.c_str(), minValue, false,
new ActionLambda([this, connNo, feature, name](
MM::PropertyBase* pProp, MM::ActionType eAct) {
new MM::ActionLambda([this, connNo, feature,
name](MM::PropertyBase* pProp,
MM::ActionType eAct) {
if (eAct == MM::BeforeGet) {
short err{};
const float value =
Expand Down Expand Up @@ -506,8 +496,9 @@ class DCCDCUModuleDevice : public CGenericBase<DCCDCUModuleDevice<Model>> {
const std::string& name) {
this->CreateIntegerProperty(
name.c_str(), 0, false,
new ActionLambda([this, connNo, feature, name](
MM::PropertyBase* pProp, MM::ActionType eAct) {
new MM::ActionLambda([this, connNo, feature,
name](MM::PropertyBase* pProp,
MM::ActionType eAct) {
if (eAct == MM::BeforeGet) {
short err{};
const unsigned value =
Expand Down Expand Up @@ -547,8 +538,8 @@ class DCCDCUModuleDevice : public CGenericBase<DCCDCUModuleDevice<Model>> {
const std::string& name) {
this->CreateStringProperty(
name.c_str(), "Off", false,
new ActionLambda([this, connNo](MM::PropertyBase* pProp,
MM::ActionType eAct) {
new MM::ActionLambda([this, connNo](MM::PropertyBase* pProp,
MM::ActionType eAct) {
// There is no readout for enable_outputs, so we rely on the
// last-set value.
if (eAct == MM::AfterSet) {
Expand Down Expand Up @@ -577,8 +568,8 @@ class DCCDCUModuleDevice : public CGenericBase<DCCDCUModuleDevice<Model>> {
void CreateEnableAllOutputsProperty() {
this->CreateStringProperty(
"EnableOutputs", "Off", false,
new ActionLambda([this](MM::PropertyBase* pProp,
MM::ActionType eAct) {
new MM::ActionLambda([this](MM::PropertyBase* pProp,
MM::ActionType eAct) {
// There is no readout for enable_outputs, so we rely on the
// last-set value.
if (eAct == MM::AfterSet) {
Expand Down Expand Up @@ -609,8 +600,8 @@ class DCCDCUModuleDevice : public CGenericBase<DCCDCUModuleDevice<Model>> {
const std::string& name) {
this->CreateStringProperty(
name.c_str(), "", false,
new ActionLambda([this, connNo](MM::PropertyBase* pProp,
MM::ActionType eAct) {
new MM::ActionLambda([this, connNo](MM::PropertyBase* pProp,
MM::ActionType eAct) {
if (eAct == MM::AfterSet) {
std::string propVal;
pProp->Get(propVal);
Expand All @@ -634,8 +625,8 @@ class DCCDCUModuleDevice : public CGenericBase<DCCDCUModuleDevice<Model>> {
void CreateClearAllOverloadsProperty() {
this->CreateStringProperty(
"ClearOverloads", "", false,
new ActionLambda([this](MM::PropertyBase* pProp,
MM::ActionType eAct) {
new MM::ActionLambda([this](MM::PropertyBase* pProp,
MM::ActionType eAct) {
if (eAct == MM::AfterSet) {
std::string propVal;
pProp->Get(propVal);
Expand All @@ -660,8 +651,8 @@ class DCCDCUModuleDevice : public CGenericBase<DCCDCUModuleDevice<Model>> {
const std::string& name) {
this->CreateStringProperty(
name.c_str(), "No", true,
new ActionLambda([this, connNo](MM::PropertyBase* pProp,
MM::ActionType eAct) {
new MM::ActionLambda([this, connNo](MM::PropertyBase* pProp,
MM::ActionType eAct) {
if (eAct == MM::BeforeGet) {
short err{};
const bool flag = module_->IsOverloaded(connNo, err);
Expand Down Expand Up @@ -691,8 +682,8 @@ class DCCDCUModuleDevice : public CGenericBase<DCCDCUModuleDevice<Model>> {
const std::string& name) {
this->CreateStringProperty(
name.c_str(), "No", true,
new ActionLambda([this, connNo](MM::PropertyBase* pProp,
MM::ActionType eAct) {
new MM::ActionLambda([this, connNo](MM::PropertyBase* pProp,
MM::ActionType eAct) {
if (eAct == MM::BeforeGet) {
short err{};
const bool flag =
Expand Down

0 comments on commit 8459a7c

Please sign in to comment.