Add a verbs iterator to SkPathPriv
Bug: skia:
Change-Id: If846eeac2722b67a80266f01ede7ef03ef027ac8
Reviewed-on: https://skia-review.googlesource.com/20027
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
diff --git a/src/core/SkPathPriv.h b/src/core/SkPathPriv.h
index 029cb75..febc4e3 100644
--- a/src/core/SkPathPriv.h
+++ b/src/core/SkPathPriv.h
@@ -100,6 +100,30 @@
SkScalar sweepAngle, bool useCenter, bool isFillNoPathEffect);
/**
+ * Returns a C++11-iterable object that traverses a path's verbs in order. e.g:
+ *
+ * for (SkPath::Verb verb : SkPathPriv::Verbs(path)) {
+ * ...
+ * }
+ */
+ struct Verbs {
+ public:
+ Verbs(const SkPath& path) : fPathRef(path.fPathRef.get()) {}
+ struct Iter {
+ void operator++() { --fVerb; } // verbs are laid out backwards in memory.
+ bool operator!=(const Iter& b) { return fVerb != b.fVerb; }
+ SkPath::Verb operator*() { return static_cast<SkPath::Verb>(*fVerb); }
+ const uint8_t* fVerb;
+ };
+ Iter begin() { return Iter{fPathRef->verbs() - 1}; }
+ Iter end() { return Iter{fPathRef->verbs() - fPathRef->countVerbs() - 1}; }
+ private:
+ Verbs(const Verbs&) = delete;
+ Verbs& operator=(const Verbs&) = delete;
+ SkPathRef* fPathRef;
+ };
+
+ /**
* Returns a pointer to the verb data. Note that the verbs are stored backwards in memory and
* thus the returned pointer is the last verb.
*/