OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_ENHANCED_BOOKMARKS_ITEM_POSITION_H_ |
| 6 #define COMPONENTS_ENHANCED_BOOKMARKS_ITEM_POSITION_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 namespace enhanced_bookmarks { |
| 12 |
| 13 // Convenience class for generating string based relative ordering between |
| 14 // bookmark nodes. |
| 15 class ItemPosition { |
| 16 public: |
| 17 ~ItemPosition(); |
| 18 |
| 19 // Creates a position suitable to use as a starting point. |
| 20 static ItemPosition CreateInitialPosition(); |
| 21 |
| 22 // Creates positions relative to other positions. |
| 23 static ItemPosition CreateBefore(const ItemPosition& other); |
| 24 static ItemPosition CreateBetween(const ItemPosition& before, |
| 25 const ItemPosition& after); |
| 26 static ItemPosition CreateAfter(const ItemPosition& other); |
| 27 |
| 28 bool IsValid() const; |
| 29 |
| 30 // Returns a string representation of the position. The string representations |
| 31 // of two position have the same ordering as the positions themselves when |
| 32 // compared using ASCII order. |
| 33 std::string ToString() const; |
| 34 |
| 35 // Comparison functions. |
| 36 bool Equals(const ItemPosition& other) const; |
| 37 bool LessThan(const ItemPosition& other) const; |
| 38 |
| 39 private: |
| 40 typedef std::vector<unsigned char> PositionVector; |
| 41 |
| 42 ItemPosition(); |
| 43 explicit ItemPosition(const PositionVector& position); |
| 44 |
| 45 static PositionVector CreateBeforeImpl(const PositionVector& before, |
| 46 size_t from_index); |
| 47 static PositionVector CreateBetweenImpl(const PositionVector& before, |
| 48 const PositionVector& after); |
| 49 static PositionVector CreateAfterImpl(const PositionVector& after, |
| 50 size_t from_index); |
| 51 |
| 52 PositionVector position_; |
| 53 }; |
| 54 |
| 55 } // namespace enhanced_bookmarks |
| 56 |
| 57 #endif // COMPONENTS_ENHANCED_BOOKMARKS_ITEM_POSITION_H_ |
OLD | NEW |