Make SkTDArray accessors const-friendly.

This change creates const and non-const versions of SkTDArray::begin(), end(), operator[]() and getAt(). This will keep us from inadvertently changing a const SkTDArray, which the previous signatures allowed.

Review URL: https://chromiumcodereview.appspot.com/12315131

git-svn-id: http://skia.googlecode.com/svn/trunk@7902 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkTDArray.h b/include/core/SkTDArray.h
index ee77889..d733c47 100644
--- a/include/core/SkTDArray.h
+++ b/include/core/SkTDArray.h
@@ -102,14 +102,24 @@
      */
     size_t bytes() const { return fCount * sizeof(T); }
 
-    T*  begin() const { return fArray; }
-    T*  end() const { return fArray ? fArray + fCount : NULL; }
-    T&  operator[](int index) const {
+    T*  begin() { return fArray; }
+    const T*  begin() const { return fArray; }
+    T*  end() { return fArray ? fArray + fCount : NULL; }
+    const T*  end() const { return fArray ? fArray + fCount : NULL; }
+
+    T&  operator[](int index) {
+        SkASSERT((unsigned)index < fCount);
+        return fArray[index];
+    }
+    const T&  operator[](int index) const {
         SkASSERT((unsigned)index < fCount);
         return fArray[index];
     }
 
-    T&  getAt(int index) const {
+    T&  getAt(int index)  {
+        return (*this)[index];
+    }
+    const T&  getAt(int index) const {
         return (*this)[index];
     }
 
@@ -306,7 +316,7 @@
         this->reset();
     }
 
-    void visitAll(void visitor(T&)) const {
+    void visitAll(void visitor(T&)) {
         T* stop = this->end();
         for (T* curr = this->begin(); curr < stop; curr++) {
             if (*curr) {
diff --git a/include/core/SkTDict.h b/include/core/SkTDict.h
index b704a48..49d07d4 100644
--- a/include/core/SkTDict.h
+++ b/include/core/SkTDict.h
@@ -84,8 +84,8 @@
 
     bool findKey(T& value, const char** name) const
     {
-        Pair* end = fArray.end();
-        for (Pair* pair = fArray.begin(); pair < end; pair++) {
+        const Pair* end = fArray.end();
+        for (const Pair* pair = fArray.begin(); pair < end; pair++) {
             if (pair->fValue != value)
                 continue;
             *name = pair->fName;
@@ -131,8 +131,8 @@
             return name;
         }
     private:
-        Pair*   fIter;
-        Pair*   fStop;
+        const Pair*   fIter;
+        const Pair*   fStop;
     };
 
 private:
diff --git a/src/core/SkPathHeap.cpp b/src/core/SkPathHeap.cpp
index b8ca40b..12db3c4 100644
--- a/src/core/SkPathHeap.cpp
+++ b/src/core/SkPathHeap.cpp
@@ -54,8 +54,8 @@
     int count = fPaths.count();
 
     buffer.writeInt(count);
-    SkPath** iter = fPaths.begin();
-    SkPath** stop = fPaths.end();
+    SkPath* const* iter = fPaths.begin();
+    SkPath* const* stop = fPaths.end();
     while (iter < stop) {
         buffer.writePath(**iter);
         iter++;
diff --git a/src/core/SkPictureFlat.h b/src/core/SkPictureFlat.h
index a9db48d..89b8e54 100644
--- a/src/core/SkPictureFlat.h
+++ b/src/core/SkPictureFlat.h
@@ -530,7 +530,7 @@
 private:
     void unflattenIntoArray(T* array) const {
         const int count = fData.count();
-        const SkFlatData** iter = fData.begin();
+        const SkFlatData* const* iter = fData.begin();
         for (int i = 0; i < count; ++i) {
             const SkFlatData* element = iter[i];
             int index = element->index() - 1;
diff --git a/src/gpu/GrTHashCache.h b/src/gpu/GrTHashCache.h
index b73b574..3427ffe 100644
--- a/src/gpu/GrTHashCache.h
+++ b/src/gpu/GrTHashCache.h
@@ -60,6 +60,7 @@
 
     // testing
     const SkTDArray<T*>& getArray() const { return fSorted; }
+    SkTDArray<T*>& getArray() { return fSorted; }
 private:
     enum {
         kHashCount = 1 << kHashBits,
diff --git a/src/images/SkImageDecoder_libbmp.cpp b/src/images/SkImageDecoder_libbmp.cpp
index 2cbdcc3..3aa834a 100644
--- a/src/images/SkImageDecoder_libbmp.cpp
+++ b/src/images/SkImageDecoder_libbmp.cpp
@@ -68,7 +68,7 @@
 
     int width() const { return fWidth; }
     int height() const { return fHeight; }
-    uint8_t* rgb() const { return fRGB.begin(); }
+    const uint8_t* rgb() const { return fRGB.begin(); }
 
 private:
     SkTDArray<uint8_t> fRGB;
diff --git a/src/pdf/SkPDFDocument.cpp b/src/pdf/SkPDFDocument.cpp
index c7266d8..4c66c6b 100644
--- a/src/pdf/SkPDFDocument.cpp
+++ b/src/pdf/SkPDFDocument.cpp
@@ -43,7 +43,7 @@
         usage.merge(pages[i]->getFontGlyphUsage());
     }
     SkPDFGlyphSetMap::F2BIter iterator(usage);
-    SkPDFGlyphSetMap::FontGlyphSetPair* entry = iterator.next();
+    const SkPDFGlyphSetMap::FontGlyphSetPair* entry = iterator.next();
     while (entry) {
         SkPDFFont* subsetFont =
             entry->fFont->getFontSubset(entry->fGlyphSet);
diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp
index 89b4fc9..3d7902d 100644
--- a/src/pdf/SkPDFFont.cpp
+++ b/src/pdf/SkPDFFont.cpp
@@ -624,7 +624,7 @@
     reset(map);
 }
 
-SkPDFGlyphSetMap::FontGlyphSetPair* SkPDFGlyphSetMap::F2BIter::next() const {
+const SkPDFGlyphSetMap::FontGlyphSetPair* SkPDFGlyphSetMap::F2BIter::next() const {
     if (fIndex >= fMap->count()) {
         return NULL;
     }
diff --git a/src/pdf/SkPDFFont.h b/src/pdf/SkPDFFont.h
index 693b911..847a2af 100644
--- a/src/pdf/SkPDFFont.h
+++ b/src/pdf/SkPDFFont.h
@@ -49,7 +49,7 @@
     class F2BIter {
     public:
         explicit F2BIter(const SkPDFGlyphSetMap& map);
-        FontGlyphSetPair* next() const;
+        const FontGlyphSetPair* next() const;
         void reset(const SkPDFGlyphSetMap& map);
 
     private:
diff --git a/src/pdf/SkPDFTypes.cpp b/src/pdf/SkPDFTypes.cpp
index 59250c8..d479a22 100644
--- a/src/pdf/SkPDFTypes.cpp
+++ b/src/pdf/SkPDFTypes.cpp
@@ -483,7 +483,7 @@
 
 SkPDFName* SkPDFDict::Iter::next(SkPDFObject** value) {
     if (fIter != fStop) {
-        Rec* cur = fIter;
+        const Rec* cur = fIter;
         fIter++;
         *value = cur->value;
         return cur->key;
diff --git a/src/pdf/SkPDFTypes.h b/src/pdf/SkPDFTypes.h
index 03799d0..98223ae 100644
--- a/src/pdf/SkPDFTypes.h
+++ b/src/pdf/SkPDFTypes.h
@@ -419,8 +419,8 @@
         SkPDFName* next(SkPDFObject** value);
 
     private:
-        Rec* fIter;
-        Rec* fStop;
+        const Rec* fIter;
+        const Rec* fStop;
     };
 
 private: