Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Unified Diff: third_party/WebKit/Source/core/editing/markers/DocumentMarker.h

Issue 2765013003: Add iterator for DocumentMarker::MarkerTypes (Closed)
Patch Set: Work around MSVC warning Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/editing/markers/DocumentMarker.h
diff --git a/third_party/WebKit/Source/core/editing/markers/DocumentMarker.h b/third_party/WebKit/Source/core/editing/markers/DocumentMarker.h
index 7db49d1a45320fa4724c6a664cb6a6d88e08a618..dbcfdf2964555be13aa50b7551bf2305f37a6fd8 100644
--- a/third_party/WebKit/Source/core/editing/markers/DocumentMarker.h
+++ b/third_party/WebKit/Source/core/editing/markers/DocumentMarker.h
@@ -55,6 +55,46 @@ class CORE_EXPORT DocumentMarker : public GarbageCollected<DocumentMarker> {
Composition = 1 << CompositionMarkerIndex,
};
+ class MarkerTypesIterator
+ : public std::iterator<std::forward_iterator_tag, MarkerType> {
+ public:
+ explicit MarkerTypesIterator(unsigned markerTypes)
+ : m_remainingTypes(markerTypes) {}
+ MarkerTypesIterator(const MarkerTypesIterator& other) = default;
+
+ bool operator==(const MarkerTypesIterator& other) {
+ return m_remainingTypes == other.m_remainingTypes;
+ }
+ bool operator!=(const MarkerTypesIterator& other) {
+ return !operator==(other);
+ }
+
+ MarkerTypesIterator& operator++() {
+ DCHECK(m_remainingTypes);
+ // Turn off least significant 1-bit (from Hacker's Delight 2-1)
+ // Example:
+ // 7: 7 & 6 = 6
+ // 6: 6 & 5 = 4
+ // 4: 4 & 3 = 0
+ m_remainingTypes &= (m_remainingTypes - 1);
+ return *this;
+ }
+
+ MarkerType operator*() const {
+ DCHECK(m_remainingTypes);
+ // Isolate least significant 1-bit (from Hacker's Delight 2-1)
+ // Example:
+ // 7: 7 & -7 = 1
+ // 6: 6 & -6 = 2
+ // 4: 4 & -4 = 4
+ return static_cast<MarkerType>(m_remainingTypes &
+ (~m_remainingTypes + 1));
+ }
+
+ private:
+ unsigned m_remainingTypes;
+ };
+
class MarkerTypes {
public:
// The constructor is intentionally implicit to allow conversion from the
@@ -72,6 +112,9 @@ class CORE_EXPORT DocumentMarker : public GarbageCollected<DocumentMarker> {
void add(const MarkerTypes& types) { m_mask |= types.m_mask; }
void remove(const MarkerTypes& types) { m_mask &= ~types.m_mask; }
+ MarkerTypesIterator begin() const { return MarkerTypesIterator(m_mask); }
+ MarkerTypesIterator end() const { return MarkerTypesIterator(0); }
+
private:
unsigned m_mask;
};
« no previous file with comments | « third_party/WebKit/Source/core/editing/BUILD.gn ('k') | third_party/WebKit/Source/core/editing/markers/DocumentMarkerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698