| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 SYNC_INTERNAL_API_PUBLIC_BASE_UNIQUE_POSITION_H_ | 5 #ifndef SYNC_INTERNAL_API_PUBLIC_BASE_UNIQUE_POSITION_H_ |
| 6 #define SYNC_INTERNAL_API_PUBLIC_BASE_UNIQUE_POSITION_H_ | 6 #define SYNC_INTERNAL_API_PUBLIC_BASE_UNIQUE_POSITION_H_ |
| 7 | 7 |
| 8 #include <stdint.h> |
| 9 |
| 8 #include <string> | 10 #include <string> |
| 9 | 11 |
| 10 #include "base/basictypes.h" | |
| 11 #include "sync/base/sync_export.h" | 12 #include "sync/base/sync_export.h" |
| 12 | 13 |
| 13 namespace sync_pb { | 14 namespace sync_pb { |
| 14 class UniquePosition; | 15 class UniquePosition; |
| 15 } | 16 } |
| 16 | 17 |
| 17 namespace syncer { | 18 namespace syncer { |
| 18 | 19 |
| 19 // A class to represent positions. | 20 // A class to represent positions. |
| 20 // | 21 // |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 // Returns an invalid position. | 54 // Returns an invalid position. |
| 54 static UniquePosition CreateInvalid(); | 55 static UniquePosition CreateInvalid(); |
| 55 | 56 |
| 56 // Converts from a 'sync_pb::UniquePosition' protobuf to a UniquePosition. | 57 // Converts from a 'sync_pb::UniquePosition' protobuf to a UniquePosition. |
| 57 // This may return an invalid position if the parsing fails. | 58 // This may return an invalid position if the parsing fails. |
| 58 static UniquePosition FromProto(const sync_pb::UniquePosition& proto); | 59 static UniquePosition FromProto(const sync_pb::UniquePosition& proto); |
| 59 | 60 |
| 60 // Creates a position with the given suffix. Ordering among positions created | 61 // Creates a position with the given suffix. Ordering among positions created |
| 61 // from this function is the same as that of the integer parameters that were | 62 // from this function is the same as that of the integer parameters that were |
| 62 // passed in. | 63 // passed in. |
| 63 static UniquePosition FromInt64(int64 i, const std::string& suffix); | 64 static UniquePosition FromInt64(int64_t i, const std::string& suffix); |
| 64 | 65 |
| 65 // Returns a valid position. Its ordering is not defined. | 66 // Returns a valid position. Its ordering is not defined. |
| 66 static UniquePosition InitialPosition(const std::string& suffix); | 67 static UniquePosition InitialPosition(const std::string& suffix); |
| 67 | 68 |
| 68 // Returns positions compare smaller than, greater than, or between the input | 69 // Returns positions compare smaller than, greater than, or between the input |
| 69 // positions. | 70 // positions. |
| 70 static UniquePosition Before(const UniquePosition& x, | 71 static UniquePosition Before(const UniquePosition& x, |
| 71 const std::string& suffix); | 72 const std::string& suffix); |
| 72 static UniquePosition After(const UniquePosition& x, | 73 static UniquePosition After(const UniquePosition& x, |
| 73 const std::string& suffix); | 74 const std::string& suffix); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 86 | 87 |
| 87 // Serializes the protobuf representation of this object as a string. | 88 // Serializes the protobuf representation of this object as a string. |
| 88 void SerializeToString(std::string* blob) const; | 89 void SerializeToString(std::string* blob) const; |
| 89 | 90 |
| 90 // Returns a human-readable representation of this item's internal state. | 91 // Returns a human-readable representation of this item's internal state. |
| 91 std::string ToDebugString() const; | 92 std::string ToDebugString() const; |
| 92 | 93 |
| 93 // Returns the suffix. | 94 // Returns the suffix. |
| 94 std::string GetSuffixForTest() const; | 95 std::string GetSuffixForTest() const; |
| 95 | 96 |
| 96 // Performs a lossy conversion to an int64 position. Positions converted to | 97 // Performs a lossy conversion to an int64_t position. Positions converted to |
| 97 // and from int64s using this and the FromInt64 function should maintain their | 98 // and from int64_ts using this and the FromInt64 function should maintain |
| 98 // relative orderings unless the int64 values conflict. | 99 // their |
| 99 int64 ToInt64() const; | 100 // relative orderings unless the int64_t values conflict. |
| 101 int64_t ToInt64() const; |
| 100 | 102 |
| 101 bool IsValid() const; | 103 bool IsValid() const; |
| 102 | 104 |
| 103 private: | 105 private: |
| 104 friend class UniquePositionTest; | 106 friend class UniquePositionTest; |
| 105 | 107 |
| 106 // Returns a string X such that (X ++ |suffix|) < |str|. | 108 // Returns a string X such that (X ++ |suffix|) < |str|. |
| 107 // |str| must be a trailing substring of a valid ordinal. | 109 // |str| must be a trailing substring of a valid ordinal. |
| 108 // |suffix| must be a valid unique suffix. | 110 // |suffix| must be a valid unique suffix. |
| 109 static std::string FindSmallerWithSuffix(const std::string& str, | 111 static std::string FindSmallerWithSuffix(const std::string& str, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 135 | 137 |
| 136 // The position value after it has been run through the custom compression | 138 // The position value after it has been run through the custom compression |
| 137 // algorithm. See Compress() and Uncompress() functions above. | 139 // algorithm. See Compress() and Uncompress() functions above. |
| 138 std::string compressed_; | 140 std::string compressed_; |
| 139 bool is_valid_; | 141 bool is_valid_; |
| 140 }; | 142 }; |
| 141 | 143 |
| 142 } // namespace syncer; | 144 } // namespace syncer; |
| 143 | 145 |
| 144 #endif // SYNC_INTERNAL_API_PUBLIC_BASE_UNIQUE_POSITION_H_ | 146 #endif // SYNC_INTERNAL_API_PUBLIC_BASE_UNIQUE_POSITION_H_ |
| OLD | NEW |