summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib
diff options
context:
space:
mode:
author Nathan Woods <npwoods@mess.org>2016-09-12 20:33:05 -0400
committer Nathan Woods <npwoods@mess.org>2016-09-12 20:33:05 -0400
commit714b78d0846bfdc3af3c18a311f8ba00c72eb90b (patch)
treea30ab48943a8e9e05c5482f96b8d3f1427b44666 /src/lib
parent88c952adb3977af65872175228a72727b693ed06 (diff)
Folded util::contiguous_sequence_wrapper<T> into coretmpl.h, and fixing the reverse_iterators
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/util/contiguous_sequence_wrapper.h89
-rw-r--r--src/lib/util/coretmpl.h70
-rw-r--r--src/lib/util/opresolv.h2
3 files changed, 71 insertions, 90 deletions
diff --git a/src/lib/util/contiguous_sequence_wrapper.h b/src/lib/util/contiguous_sequence_wrapper.h
deleted file mode 100644
index d911c4de27b..00000000000
--- a/src/lib/util/contiguous_sequence_wrapper.h
+++ /dev/null
@@ -1,89 +0,0 @@
-// 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; }
-
- // reverse iteration
- std::reverse_iterator<iterator> rbegin() { return std::reverse_iterator<iterator>(end() - 1); }
- std::reverse_iterator<const_iterator> rbegin() const { return std::reverse_iterator<const_iterator>(end() - 1); }
- std::reverse_iterator<const_iterator> crbegin() const { return std::reverse_iterator<const_iterator>(cend() - 1); }
- std::reverse_iterator<iterator> rend() { return std::reverse_iterator<iterator>(begin() - 1); }
- std::reverse_iterator<const_iterator> rend() const { return std::reverse_iterator<iterator>(begin() - 1); }
- std::reverse_iterator<const_iterator> crend() const { return std::reverse_iterator<iterator>(begin() - 1); }
-
- // 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[n]; }
- const_reference operator[] (size_type n) const { return m_begin[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/coretmpl.h b/src/lib/util/coretmpl.h
index b0e283378ed..fc88afeab69 100644
--- a/src/lib/util/coretmpl.h
+++ b/src/lib/util/coretmpl.h
@@ -351,4 +351,74 @@ private:
};
+// ======================> contiguous_sequence_wrapper
+
+namespace util {
+
+// wraps an existing sequence of values
+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; }
+
+ // reverse iteration
+ std::reverse_iterator<iterator> rbegin() { return std::reverse_iterator<iterator>(end()); }
+ std::reverse_iterator<const_iterator> rbegin() const { return std::reverse_iterator<const_iterator>(end()); }
+ std::reverse_iterator<const_iterator> crbegin() const { return std::reverse_iterator<const_iterator>(cend()); }
+ std::reverse_iterator<iterator> rend() { return std::reverse_iterator<iterator>(begin()); }
+ std::reverse_iterator<const_iterator> rend() const { return std::reverse_iterator<iterator>(begin()); }
+ std::reverse_iterator<const_iterator> crend() const { return std::reverse_iterator<iterator>(begin()); }
+
+ // 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[n]; }
+ const_reference operator[] (size_type n) const { return m_begin[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
diff --git a/src/lib/util/opresolv.h b/src/lib/util/opresolv.h
index 76c1f296736..760e6a237e8 100644
--- a/src/lib/util/opresolv.h
+++ b/src/lib/util/opresolv.h
@@ -45,7 +45,7 @@
#include <vector>
#include <string>
-#include "contiguous_sequence_wrapper.h"
+#include "coretmpl.h"
//**************************************************************************