|
Elm
2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
|
21 #ifndef ELM_ARRAY_TABLE_H_
22 #define ELM_ARRAY_TABLE_H_
24 #include <elm/assert.h>
25 #include <elm/PreIterator.h>
26 #include <elm/array.h>
27 #include <elm/compare.h>
53 inline Iter(
void): p(0),
t(0) { }
56 inline bool ended(
void)
const {
return p >=
t; }
57 inline const T&
item(
void)
const { ASSERT(p <
t);
return *p; }
58 inline void next(
void) { p++; }
59 inline bool equals(
const Iter& i)
const {
return p == i.p &&
t == i.t; }
66 inline Iter
items(
void)
const {
return Iter(*
this); }
69 inline Iter
end(
void)
const {
return Iter(*
this,
true); }
73 {
for(
auto x: *
this)
if(x == item)
return true;
return false; }
75 {
for(
auto x: c)
if(!
contains(x))
return false;
return true; }
79 if(
cnt != a.
cnt)
return false;
80 for(
auto i =
begin(), j = a.
begin(); i; ++i, ++j)
81 if(*i != *j)
return false;
93 inline const T&
get(
int idx)
const { ASSERT(0 <= idx && idx <
cnt);
return buf[idx]; }
94 inline int indexOf(
const T& v,
int i = 0)
const
95 {
for(; i <
count(); i++)
if(v ==
get(i))
return i;
return -1; }
97 {
if(i < 0) i =
count() - 1;
for(; i >= 0; i--)
if(v ==
get(i))
return i;
return -1; }
101 inline void set(
int idx,
const T& val) { ASSERT(0 <= idx && idx <
cnt);
buf[idx] = val; }
102 inline void set(
const Iter& i,
const T& val) { ASSERT(
buf <= i.p && i.p <
buf +
cnt); *i.p = val; }
103 inline T&
get(
int idx) { ASSERT(0 <= idx && idx <
cnt);
return buf[idx]; }
AllocArray(int count)
Definition: Array.h:121
Array(int count, T *buffer)
Definition: Array.h:38
Iter end(void) const
Definition: Array.h:69
const T * buffer(void) const
Definition: Array.h:40
void copy(T *target, const T *source, int size)
Definition: array.h:70
~AllocArray(void)
Definition: Array.h:125
int size(void) const
Definition: Array.h:42
T * buf
Definition: Array.h:109
Iter(void)
Definition: Array.h:53
const T * operator()(void) const
Definition: Array.h:47
AllocArray(int count, T *buffer)
Definition: Array.h:120
Array< T > self_t
Definition: Array.h:35
Array< T > & operator=(const Array< T > &t)
Definition: Array.h:49
Iter begin(void) const
Definition: Array.h:68
AllocArray(int count, const T &val)
Definition: Array.h:122
Iter operator*(void) const
Definition: Array.h:67
void copy(const Array< T > &t)
Definition: Array.h:127
bool operator>(const Array< T > &a) const
Definition: Array.h:89
T t
Definition: Array.h:34
void copy(const Array &t)
Definition: Array.h:45
void set(int idx, const T &val)
Definition: Array.h:101
bool contains(const T &item)
Definition: Array.h:72
int length(void) const
Definition: Array.h:92
bool equals(const Iter &i) const
Definition: Array.h:59
int lastIndexOf(const T &v, int i=-1) const
Definition: Array.h:96
const T & min(const T &x, const T &y)
Definition: compare.h:104
bool isEmpty(void) const
Definition: Array.h:76
void set(int count, T *buffer)
Definition: Array.h:43
bool operator<(const Array< T > &a) const
Definition: Array.h:87
AllocArray(const AllocArray< T > &t)
Definition: Array.h:124
void tie(const Array< T > &t)
Definition: Array.h:131
AllocArray< T > & operator=(const AllocArray< T > &t)
Definition: Array.h:134
T * buffer(void)
Definition: Array.h:41
bool ended(void) const
Definition: Array.h:56
void set(const Iter &i, const T &val)
Definition: Array.h:102
T & operator[](int idx)
Definition: Array.h:104
void set(T *target, int size, const T &v)
Definition: array.h:76
bool containsAll(const C &c)
Definition: Array.h:74
int cnt
Definition: Array.h:108
AllocArray< T > & operator=(const Array< T > &t)
Definition: Array.h:133
T & get(int idx)
Definition: Array.h:103
void tie(int cnt, T *buffer)
Definition: Array.h:130
Iter(const Array< T > &table)
Definition: Array.h:54
AllocArray(const Array< T > &t)
Definition: Array.h:123
int indexOf(const T &v, int i=0) const
Definition: Array.h:94
bool operator!=(const Array< T > &a) const
Definition: Array.h:85
Array(void)
Definition: Array.h:37
AllocArray(void)
Definition: Array.h:119
bool operator<=(const Array< T > &a) const
Definition: Array.h:86
void fill(const T &val)
Definition: Array.h:46
int count(void) const
Definition: Array.h:71
Array< T > _array(int n, T t[])
Definition: Array.h:138
bool equals(const Array< T > &a)
Definition: Array.h:78
void next(void)
Definition: Array.h:58
void set(const Array< T > &t)
Definition: Array.h:44
bool operator>=(const Array< T > &a) const
Definition: Array.h:88
const T & get(int idx) const
Definition: Array.h:93
const T & item(void) const
Definition: Array.h:57
Iter(const Array< T > &table, bool end)
Definition: Array.h:55
Iter items(void) const
Definition: Array.h:66
bool operator==(const Array< T > &a) const
Definition: Array.h:84
T * operator()(void)
Definition: Array.h:48
const T & operator[](int idx) const
Definition: Array.h:98