mirror of
https://github.com/TomHarte/CLK.git
synced 2026-04-24 05:18:36 +00:00
Adds transcoding of ostensible list selections to Boolean selections, and vice versa.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Configurable.cpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 18/11/2017.
|
||||
// Copyright © 2017 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#include "Configurable.hpp"
|
||||
|
||||
using namespace Configurable;
|
||||
|
||||
ListSelection *BooleanSelection::list_selection() {
|
||||
return new ListSelection(value ? "yes" : "no");
|
||||
}
|
||||
|
||||
ListSelection *ListSelection::list_selection() {
|
||||
return new ListSelection(value);
|
||||
}
|
||||
|
||||
BooleanSelection *ListSelection::boolean_selection() {
|
||||
return new BooleanSelection(value != "no" && value != "n");
|
||||
}
|
||||
|
||||
BooleanSelection *BooleanSelection::boolean_selection() {
|
||||
return new BooleanSelection(value);
|
||||
}
|
||||
@@ -37,20 +37,31 @@ struct ListOption: public Option {
|
||||
ListOption(const std::string &long_name, const std::string &short_name, const std::vector<std::string> &options) : Option(long_name, short_name), options(options) {}
|
||||
};
|
||||
|
||||
struct BooleanSelection;
|
||||
struct ListSelection;
|
||||
|
||||
/*!
|
||||
Selections are responses to Options.
|
||||
*/
|
||||
struct Selection {
|
||||
virtual ~Selection() {}
|
||||
virtual ListSelection *list_selection() = 0;
|
||||
virtual BooleanSelection *boolean_selection() = 0;
|
||||
};
|
||||
|
||||
struct BooleanSelection: public Selection {
|
||||
bool value;
|
||||
|
||||
ListSelection *list_selection();
|
||||
BooleanSelection *boolean_selection();
|
||||
BooleanSelection(bool value) : value(value) {}
|
||||
};
|
||||
|
||||
struct ListSelection: public Selection {
|
||||
std::string value;
|
||||
|
||||
ListSelection *list_selection();
|
||||
BooleanSelection *boolean_selection();
|
||||
ListSelection(const std::string value) : value(value) {}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user