mirror of
https://github.com/holub/mame
synced 2025-05-03 04:56:45 +03:00
Attempting to make option_guide and option_guide::entry POD types; need to figure out a better way to do OPTION_GUIDE_EXTERN
This commit is contained in:
parent
2c9e00b96d
commit
965fb61f95
@ -1227,7 +1227,8 @@ void device_image_interface::unload()
|
||||
// create_option_guide
|
||||
//-------------------------------------------------
|
||||
|
||||
static const util::option_guide null_option_guide = {};
|
||||
static OPTION_GUIDE_START(null_option_guide)
|
||||
OPTION_GUIDE_END
|
||||
|
||||
const util::option_guide &device_image_interface::create_option_guide() const
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user