summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib
diff options
context:
space:
mode:
author Nathan Woods <npwoods@mess.org>2016-09-02 23:52:30 -0400
committer Nathan Woods <npwoods@mess.org>2016-09-02 23:52:30 -0400
commit965fb61f95c4f788278b9a338c02586dc2fb04ed (patch)
tree65d570833400d3d251899816c73df4fcc316cb10 /src/lib
parent2c9e00b96d89b78203c0b11b7bdcfd28f3792d96 (diff)
Attempting to make option_guide and option_guide::entry POD types; need to figure out a better way to do OPTION_GUIDE_EXTERN
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/formats/flopimg.cpp3
-rw-r--r--src/lib/util/opresolv.cpp8
-rw-r--r--src/lib/util/opresolv.h67
3 files changed, 54 insertions, 24 deletions
diff --git a/src/lib/formats/flopimg.cpp b/src/lib/formats/flopimg.cpp
index 9fb487ba971..e05bd54cf26 100644
--- a/src/lib/formats/flopimg.cpp
+++ b/src/lib/formats/flopimg.cpp
@@ -58,7 +58,7 @@ struct floppy_params
static floperr_t floppy_track_unload(floppy_image_legacy *floppy);
-OPTION_GUIDE_START(floppy_option_guide)
+OPTION_GUIDE_START(floppy_option_guide_actual)
OPTION_INT('H', "heads", "Heads")
OPTION_INT('T', "tracks", "Tracks")
OPTION_INT('S', "sectors", "Sectors")
@@ -66,6 +66,7 @@ OPTION_GUIDE_START(floppy_option_guide)
OPTION_INT('I', "interleave", "Interleave")
OPTION_INT('F', "firstsectorid", "First Sector")
OPTION_GUIDE_END
+const util::option_guide &floppy_option_guide = floppy_option_guide_actual;
static void floppy_close_internal(floppy_image_legacy *floppy, int close_file);
diff --git a/src/lib/util/opresolv.cpp b/src/lib/util/opresolv.cpp
index b707508dcac..358305a9576 100644
--- a/src/lib/util/opresolv.cpp
+++ b/src/lib/util/opresolv.cpp
@@ -31,11 +31,11 @@ namespace util {
option_resolution::option_resolution(const option_guide &guide)
{
// reserve space for entries
- m_entries.reserve(guide.entries().size());
+ m_entries.reserve(guide.end() - guide.begin());
// initialize each of the entries; can't use foreach because we need to scan the
// ENUM_VALUE entries
- for (auto iter = guide.entries().cbegin(); iter != guide.entries().cend(); iter++)
+ for (auto iter = guide.begin(); iter != guide.end(); iter++)
{
// create the entry
m_entries.emplace_back(*iter);
@@ -49,7 +49,7 @@ option_resolution::option_resolution(const option_guide &guide)
auto enum_value_end = enum_value_begin;
// and identify all entries of type ENUM_VALUE
- while (enum_value_end != guide.entries().end() && enum_value_end->type() == option_guide::entry::option_type::ENUM_VALUE)
+ while (enum_value_end != guide.end() && enum_value_end->type() == option_guide::entry::option_type::ENUM_VALUE)
{
iter++;
enum_value_end++;
@@ -212,7 +212,7 @@ option_resolution::entry::entry(const option_guide::entry &guide_entry)
// entry::set_enum_value_range
// -------------------------------------------------
-void option_resolution::entry::set_enum_value_range(option_guide::entrylist::const_iterator begin, option_guide::entrylist::const_iterator end)
+void option_resolution::entry::set_enum_value_range(const option_guide::entry *begin, const option_guide::entry *end)
{
m_enum_value_begin = begin;
m_enum_value_end = end;
diff --git a/src/lib/util/opresolv.h b/src/lib/util/opresolv.h
index 4c059a88d72..fdc2e6b8758 100644
--- a/src/lib/util/opresolv.h
+++ b/src/lib/util/opresolv.h
@@ -51,20 +51,20 @@
//**************************************************************************
#define OPTION_GUIDE_START(option_guide_) \
- const util::option_guide option_guide_ = \
- {
+ const auto option_guide_ = util::make_option_guide(
#define OPTION_GUIDE_END \
- };
+ util::option_guide::entry(util::option_guide::entry::option_type::INVALID, 0, nullptr, nullptr) \
+ );
#define OPTION_GUIDE_EXTERN(option_guide_) \
- extern const util::option_guide option_guide_
+ extern const util::option_guide &option_guide_
#define OPTION_INT(option_char, identifier, display_name) \
- { util::option_guide::entry::option_type::INT, (option_char), (identifier), (display_name) },
+ util::option_guide::entry(util::option_guide::entry::option_type::INT, (option_char), (identifier), (display_name)),
#define OPTION_STRING(option_char, identifier, display_name) \
- { util::option_guide::entry::option_type::STRING, (option_char), (identifier), (display_name) },
+ util::option_guide::entry(util::option_guide::entry::option_type::STRING, (option_char), (identifier), (display_name)),
#define OPTION_ENUM_START(option_char, identifier, display_name) \
- { util::option_guide::entry::option_type::ENUM_BEGIN, (option_char), (identifier), (display_name) },
+ util::option_guide::entry(util::option_guide::entry::option_type::ENUM_BEGIN, (option_char), (identifier), (display_name)),
#define OPTION_ENUM(value, identifier, display_name) \
- { util::option_guide::entry::option_type::ENUM_VALUE, (value), (identifier), (display_name) },
+ util::option_guide::entry(util::option_guide::entry::option_type::ENUM_VALUE, (value), (identifier), (display_name)),
#define OPTION_ENUM_END
namespace util {
@@ -79,12 +79,18 @@ public:
public:
enum class option_type
{
+ INVALID,
INT,
STRING,
ENUM_BEGIN,
ENUM_VALUE
};
+ constexpr entry()
+ : m_type(option_type::INVALID), m_parameter(0), m_identifier(nullptr), m_display_name(nullptr)
+ {
+ }
+
constexpr entry(option_type type, int parameter = 0, const char *identifier = nullptr, const char *display_name = nullptr)
: m_type(type), m_parameter(parameter), m_identifier(identifier), m_display_name(display_name)
{
@@ -103,20 +109,43 @@ public:
const char *m_display_name;
};
- typedef std::vector<option_guide::entry> entrylist;
+ // methods
+ const entry *begin() const { return m_begin; }
+ const entry *end() const { return m_end; }
- option_guide(std::initializer_list<entry> entries)
- : m_entries(entries)
+protected:
+ option_guide(const entry *begin, const entry *end)
+ : m_begin(begin), m_end(end)
{
}
- // methods
- const entrylist &entries() const { return m_entries; }
private:
- entrylist m_entries;
+ const entry *m_begin;
+ const entry *m_end;
};
+// ======================> option_guide_impl
+
+template <std::size_t Count>
+class option_guide_impl : protected std::array<option_guide::entry, Count>, public option_guide
+{
+public:
+ template<typename... T>
+ option_guide_impl(T &&... elems)
+ : std::array<option_guide::entry, Count>({ std::forward<T>(elems)... })
+ , option_guide(&(*this)[0], &(*this)[0] + Count - 1)
+ {
+ }
+};
+
+template <typename... T>
+option_guide_impl<sizeof...(T)> make_option_guide(T &&... elems)
+{
+ return option_guide_impl<sizeof...(T)>(std::forward<T>(elems)...);
+}
+
+
// ======================> option_resolution
class option_resolution
@@ -163,8 +192,8 @@ public:
int value_int() const;
const std::string &default_value() const { return m_default_value; }
const rangelist &ranges() const { return m_ranges; }
- const option_guide::entrylist::const_iterator enum_value_begin() const { return m_enum_value_begin; }
- const option_guide::entrylist::const_iterator enum_value_end() const { return m_enum_value_end; }
+ const option_guide::entry *enum_value_begin() const { return m_enum_value_begin; }
+ const option_guide::entry *enum_value_end() const { return m_enum_value_end; }
// accessors for guide data
option_guide::entry::option_type option_type() const { return m_guide_entry.type(); }
@@ -186,8 +215,8 @@ public:
private:
// references to the option guide
const option_guide::entry & m_guide_entry;
- option_guide::entrylist::const_iterator m_enum_value_begin;
- option_guide::entrylist::const_iterator m_enum_value_end;
+ const option_guide::entry * m_enum_value_begin;
+ const option_guide::entry * m_enum_value_end;
// runtime state
bool m_is_pertinent;
@@ -197,7 +226,7 @@ public:
// methods
void parse_specification(const char *specification);
- void set_enum_value_range(option_guide::entrylist::const_iterator begin, option_guide::entrylist::const_iterator end);
+ void set_enum_value_range(const option_guide::entry *begin, const option_guide::entry *end);
static std::string numeric_value(int value);
rangelist::const_iterator find_in_ranges(int value) const;
};