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

Side by Side Diff: sync/internal_api/public/base/ordinal.h

Issue 809073005: replace COMPILE_ASSERT with static_assert in sync/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix nit Created 5 years, 11 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 unified diff | Download patch
OLDNEW
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_ORDINAL_H_ 5 #ifndef SYNC_INTERNAL_API_PUBLIC_BASE_ORDINAL_H_
6 #define SYNC_INTERNAL_API_PUBLIC_BASE_ORDINAL_H_ 6 #define SYNC_INTERNAL_API_PUBLIC_BASE_ORDINAL_H_
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <cstddef> 9 #include <cstddef>
10 #include <string> 10 #include <string>
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 // Constants for Ordinal digits. 134 // Constants for Ordinal digits.
135 static const uint8 kZeroDigit = Traits::kZeroDigit; 135 static const uint8 kZeroDigit = Traits::kZeroDigit;
136 static const uint8 kMaxDigit = Traits::kMaxDigit; 136 static const uint8 kMaxDigit = Traits::kMaxDigit;
137 static const size_t kMinLength = Traits::kMinLength; 137 static const size_t kMinLength = Traits::kMinLength;
138 static const uint8 kOneDigit = kZeroDigit + 1; 138 static const uint8 kOneDigit = kZeroDigit + 1;
139 static const uint8 kMidDigit = kOneDigit + (kMaxDigit - kOneDigit) / 2; 139 static const uint8 kMidDigit = kOneDigit + (kMaxDigit - kOneDigit) / 2;
140 static const unsigned int kMidDigitValue = kMidDigit - kZeroDigit; 140 static const unsigned int kMidDigitValue = kMidDigit - kZeroDigit;
141 static const unsigned int kMaxDigitValue = kMaxDigit - kZeroDigit; 141 static const unsigned int kMaxDigitValue = kMaxDigit - kZeroDigit;
142 static const unsigned int kRadix = kMaxDigitValue + 1; 142 static const unsigned int kRadix = kMaxDigitValue + 1;
143 143
144 COMPILE_ASSERT(kOneDigit > kZeroDigit, OrdinalOneDigitGreaterThanMinDigit); 144 static_assert(kOneDigit > kZeroDigit, "incorrect ordinal one digit");
145 COMPILE_ASSERT(kMidDigit > kOneDigit, OrdinalMidDigitGreaterThanOneDigit); 145 static_assert(kMidDigit > kOneDigit, "incorrect ordinal mid digit");
146 COMPILE_ASSERT(kMaxDigit > kMidDigit, OrdinalMaxDigitGreaterThanMidDigit); 146 static_assert(kMaxDigit > kMidDigit, "incorrect ordinal max digit");
147 COMPILE_ASSERT(kMinLength > 0, OrdinalMinLengthIsPositive); 147 static_assert(kMinLength > 0, "incorrect ordinal min length");
148 COMPILE_ASSERT(kMidDigitValue > 1, OrdinalMidDigitValueGreaterThanOne); 148 static_assert(kMidDigitValue > 1, "incorrect ordinal mid digit");
149 COMPILE_ASSERT(kMaxDigitValue > kMidDigitValue, 149 static_assert(kMaxDigitValue > kMidDigitValue, "incorrect ordinal max digit");
150 OrdinalMaxDigitValueGreaterThanMidDigitValue); 150 static_assert(kRadix == kMaxDigitValue + 1, "incorrect ordinal radix");
151 COMPILE_ASSERT(kRadix == kMaxDigitValue + 1,
152 OrdinalRadixIsMaxDigitValuePlusOne);
153 151
154 private: 152 private:
155 // Returns true iff the given byte string satisfies the criteria for 153 // Returns true iff the given byte string satisfies the criteria for
156 // a valid Ordinal. 154 // a valid Ordinal.
157 static bool IsValidOrdinalBytes(const std::string& bytes); 155 static bool IsValidOrdinalBytes(const std::string& bytes);
158 156
159 // Returns the length that bytes.substr(0, length) would be with 157 // Returns the length that bytes.substr(0, length) would be with
160 // trailing zero digits removed. 158 // trailing zero digits removed.
161 static size_t GetLengthWithoutTrailingZeroDigits( 159 static size_t GetLengthWithoutTrailingZeroDigits(
162 const std::string& bytes, 160 const std::string& bytes,
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 DCHECK_LT(midpoint, end_bytes); 475 DCHECK_LT(midpoint, end_bytes);
478 476
479 Ordinal<Traits> midpoint_ordinal(midpoint); 477 Ordinal<Traits> midpoint_ordinal(midpoint);
480 DCHECK(midpoint_ordinal.IsValid()); 478 DCHECK(midpoint_ordinal.IsValid());
481 return midpoint_ordinal; 479 return midpoint_ordinal;
482 } 480 }
483 481
484 } // namespace syncer 482 } // namespace syncer
485 483
486 #endif // SYNC_INTERNAL_API_PUBLIC_BASE_ORDINAL_H_ 484 #endif // SYNC_INTERNAL_API_PUBLIC_BASE_ORDINAL_H_
OLDNEW
« no previous file with comments | « sync/internal_api/public/base/node_ordinal.h ('k') | sync/internal_api/public/base/ordinal_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698