More cleanup on the back of Osso's fix for a7e393b36b (nw)

* Make iterators actually meet requirements of ForwardIterator (and by consequence, ForwardIterator, Iterator and EqualityComparable)
* Don't use function statics if they can be avoided - it isn't thread-safe
* Remove leftover crud from when dynamic_buffer and friends were templates in lib/util

It's still dangerous that the const behaviour of iterators doesn't match STL.
Also, simple_list members with similar functionality to STL container members should be renamed.
This commit is contained in:
Vas Crabb 2016-08-30 01:31:23 +10:00
parent 7c6a527e26
commit 46bf1ce04b
5 changed files with 66 additions and 31 deletions

View File

@ -111,7 +111,7 @@ class device_t : public delegate_late_bind
friend class device_t;
friend class machine_config;
public:
public:
// construction/destruction
subdevice_list() { }
@ -125,7 +125,7 @@ public:
auto_iterator begin() const { return m_list.begin(); }
auto_iterator end() const { return m_list.end(); }
private:
private:
// private helpers
device_t *find(const std::string &name) const
{
@ -149,19 +149,28 @@ private:
friend class device_state_interface;
friend class device_execute_interface;
public:
public:
class auto_iterator
{
public:
public:
typedef std::ptrdiff_t difference_type;
typedef device_interface value_type;
typedef device_interface *pointer;
typedef device_interface &reference;
typedef std::forward_iterator_tag iterator_category;
// construction/destruction
auto_iterator(device_interface *intf) : m_current(intf) { }
// required operator overrides
// required operator overloads
bool operator==(const auto_iterator &iter) const { return m_current == iter.m_current; }
bool operator!=(const auto_iterator &iter) const { return m_current != iter.m_current; }
device_interface &operator*() const { return *m_current; }
const auto_iterator &operator++();
device_interface *operator->() const { return m_current; }
auto_iterator &operator++();
auto_iterator operator++(int);
private:
private:
// private state
device_interface *m_current;
};
@ -176,8 +185,8 @@ private:
auto_iterator begin() const { return auto_iterator(m_head); }
auto_iterator end() const { return auto_iterator(nullptr); }
private:
device_interface * m_head; // head of interface list
private:
device_interface *m_head; // head of interface list
device_execute_interface *m_execute; // pre-cached pointer to execute interface
device_memory_interface *m_memory; // pre-cached pointer to memory interface
device_state_interface *m_state; // pre-cached pointer to state interface
@ -768,12 +777,19 @@ inline device_t *device_t::siblingdevice(const char *tag) const
}
// this operator requires device_interface to be a complete type
inline const device_t::interface_list::auto_iterator &device_t::interface_list::auto_iterator::operator++()
// these operators requires device_interface to be a complete type
inline device_t::interface_list::auto_iterator &device_t::interface_list::auto_iterator::operator++()
{
m_current = m_current->interface_next();
return *this;
}
inline device_t::interface_list::auto_iterator device_t::interface_list::auto_iterator::operator++(int)
{
auto_iterator result(*this);
m_current = m_current->interface_next();
return result;
}
#endif /* __DEVICE_H__ */

View File

@ -4038,7 +4038,7 @@ memory_block::memory_block(address_space &space, offs_t bytestart, offs_t byteen
m_byteend(byteend),
m_data(reinterpret_cast<UINT8 *>(memory))
{
offs_t length = byteend + 1 - bytestart;
offs_t const length = byteend + 1 - bytestart;
VPRINTF(("block_allocate('%s',%s,%08X,%08X,%p)\n", space.device().tag(), space.name(), bytestart, byteend, memory));
// allocate a block if needed

View File

@ -1041,6 +1041,8 @@ private:
simple_list<item> m_bezel_list; // list of bezel items
simple_list<item> m_cpanel_list; // list of marquee items
simple_list<item> m_marquee_list; // list of marquee items
static const simple_list<item> s_null_list;
};

View File

@ -2208,6 +2208,8 @@ void layout_element::component::apply_skew(bitmap_argb32 &dest, int skewwidth)
// LAYOUT VIEW
//**************************************************************************
const simple_list<layout_view::item> layout_view::s_null_list;
//-------------------------------------------------
// layout_view - constructor
//-------------------------------------------------
@ -2270,8 +2272,6 @@ layout_view::~layout_view()
const simple_list<layout_view::item> &layout_view::items(item_layer layer) const
{
static simple_list<item> s_null_list;
switch (layer)
{
case ITEM_LAYER_BACKDROP: return m_backdrop_list;

View File

@ -16,14 +16,10 @@
#include "osdcore.h"
#include "corealloc.h"
#include <iterator>
#include <utility>
#include <vector>
// TEMPORARY helper to catch is_pod assertions in the debugger
#if 0
#undef assert
#define assert(x) do { if (!(x)) { fprintf(stderr, "Assert: %s\n", #x); osd_break_into_debugger("Assertion failed"); } } while (0)
#endif
typedef std::vector<UINT8> dynamic_buffer;
@ -38,32 +34,53 @@ class simple_list final
public:
class auto_iterator
{
public:
public:
typedef int difference_type;
typedef _ElementType value_type;
typedef _ElementType *pointer;
typedef _ElementType &reference;
typedef std::forward_iterator_tag iterator_category;
// construction/destruction
auto_iterator() noexcept : m_current(nullptr) { }
auto_iterator(_ElementType *ptr) noexcept : m_current(ptr) { }
// required operator overrides
// required operator overloads
bool operator==(const auto_iterator &iter) const noexcept { return m_current == iter.m_current; }
bool operator!=(const auto_iterator &iter) const noexcept { return m_current != iter.m_current; }
_ElementType &operator*() const noexcept { return *m_current; }
_ElementType *operator->() const noexcept { return m_current; }
// note that _ElementType::next() must not return a const ptr
const auto_iterator &operator++() noexcept { m_current = m_current->next(); return *this; }
auto_iterator &operator++() noexcept { m_current = m_current->next(); return *this; }
auto_iterator operator++(int) noexcept { auto_iterator result(*this); m_current = m_current->next(); return result; }
private:
private:
// private state
_ElementType *m_current;
};
// construction/destruction
simple_list() noexcept
: m_head(nullptr)
, m_tail(nullptr)
, m_count(0)
{
}
~simple_list() noexcept { reset(); }
// we don't support deep copying
simple_list(const simple_list &) = delete;
simple_list &operator=(const simple_list &) = delete;
// construction/destruction
simple_list() noexcept
: m_head(nullptr),
m_tail(nullptr),
m_count(0) { }
~simple_list() noexcept { reset(); }
// but we do support cheap swap/move
simple_list(simple_list &&list) : simple_list() { operator=(std::move(list)); }
simple_list &operator=(simple_list &&list)
{
using std::swap;
swap(m_head, list.m_head);
swap(m_tail, list.m_tail);
swap(m_count, list.m_count);
}
// simple getters
_ElementType *first() const noexcept { return m_head; }