sk_tool::Registry: make an iterator.

Change-Id: Icf4e31b50bbd91b7ea330a1300f736d6dfd0a41c
Reviewed-on: https://skia-review.googlesource.com/144500
Commit-Queue: Ben Wagner <bungeman@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
Auto-Submit: Hal Canary <halcanary@google.com>
diff --git a/tools/Registry.h b/tools/Registry.h
index 4184e49..6c35578 100644
--- a/tools/Registry.h
+++ b/tools/Registry.h
@@ -19,9 +19,7 @@
  */
 template <typename T> class Registry : SkNoncopyable {
 public:
-    typedef T Factory;
-
-    explicit Registry(T fact) : fFact(fact) {
+    explicit Registry(T value) : fValue(value) {
 #ifdef SK_BUILD_FOR_ANDROID
         // work-around for double-initialization bug
         {
@@ -41,10 +39,22 @@
     static const Registry* Head() { return gHead; }
 
     const Registry* next() const { return fChain; }
-    const Factory& factory() const { return fFact; }
+    const T& get() const { return fValue; }
+
+    // for (const T& t : sk_tools::Registry<T>::Range()) { process(t); }
+    struct Range {
+        struct Iterator {
+            const Registry* fPtr;
+            const T& operator*() { return SkASSERT(fPtr), fPtr->get(); }
+            void operator++() { if (fPtr) { fPtr = fPtr->next(); } }
+            bool operator!=(const Iterator& other) const { return fPtr != other.fPtr; }
+        };
+        Iterator begin() const { return Iterator{Registry::Head()}; }
+        Iterator end() const { return Iterator{nullptr}; }
+    };
 
 private:
-    Factory   fFact;
+    T fValue;
     Registry* fChain;
 
     static Registry* gHead;