check_PROGRAMS += $(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_CPPFLAGS = $(HBCFLAGS) -DMAIN
test_ot_tag_LDADD = libharfbuzz.la $(HBLIBS)
test_unicode_ranges_SOURCES = test-unicode-ranges.cc
+test_unicode_ranges_CPPFLAGS = $(HBCFLAGS) -DMAIN
test_unicode_ranges_LDADD = libharfbuzz.la $(HBLIBS)
TESTS_ENVIRONMENT = \
*/
/* Base class for all iterators. */
-template <typename Iter>
+template <typename Iter, typename Item = typename Iter::__item_type__>
struct hb_iter_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 */
const type_t* thiz () const { return static_cast<const type_t *> (this); }
explicit_operator bool () const { return more (); }
item_type_t& operator * () { return item (); }
item_type_t& operator [] (unsigned i) { return item (i); }
- type_t& operator += (unsigned count) { forward (count); return thiz(); }
- type_t& operator ++ () { next (); return thiz(); }
- type_t& operator -= (unsigned count) { rewind (count); return thiz(); }
- type_t& operator -- () { prev (); return thiz(); }
+ type_t& operator += (unsigned count) { forward (count); return *thiz(); }
+ type_t& operator ++ () { next (); return *thiz(); }
+ type_t& operator -= (unsigned count) { rewind (count); return *thiz(); }
+ type_t& operator -- () { prev (); return *thiz(); }
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 - (unsigned count) { type_t c (*thiz()); c -= count; return c; }
/* Methods. */
type_t iter () const { return *thiz(); }
- item_type_t item () const { return thiz()->__item__ (); }
- item_type_t item (unsigned i) const { return thiz()->__item__ (i); }
+ item_type_t& item () const { return thiz()->__item__ (); }
+ item_type_t& item_at (unsigned i) const { return thiz()->__item_at__ (i); }
bool more () const { return thiz()->__more__ (); }
void next () { thiz()->__next__ (); }
void forward (unsigned n) { thiz()->__forward__ (n); }
* Subclasses overrides:
*/
- /* Item type. */
- //typedef ... __type__;
-
- /* 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); }
+ /* Access: Implement __item__(), or __item_at__() if random-access. */
+ item_type_t& __item__ () const { return thiz()->item_at (0); }
+ item_type_t& __item_at__ (unsigned i) const { return *(thiz() + i); }
/* Termination: Implement __more__() or __end__(). */
bool __more__ () const { return item () != thiz()->__end__ (); }
#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
main (int argc, char **argv)
{
const int src[10] = {};
int dst[20];
-#if 0
- hb_iter_t<const int *> s (src);
- hb_iter_t<const int *> s2 (src, 5);
- hb_iter_t<int *> t (dst);
+ array_iter_t<const int> s (src);
+ array_iter_t<const int> s2 (src);
+ array_iter_t<int> t (dst);
s2 = s;
{
*t = *s;
}
-#endif
return 0;
}