summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib
diff options
context:
space:
mode:
author Nathan Woods <npwoods@mess.org>2016-09-12 06:56:55 -0400
committer Nathan Woods <npwoods@mess.org>2016-09-12 06:56:55 -0400
commitaf1c5b26b84922e26e4ff0d9ec2299db6a7135ee (patch)
treed689ab522c6280b4fceb7fe575503f77b7312e05 /src/lib
parent91fb8f5bc3ff97df38344497af53ab45b9ce1895 (diff)
Renamed util::view<T> to util::contiguous_sequence_wrapper<T>, changed ::iterator and ::const_iterator to just be pointers and other cleanups
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/util/contiguous_sequence_wrapper.h81
-rw-r--r--src/lib/util/opresolv.h6
-rw-r--r--src/lib/util/view.h154
3 files changed, 84 insertions, 157 deletions
diff --git a/src/lib/util/contiguous_sequence_wrapper.h b/src/lib/util/contiguous_sequence_wrapper.h
new file mode 100644
index 00000000000..84dc0054d4a
--- /dev/null
+++ b/src/lib/util/contiguous_sequence_wrapper.h
@@ -0,0 +1,81 @@
+// license:BSD-3-Clause
+// copyright-holders:Nathan Woods
+/******************************************************************************
+
+ contiguous_sequence_wrapper.h
+
+ STL container that points to an existing contiguous sequence
+
+***************************************************************************/
+
+#pragma once
+
+#ifndef MAME_LIB_UTIL_CONTIGUOUS_SEQUENCE_WRAPPER_H
+#define MAME_LIB_UTIL_CONTIGUOUS_SEQUENCE_WRAPPER_H
+
+#include <cstddef>
+
+namespace util {
+
+//**************************************************************************
+// TYPE DEFINITIONS
+//**************************************************************************
+
+template<typename T >
+class contiguous_sequence_wrapper
+{
+public:
+ typedef std::ptrdiff_t difference_type;
+ typedef std::size_t size_type;
+ typedef T value_type;
+ typedef T &reference;
+ typedef const T &const_reference;
+ typedef T *pointer;
+ typedef T *iterator;
+ typedef const T *const_iterator;
+
+ contiguous_sequence_wrapper(T *ptr, std::size_t size)
+ : m_begin(ptr)
+ , m_end(ptr + size)
+ {
+ }
+
+ contiguous_sequence_wrapper(const contiguous_sequence_wrapper &that) = default;
+
+ // iteration
+ iterator begin() { return m_begin; }
+ const_iterator begin() const { return m_begin; }
+ const_iterator cbegin() const { return m_begin; }
+ iterator end() { return m_end; }
+ const_iterator end() const { return m_end; }
+ const_iterator cend() const { return m_end; }
+
+ // capacity
+ size_type size() const { return m_end - m_begin; }
+ size_type max_size() const { return size(); }
+ bool empty() const { return size() > 0; }
+
+ // element access
+ reference front() { return operator[](0); }
+ const_reference front() const { return operator[](0); }
+ reference back() { return operator[](size() - 1); }
+ const_reference back() const { return operator[](size() - 1); }
+ reference operator[] (size_type n) { return m_begin.m_ptr[n]; }
+ const_reference operator[] (size_type n) const { return m_begin.m_ptr[n]; }
+ reference at(size_type n) { check_in_bounds(n); return operator[](n); }
+ const_reference at(size_type n) const { check_in_bounds(n); return operator[](n); }
+
+private:
+ iterator m_begin;
+ iterator m_end;
+
+ void check_in_bounds(size_type n)
+ {
+ if (n < 0 || n >= size())
+ throw new std::out_of_range("invalid contiguous_sequence_wrapper<T> subscript");
+ }
+};
+
+}; // namespace util
+
+#endif // MAME_LIB_UTIL_CONTIGUOUS_SEQUENCE_WRAPPER_H
diff --git a/src/lib/util/opresolv.h b/src/lib/util/opresolv.h
index d89c8197a75..76c1f296736 100644
--- a/src/lib/util/opresolv.h
+++ b/src/lib/util/opresolv.h
@@ -45,7 +45,7 @@
#include <vector>
#include <string>
-#include "view.h"
+#include "contiguous_sequence_wrapper.h"
//**************************************************************************
@@ -120,7 +120,7 @@ public:
};
// methods
- const util::view<const entry> &entries() const { return m_entries; }
+ const util::contiguous_sequence_wrapper<const entry> &entries() const { return m_entries; }
protected:
option_guide(const entry *begin, size_t count)
@@ -130,7 +130,7 @@ protected:
private:
- util::view<const entry> m_entries;
+ util::contiguous_sequence_wrapper<const entry> m_entries;
};
// ======================> option_guide_impl
diff --git a/src/lib/util/view.h b/src/lib/util/view.h
deleted file mode 100644
index 7bbccc977aa..00000000000
--- a/src/lib/util/view.h
+++ /dev/null
@@ -1,154 +0,0 @@
-// license:BSD-3-Clause
-// copyright-holders:Nathan Woods
-/******************************************************************************
-
- view.h
-
- STL container for a view
-
-***************************************************************************/
-
-#pragma once
-
-#ifndef __VIEW_H__
-#define __VIEW_H__
-
-#include <cstddef>
-
-namespace util {
-
-//**************************************************************************
-// TYPE DEFINITIONS
-//**************************************************************************
-
-template<typename T >
-class view
-{
-public:
- typedef std::ptrdiff_t difference_type;
- typedef std::size_t size_type;
- typedef T value_type;
- typedef T &reference;
- typedef const T &const_reference;
- typedef T *pointer;
-
- class iterator
- {
- public:
- typedef std::ptrdiff_t difference_type;
- typedef T value_type;
- typedef T &reference;
- typedef T *pointer;
-
- typedef std::random_access_iterator_tag iterator_category;
-
- iterator(T *ptr) : m_ptr(ptr) { }
- iterator(const iterator &that) : m_ptr(that) { }
-
- iterator& operator=(const iterator &that) { m_ptr = that.m_ptr; return *this; }
- bool operator==(const iterator &that) const { return m_ptr == that.m_ptr; }
- bool operator!=(const iterator &that) const { return m_ptr != that.m_ptr; }
- bool operator<(const iterator &that) const { return m_ptr < that.m_ptr; }
- bool operator>(const iterator &that) const { return m_ptr > that.m_ptr; }
- bool operator<=(const iterator &that) const { return m_ptr <= that.m_ptr; }
- bool operator>=(const iterator &that) const { return m_ptr >= that.m_ptr; }
- iterator operator+(size_type i) const { return iterator(m_ptr + i); }
- iterator operator-(size_type i) const { return iterator(m_ptr - i); }
- difference_type operator-(const iterator &that) const { return m_ptr - that.m_ptr; }
-
- iterator& operator++() { m_ptr++; return *this; }
- iterator operator++(int) { iterator result = *this; m_ptr++; return result; }
-
- reference operator*() const { return *m_ptr; }
- pointer operator->() const { return m_ptr; }
- operator T*() const { return m_ptr; }
-
- private:
- T *m_ptr;
- };
-
- class const_iterator
- {
- public:
- typedef std::ptrdiff_t difference_type;
- typedef T value_type;
- typedef const T &const_reference;
- typedef const T *const_pointer;
-
- typedef std::random_access_iterator_tag iterator_category;
-
- const_iterator(const T *ptr) : m_ptr(ptr) { }
- const_iterator(const iterator &that) : m_ptr(that) { }
- const_iterator(const const_iterator &that) : m_ptr(that) { }
-
- const_iterator& operator=(const const_iterator &that) { m_ptr = that.m_ptr; return *this; }
- bool operator==(const const_iterator &that) const { return m_ptr == that.m_ptr; }
- bool operator!=(const const_iterator &that) const { return m_ptr != that.m_ptr; }
- bool operator<(const const_iterator &that) const { return m_ptr < that.m_ptr; }
- bool operator>(const const_iterator &that) const { return m_ptr > that.m_ptr; }
- bool operator<=(const const_iterator &that) const { return m_ptr <= that.m_ptr; }
- bool operator>=(const const_iterator &that) const { return m_ptr >= that.m_ptr; }
- const_iterator operator+(size_type i) const { return const_iterator(m_ptr + i); }
- const_iterator operator-(size_type i) const { return const_iterator(m_ptr - i); }
- difference_type operator-(const const_iterator &that) const { return m_ptr - that.m_ptr; }
-
- const_iterator& operator++() { m_ptr++; return *this; }
- const_iterator operator++(int) { const_iterator result = *this; m_ptr++; return result; }
-
- const_reference operator*() const { return *m_ptr; }
- const_pointer operator->() const { return m_ptr; }
- operator T*() const { return m_ptr; }
-
- private:
- const T *m_ptr;
- };
-
- view(T *ptr, std::size_t size)
- : m_begin(ptr)
- , m_end(ptr + size)
- {
- }
-
- view(const view &that)
- : m_begin(that.m_begin)
- , m_end(that.m_end)
- {
- }
-
- // iteration
- iterator begin() { return m_begin; }
- const_iterator begin() const { return m_begin; }
- const_iterator cbegin() const { return m_begin; }
- iterator end() { return m_end; }
- const_iterator end() const { return m_end; }
- const_iterator cend() const { return m_end; }
-
- // capacity
- size_type size() const { return m_end - m_begin; }
- size_type max_size() const { return size(); }
- bool empty() const { return size() > 0; }
-
- // element access
- reference front() { return *this[0]; }
- const_reference front() const { return *this[0]; }
- reference back() { return *this[size() - 1]; }
- const_reference back() const { return *this[size() - 1]; }
- reference operator[] (size_type n) { return m_begin.m_ptr[n]; }
- const_reference operator[] (size_type n) const { return m_begin.m_ptr[n]; }
- reference at(size_type n) { check_in_bounds(n); return *this[n]; }
- const_reference at(size_type n) const { check_in_bounds(n); return *this[n]; }
-
-private:
- iterator m_begin;
- iterator m_end;
-
- void check_in_bounds(size_type n)
- {
- if (n < 0 || n >= size())
- throw new std::out_of_range("invalid view<T> subscript");
- }
-};
-
-}; // namespace util
-
-#endif // __VIEW_H__