[iter] First sample use
This commit is contained in:
parent
19d2b5013d
commit
8001e00a47
|
@ -388,13 +388,16 @@ compiled_tests = test-iter test-ot-tag test-unicode-ranges
|
||||||
check_PROGRAMS += $(compiled_tests)
|
check_PROGRAMS += $(compiled_tests)
|
||||||
TESTS += $(compiled_tests)
|
TESTS += $(compiled_tests)
|
||||||
|
|
||||||
test_iter_SOURCES = test-iter.cc
|
test_iter_SOURCES = test-iter.cc hb-static.cc
|
||||||
|
test_iter_CPPFLAGS = $(HBCFLAGS) -DMAIN
|
||||||
|
test_iter_LDADD = libharfbuzz.la $(HBLIBS)
|
||||||
|
|
||||||
test_ot_tag_SOURCES = hb-ot-tag.cc
|
test_ot_tag_SOURCES = hb-ot-tag.cc
|
||||||
test_ot_tag_CPPFLAGS = $(HBCFLAGS) -DMAIN
|
test_ot_tag_CPPFLAGS = $(HBCFLAGS) -DMAIN
|
||||||
test_ot_tag_LDADD = libharfbuzz.la $(HBLIBS)
|
test_ot_tag_LDADD = libharfbuzz.la $(HBLIBS)
|
||||||
|
|
||||||
test_unicode_ranges_SOURCES = test-unicode-ranges.cc
|
test_unicode_ranges_SOURCES = test-unicode-ranges.cc
|
||||||
|
test_unicode_ranges_CPPFLAGS = $(HBCFLAGS) -DMAIN
|
||||||
test_unicode_ranges_LDADD = libharfbuzz.la $(HBLIBS)
|
test_unicode_ranges_LDADD = libharfbuzz.la $(HBLIBS)
|
||||||
|
|
||||||
TESTS_ENVIRONMENT = \
|
TESTS_ENVIRONMENT = \
|
||||||
|
|
|
@ -41,11 +41,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Base class for all iterators. */
|
/* Base class for all iterators. */
|
||||||
template <typename Iter>
|
template <typename Iter, typename Item = typename Iter::__item_type__>
|
||||||
struct hb_iter_t
|
struct hb_iter_t
|
||||||
{
|
{
|
||||||
typedef Iter type_t;
|
typedef Iter type_t;
|
||||||
typedef typename Iter::__type__ item_type_t;
|
typedef Item item_type_t;
|
||||||
|
|
||||||
/* https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern */
|
/* https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern */
|
||||||
const type_t* thiz () const { return static_cast<const type_t *> (this); }
|
const type_t* thiz () const { return static_cast<const type_t *> (this); }
|
||||||
|
@ -56,10 +56,10 @@ struct hb_iter_t
|
||||||
explicit_operator bool () const { return more (); }
|
explicit_operator bool () const { return more (); }
|
||||||
item_type_t& operator * () { return item (); }
|
item_type_t& operator * () { return item (); }
|
||||||
item_type_t& operator [] (unsigned i) { return item (i); }
|
item_type_t& operator [] (unsigned i) { return item (i); }
|
||||||
type_t& operator += (unsigned count) { forward (count); return thiz(); }
|
type_t& operator += (unsigned count) { forward (count); return *thiz(); }
|
||||||
type_t& operator ++ () { next (); return thiz(); }
|
type_t& operator ++ () { next (); return *thiz(); }
|
||||||
type_t& operator -= (unsigned count) { rewind (count); return thiz(); }
|
type_t& operator -= (unsigned count) { rewind (count); return *thiz(); }
|
||||||
type_t& operator -- () { prev (); return thiz(); }
|
type_t& operator -- () { prev (); return *thiz(); }
|
||||||
type_t operator + (unsigned count) { type_t c (*thiz()); c += count; return c; }
|
type_t operator + (unsigned count) { type_t c (*thiz()); c += count; return c; }
|
||||||
type_t operator ++ (int) { type_t c (*thiz()); ++*thiz(); return c; }
|
type_t operator ++ (int) { type_t c (*thiz()); ++*thiz(); return c; }
|
||||||
type_t operator - (unsigned count) { type_t c (*thiz()); c -= count; return c; }
|
type_t operator - (unsigned count) { type_t c (*thiz()); c -= count; return c; }
|
||||||
|
@ -67,8 +67,8 @@ struct hb_iter_t
|
||||||
|
|
||||||
/* Methods. */
|
/* Methods. */
|
||||||
type_t iter () const { return *thiz(); }
|
type_t iter () const { return *thiz(); }
|
||||||
item_type_t item () const { return thiz()->__item__ (); }
|
item_type_t& item () const { return thiz()->__item__ (); }
|
||||||
item_type_t item (unsigned i) const { return thiz()->__item__ (i); }
|
item_type_t& item_at (unsigned i) const { return thiz()->__item_at__ (i); }
|
||||||
bool more () const { return thiz()->__more__ (); }
|
bool more () const { return thiz()->__more__ (); }
|
||||||
void next () { thiz()->__next__ (); }
|
void next () { thiz()->__next__ (); }
|
||||||
void forward (unsigned n) { thiz()->__forward__ (n); }
|
void forward (unsigned n) { thiz()->__forward__ (n); }
|
||||||
|
@ -80,12 +80,9 @@ struct hb_iter_t
|
||||||
* Subclasses overrides:
|
* Subclasses overrides:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Item type. */
|
/* Access: Implement __item__(), or __item_at__() if random-access. */
|
||||||
//typedef ... __type__;
|
item_type_t& __item__ () const { return thiz()->item_at (0); }
|
||||||
|
item_type_t& __item_at__ (unsigned i) const { return *(thiz() + i); }
|
||||||
/* Access: Implement __item__(), or __item__(n) if random-access. */
|
|
||||||
item_type_t __item__ () const { return thiz()->item (0); }
|
|
||||||
item_type_t __item__ (unsigned i) const { return *(thiz() + i); }
|
|
||||||
|
|
||||||
/* Termination: Implement __more__() or __end__(). */
|
/* Termination: Implement __more__() or __end__(). */
|
||||||
bool __more__ () const { return item () != thiz()->__end__ (); }
|
bool __more__ () const { return item () != thiz()->__end__ (); }
|
||||||
|
|
|
@ -26,16 +26,32 @@
|
||||||
|
|
||||||
#include "hb-iter.hh"
|
#include "hb-iter.hh"
|
||||||
|
|
||||||
|
#include "hb-array.hh"
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct array_iter_t : hb_iter_t<array_iter_t<T>, T>
|
||||||
|
{
|
||||||
|
array_iter_t (hb_array_t<T> arr_) : arr (arr_) {}
|
||||||
|
|
||||||
|
T& __item_at__ (unsigned i) const { return arr[i]; }
|
||||||
|
bool __more__ () const { return arr.len; }
|
||||||
|
void __forward__ (unsigned n) { arr += n; }
|
||||||
|
void __rewind__ (unsigned n) { arr -= n; }
|
||||||
|
unsigned __len__ () const { return arr.len; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
hb_array_t<T> arr;
|
||||||
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
const int src[10] = {};
|
const int src[10] = {};
|
||||||
int dst[20];
|
int dst[20];
|
||||||
|
|
||||||
#if 0
|
array_iter_t<const int> s (src);
|
||||||
hb_iter_t<const int *> s (src);
|
array_iter_t<const int> s2 (src);
|
||||||
hb_iter_t<const int *> s2 (src, 5);
|
array_iter_t<int> t (dst);
|
||||||
hb_iter_t<int *> t (dst);
|
|
||||||
|
|
||||||
s2 = s;
|
s2 = s;
|
||||||
|
|
||||||
|
@ -43,7 +59,6 @@ main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
*t = *s;
|
*t = *s;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue