OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_ID_H_ | 5 #ifndef CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_ID_H_ |
6 #define CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_ID_H_ | 6 #define CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_ID_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <iosfwd> | 9 #include <iosfwd> |
10 #include <limits> | 10 #include <limits> |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 // fix this, this is madness :) | 72 // fix this, this is madness :) |
73 inline bool IsNull() const { | 73 inline bool IsNull() const { |
74 return IsRoot(); | 74 return IsRoot(); |
75 } | 75 } |
76 inline void Clear() { | 76 inline void Clear() { |
77 s_ = "r"; | 77 s_ = "r"; |
78 } | 78 } |
79 inline int compare(const Id& that) const { | 79 inline int compare(const Id& that) const { |
80 return s_.compare(that.s_); | 80 return s_.compare(that.s_); |
81 } | 81 } |
82 // Must never allow id == 0 or id < 0 to compile. | |
83 inline bool operator == (const Id& that) const { | 82 inline bool operator == (const Id& that) const { |
84 return s_ == that.s_; | 83 return s_ == that.s_; |
85 } | 84 } |
86 inline bool operator != (const Id& that) const { | 85 inline bool operator != (const Id& that) const { |
87 return s_ != that.s_; | 86 return s_ != that.s_; |
88 } | 87 } |
89 inline bool operator < (const Id& that) const { | 88 inline bool operator < (const Id& that) const { |
90 return s_ < that.s_; | 89 return s_ < that.s_; |
91 } | 90 } |
92 inline bool operator > (const Id& that) const { | 91 inline bool operator > (const Id& that) const { |
93 return s_ > that.s_; | 92 return s_ > that.s_; |
94 } | 93 } |
| 94 // Return the next highest ID in the lexicographic ordering. This is |
| 95 // useful for computing upper bounds on std::sets that are ordered |
| 96 // by operator<. |
| 97 Id GetLexicographicSuccessor() const; |
95 | 98 |
96 // Three functions are used to work with our proto buffers. | 99 // Three functions are used to work with our proto buffers. |
97 std::string GetServerId() const; | 100 std::string GetServerId() const; |
98 static Id CreateFromServerId(const std::string& server_id); | 101 static Id CreateFromServerId(const std::string& server_id); |
99 // This should only be used if you get back a reference to a local | 102 // This should only be used if you get back a reference to a local |
100 // id from the server. Returns a client only opaque id. | 103 // id from the server. Returns a client only opaque id. |
101 static Id CreateFromClientString(const std::string& local_id); | 104 static Id CreateFromClientString(const std::string& local_id); |
102 | 105 |
103 protected: | 106 // This method returns an ID that will compare less than any valid ID. |
| 107 // The returned ID is not a valid ID itself. This is useful for |
| 108 // computing lower bounds on std::sets that are ordered by operator<. |
| 109 static Id GetLeastIdForLexicographicComparison(); |
| 110 |
| 111 private: |
104 std::string s_; | 112 std::string s_; |
105 }; | 113 }; |
106 | 114 |
107 extern const Id kNullId; | 115 extern const Id kNullId; |
108 | 116 |
109 } // namespace syncable | 117 } // namespace syncable |
110 | 118 |
111 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_ID_H_ | 119 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_ID_H_ |
OLD | NEW |