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

Unified Diff: components/enhanced_bookmarks/stars_position.h

Issue 510543002: Introduce ItemPosition class for enhanced bookmarks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Comments and comparison functions Created 6 years, 3 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: components/enhanced_bookmarks/stars_position.h
diff --git a/components/enhanced_bookmarks/stars_position.h b/components/enhanced_bookmarks/stars_position.h
new file mode 100644
index 0000000000000000000000000000000000000000..0645c09f8da9a59be65b49ec4beea2b0b63a8bb4
--- /dev/null
+++ b/components/enhanced_bookmarks/stars_position.h
@@ -0,0 +1,57 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_ENHANCED_BOOKMARKS_STARS_POSITION_H_
+#define COMPONENTS_ENHANCED_BOOKMARKS_STARS_POSITION_H_
+
+#include <string>
+#include <vector>
+
+namespace enhanced_bookmarks {
+
+// Convenience class for generating string based relative ordering between
+// bookmark nodes.
+class StarsPosition {
Yaron 2014/09/05 03:52:02 StarPosition/ItemPosition? Why is it plural?
Rune Fevang 2014/09/05 19:02:30 Because it refers to the Stars name, and is stored
Yaron 2014/09/05 19:52:13 It just reads weirdly to me and can be used withou
Rune Fevang 2014/09/05 20:47:08 Done.
+ public:
+ ~StarsPosition();
+
+ // Creates a position suitable to use as a starting point.
+ static StarsPosition CreateInitialPosition();
+
+ // Creates positions relative to other positions.
+ static StarsPosition CreateBefore(const StarsPosition& other);
+ static StarsPosition CreateBetween(const StarsPosition& before,
+ const StarsPosition& after);
+ static StarsPosition CreateAfter(const StarsPosition& other);
+
+ bool IsValid() const;
+
+ // Returns a string representation of the position. The string representations
+ // of two position have the same ordering as the positions themselves when
+ // compared using ASCII order.
+ std::string ToString() const;
+
+ // Comparison functions.
+ bool Equals(const StarsPosition& other);
+ bool LessThan(const StarsPosition& other);
+
+ private:
+ typedef std::vector<char> PositionVector;
+
+ StarsPosition();
+ explicit StarsPosition(const PositionVector& position);
+
+ static PositionVector CreateBeforeImpl(const PositionVector& before,
+ size_t from_index);
+ static PositionVector CreateBetweenImpl(const PositionVector& before,
+ const PositionVector& after);
+ static PositionVector CreateAfterImpl(const PositionVector& after,
+ size_t from_index);
+
+ PositionVector position_;
+};
+
+} // namespace enhanced_bookmarks
+
+#endif // COMPONENTS_ENHANCED_BOOKMARKS_STARS_POSITION_H_

Powered by Google App Engine
This is Rietveld 408576698