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 COMPONENTS_SYNC_MODEL_STRING_ORDINAL_H_ | 5 #ifndef COMPONENTS_SYNC_MODEL_STRING_ORDINAL_H_ |
6 #define COMPONENTS_SYNC_MODEL_STRING_ORDINAL_H_ | 6 #define COMPONENTS_SYNC_MODEL_STRING_ORDINAL_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include "components/sync/base/ordinal.h" | 11 #include "components/sync/base/ordinal.h" |
12 | 12 |
13 namespace syncer { | 13 namespace syncer { |
14 | 14 |
15 // A StringOrdinal is an Ordinal with range 'a'-'z' for printability | 15 // A StringOrdinal is an Ordinal with range 'a'-'z' for printability |
16 // of its internal byte string representation. (Think of | 16 // of its internal byte string representation. (Think of |
17 // StringOrdinal as being short for PrintableStringOrdinal.) It | 17 // StringOrdinal as being short for PrintableStringOrdinal.) It |
18 // should be used for data types that want to maintain one or more | 18 // should be used for data types that want to maintain one or more |
19 // orderings for nodes. | 19 // orderings for nodes. |
20 // | 20 // |
21 // Since StringOrdinals contain only printable characters, it is safe | 21 // Since StringOrdinals contain only printable characters, it is safe |
22 // to store as a string in a protobuf. | 22 // to store as a string in a protobuf. |
23 | 23 |
24 struct StringOrdinalTraits { | 24 struct StringOrdinalTraits { |
25 static const uint8_t kZeroDigit = 'a'; | 25 static const uint8_t kZeroDigit = 'a'; |
26 static const uint8_t kMaxDigit = 'z'; | 26 static const uint8_t kMaxDigit = 'z'; |
27 static const size_t kMinLength = 1; | 27 static const size_t kMinLength = 1; |
28 }; | 28 }; |
29 | 29 |
30 typedef Ordinal<StringOrdinalTraits> StringOrdinal; | 30 using StringOrdinal = Ordinal<StringOrdinalTraits>; |
31 | 31 |
32 static_assert(StringOrdinal::kZeroDigit == 'a', | 32 static_assert(StringOrdinal::kZeroDigit == 'a', |
33 "StringOrdinal has incorrect zero digit"); | 33 "StringOrdinal has incorrect zero digit"); |
34 static_assert(StringOrdinal::kOneDigit == 'b', | 34 static_assert(StringOrdinal::kOneDigit == 'b', |
35 "StringOrdinal has incorrect one digit"); | 35 "StringOrdinal has incorrect one digit"); |
36 static_assert(StringOrdinal::kMidDigit == 'n', | 36 static_assert(StringOrdinal::kMidDigit == 'n', |
37 "StringOrdinal has incorrect mid digit"); | 37 "StringOrdinal has incorrect mid digit"); |
38 static_assert(StringOrdinal::kMaxDigit == 'z', | 38 static_assert(StringOrdinal::kMaxDigit == 'z', |
39 "StringOrdinal has incorrect max digit"); | 39 "StringOrdinal has incorrect max digit"); |
40 static_assert(StringOrdinal::kMidDigitValue == 13, | 40 static_assert(StringOrdinal::kMidDigitValue == 13, |
41 "StringOrdinal has incorrect mid digit value"); | 41 "StringOrdinal has incorrect mid digit value"); |
42 static_assert(StringOrdinal::kMaxDigitValue == 25, | 42 static_assert(StringOrdinal::kMaxDigitValue == 25, |
43 "StringOrdinal has incorrect max digit value"); | 43 "StringOrdinal has incorrect max digit value"); |
44 static_assert(StringOrdinal::kRadix == 26, "StringOrdinal has incorrect radix"); | 44 static_assert(StringOrdinal::kRadix == 26, "StringOrdinal has incorrect radix"); |
45 | 45 |
46 } // namespace syncer | 46 } // namespace syncer |
47 | 47 |
48 #endif // COMPONENTS_SYNC_MODEL_STRING_ORDINAL_H_ | 48 #endif // COMPONENTS_SYNC_MODEL_STRING_ORDINAL_H_ |
OLD | NEW |