|
|
0ed2f6 |
#pragma once
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
#ifndef TCONSTWRAPPER_INCLUDED
|
|
|
0ed2f6 |
#define TCONSTWRAPPER_INCLUDED
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
#include <cstddef></cstddef>
|
|
|
0ed2f6 |
#include <cassert></cassert>
|
|
|
0ed2f6 |
#include <vector></vector>
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
#include "tcommon.h"
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
#undef DVAPI
|
|
|
0ed2f6 |
#undef DVVAR
|
|
|
0ed2f6 |
#ifdef TNZCORE_EXPORTS
|
|
|
0ed2f6 |
#define DVAPI DV_EXPORT_API
|
|
|
0ed2f6 |
#define DVVAR DV_EXPORT_VAR
|
|
|
0ed2f6 |
#else
|
|
|
0ed2f6 |
#define DVAPI DV_IMPORT_API
|
|
|
0ed2f6 |
#define DVVAR DV_IMPORT_VAR
|
|
|
0ed2f6 |
#endif
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
//=========================================================
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
template<typename t,="" tt="" typename=""></typename>
|
|
|
0ed2f6 |
class TConstArrayWrapperT {
|
|
|
0ed2f6 |
public:
|
|
|
0ed2f6 |
typedef T value_type;
|
|
|
0ed2f6 |
typedef TT src_value_type;
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
class reverse_iterator;
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
class iterator {
|
|
|
0ed2f6 |
private:
|
|
|
0ed2f6 |
const src_value_type *pointer;
|
|
|
0ed2f6 |
friend class TConstArrayWrapperT<value_type, src_value_type="">;</value_type,>
|
|
|
0ed2f6 |
friend class reverse_iterator;
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
explicit iterator(const src_value_type *pointer): pointer(pointer) { }
|
|
|
0ed2f6 |
public:
|
|
|
0ed2f6 |
iterator(): pointer() { }
|
|
|
0ed2f6 |
iterator(const iterator &other): pointer(other.pointer) { }
|
|
|
0ed2f6 |
explicit iterator(const reverse_iterator &other): pointer(other.pointer) { }
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
iterator& operator=(const iterator &other) const { pointer = other.pointer; return *this; }
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
bool operator==(const iterator &other) const { return pointer == other.pointer; }
|
|
|
0ed2f6 |
bool operator!=(const iterator &other) const { return pointer != other.pointer; }
|
|
|
0ed2f6 |
bool operator< (const iterator &other) const { return pointer < other.pointer; }
|
|
|
0ed2f6 |
bool operator> (const iterator &other) const { return pointer > other.pointer; }
|
|
|
0ed2f6 |
bool operator<=(const iterator &other) const { return pointer <= other.pointer; }
|
|
|
0ed2f6 |
bool operator>=(const iterator &other) const { return pointer >= other.pointer; }
|
|
|
0ed2f6 |
ptrdiff_t operator-(const iterator &other) const { return pointer - other.pointer; }
|
|
|
0ed2f6 |
iterator operator+(ptrdiff_t diff) const { return iterator(pointer + diff); }
|
|
|
0ed2f6 |
iterator operator-(ptrdiff_t diff) const { return iterator(pointer - diff); }
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
iterator& operator++() { ++pointer; return *this; }
|
|
|
0ed2f6 |
iterator& operator--() { --pointer; return *this; }
|
|
|
0ed2f6 |
iterator operator++(int) { ++pointer; return iterator(pointer-1); }
|
|
|
0ed2f6 |
iterator operator--(int) { --pointer; return iterator(pointer+1); }
|
|
|
0ed2f6 |
iterator operator+=(ptrdiff_t diff) { pointer += diff; return *this; }
|
|
|
0ed2f6 |
iterator operator-=(ptrdiff_t diff) { pointer -= diff; return *this; }
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
const value_type* operator->() const { assert(pointer); return cast(pointer); }
|
|
|
0ed2f6 |
const value_type& operator*() const { assert(pointer); return *cast(pointer); }
|
|
|
0ed2f6 |
};
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
class reverse_iterator {
|
|
|
0ed2f6 |
private:
|
|
|
0ed2f6 |
const src_value_type *pointer;
|
|
|
0ed2f6 |
friend class TConstArrayWrapperT<value_type, src_value_type="">;</value_type,>
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
explicit reverse_iterator(const src_value_type *pointer): pointer(pointer) { }
|
|
|
0ed2f6 |
public:
|
|
|
0ed2f6 |
reverse_iterator(): pointer() { }
|
|
|
0ed2f6 |
reverse_iterator(const reverse_iterator &other): pointer(other.pointer) { }
|
|
|
0ed2f6 |
explicit reverse_iterator(const iterator &other): pointer(other.pointer) { }
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
reverse_iterator& operator=(const reverse_iterator &other) const { pointer = other.pointer; return *this; }
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
bool operator==(const reverse_iterator &other) const { return pointer == other.pointer; }
|
|
|
0ed2f6 |
bool operator!=(const reverse_iterator &other) const { return pointer != other.pointer; }
|
|
|
0ed2f6 |
bool operator< (const reverse_iterator &other) const { return pointer > other.pointer; }
|
|
|
0ed2f6 |
bool operator> (const reverse_iterator &other) const { return pointer < other.pointer; }
|
|
|
0ed2f6 |
bool operator<=(const reverse_iterator &other) const { return pointer >= other.pointer; }
|
|
|
0ed2f6 |
bool operator>=(const reverse_iterator &other) const { return pointer <= other.pointer; }
|
|
|
0ed2f6 |
ptrdiff_t operator-(const reverse_iterator &other) const { return other.pointer - pointer; }
|
|
|
0ed2f6 |
reverse_iterator operator+(ptrdiff_t diff) const { return reverse_iterator(pointer - diff); }
|
|
|
0ed2f6 |
reverse_iterator operator-(ptrdiff_t diff) const { return reverse_iterator(pointer + diff); }
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
reverse_iterator& operator++() { --pointer; return *this; }
|
|
|
0ed2f6 |
reverse_iterator& operator--() { ++pointer; return *this; }
|
|
|
0ed2f6 |
reverse_iterator operator++(int) { --pointer; return reverse_iterator(pointer+1); }
|
|
|
0ed2f6 |
reverse_iterator operator--(int) { ++pointer; return reverse_iterator(pointer-1); }
|
|
|
0ed2f6 |
reverse_iterator operator+=(ptrdiff_t diff) { pointer -= diff; return *this; }
|
|
|
0ed2f6 |
reverse_iterator operator-=(ptrdiff_t diff) { pointer += diff; return *this; }
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
const value_type* operator->() const { assert(pointer); return cast(pointer); }
|
|
|
0ed2f6 |
const value_type& operator*() const { assert(pointer); return *cast(pointer); }
|
|
|
0ed2f6 |
};
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
private:
|
|
|
0ed2f6 |
const src_value_type *m_begin;
|
|
|
0ed2f6 |
const src_value_type *m_end;
|
|
|
0ed2f6 |
const src_value_type *m_rbegin;
|
|
|
0ed2f6 |
const src_value_type *m_rend;
|
|
|
0ed2f6 |
size_t m_size;
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
static const value_type* cast(const src_value_type *pointer)
|
|
|
0ed2f6 |
{ return static_cast<const value_type*="">(pointer); }</const>
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
public:
|
|
|
0ed2f6 |
TConstArrayWrapperT():
|
|
|
0ed2f6 |
m_begin(), m_end(), m_rbegin(), m_rend(), m_size() { }
|
|
|
0ed2f6 |
TConstArrayWrapperT(const src_value_type *data, size_t size):
|
|
|
0ed2f6 |
m_begin(), m_end(), m_rbegin(), m_rend(), m_size() { set(data, size); }
|
|
|
0ed2f6 |
TConstArrayWrapperT(const TConstArrayWrapperT &other):
|
|
|
0ed2f6 |
m_begin(), m_end(), m_rbegin(), m_rend(), m_size() { *this = other; }
|
|
|
0ed2f6 |
explicit TConstArrayWrapperT(const std::vector<tt> &v):</tt>
|
|
|
0ed2f6 |
m_begin(), m_end(), m_rbegin(), m_rend(), m_size() { set(v); }
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
void reset() {
|
|
|
0ed2f6 |
m_begin = 0;
|
|
|
0ed2f6 |
m_end = 0;
|
|
|
0ed2f6 |
m_rbegin = 0;
|
|
|
0ed2f6 |
m_rend = 0;
|
|
|
0ed2f6 |
m_size = 0;
|
|
|
0ed2f6 |
}
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
void set(const src_value_type *data, size_t size) {
|
|
|
0ed2f6 |
assert((data != 0) == (size != 0));
|
|
|
0ed2f6 |
if (!data) reset();
|
|
|
0ed2f6 |
m_begin = data;
|
|
|
0ed2f6 |
m_end = data + size;
|
|
|
0ed2f6 |
m_rbegin = m_end - 1;
|
|
|
0ed2f6 |
m_rend = m_begin - 1;
|
|
|
0ed2f6 |
m_size = size;
|
|
|
0ed2f6 |
}
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
void set(const std::vector<tt> &v)</tt>
|
|
|
0ed2f6 |
{ if (v.empty()) reset(); else set(&v.front(), v.size()); }
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
TConstArrayWrapperT& operator=(const TConstArrayWrapperT &other)
|
|
|
0ed2f6 |
{ set(other.m_begin, other.m_size); return *this; }
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
size_t size() const { return m_size; }
|
|
|
0ed2f6 |
bool empty() const { return m_size != 0; }
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
iterator begin() const
|
|
|
0ed2f6 |
{ return iterator(m_begin); }
|
|
|
0ed2f6 |
iterator end() const
|
|
|
0ed2f6 |
{ return iterator(m_end); }
|
|
|
0ed2f6 |
reverse_iterator rbegin() const
|
|
|
0ed2f6 |
{ return reverse_iterator(m_rbegin); }
|
|
|
0ed2f6 |
reverse_iterator rend() const
|
|
|
0ed2f6 |
{ return reverse_iterator(m_rend); }
|
|
|
0ed2f6 |
const value_type& at (size_t index) const
|
|
|
0ed2f6 |
{ assert(index < m_size); return *cast(m_begin + index); }
|
|
|
0ed2f6 |
const value_type& operator[] (size_t index) const
|
|
|
0ed2f6 |
{ return at(index); }
|
|
|
0ed2f6 |
const value_type& front() const
|
|
|
0ed2f6 |
{ assert(!empty()); return *cast(m_begin); }
|
|
|
0ed2f6 |
const value_type& back() const
|
|
|
0ed2f6 |
{ assert(!empty()); return *cast(m_rbegin); }
|
|
|
0ed2f6 |
};
|
|
|
0ed2f6 |
|
|
|
0ed2f6 |
#endif
|