| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_COMMON_STRING_ORDINAL_H_ | 5 #ifndef CHROME_COMMON_STRING_ORDINAL_H_ |
| 6 #define CHROME_COMMON_STRING_ORDINAL_H_ | 6 #define CHROME_COMMON_STRING_ORDINAL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 // has to change to represent the new order, and all the other older values | 22 // has to change to represent the new order, and all the other older values |
| 23 // can stay the same. | 23 // can stay the same. |
| 24 class StringOrdinal { | 24 class StringOrdinal { |
| 25 public: | 25 public: |
| 26 // Creates a StringOrdinal from the given string. It may be valid or invalid. | 26 // Creates a StringOrdinal from the given string. It may be valid or invalid. |
| 27 explicit StringOrdinal(const std::string& string_ordinal); | 27 explicit StringOrdinal(const std::string& string_ordinal); |
| 28 | 28 |
| 29 // Creates an invalid StringOrdinal. | 29 // Creates an invalid StringOrdinal. |
| 30 StringOrdinal(); | 30 StringOrdinal(); |
| 31 | 31 |
| 32 // Creates a valid initial StringOrdinal, this is called to create the first | |
| 33 // element of StringOrdinal list (i.e. before we have any other values we can | |
| 34 // generate from). | |
| 35 static StringOrdinal CreateInitialOrdinal(); | |
| 36 | |
| 37 bool IsValid() const; | 32 bool IsValid() const; |
| 38 | 33 |
| 39 // All remaining functions can only be called if IsValid() holds. | 34 // All remaining functions can only be called if IsValid() holds. |
| 40 // It is an error to call them if IsValid() is false. | 35 // It is an error to call them if IsValid() is false. |
| 41 | 36 |
| 42 // Order-related Functions | 37 // Order-related Functions |
| 43 | 38 |
| 44 // Returns true iff |*this| < |other|. | 39 // Returns true iff |*this| < |other|. |
| 45 bool LessThan(const StringOrdinal& other) const; | 40 bool LessThan(const StringOrdinal& other) const; |
| 46 | 41 |
| 47 // Returns true iff |*this| > |other|. | |
| 48 bool GreaterThan(const StringOrdinal& other) const; | |
| 49 | |
| 50 // Returns true iff |*this| == |other| (i.e. |*this| < |other| and | 42 // Returns true iff |*this| == |other| (i.e. |*this| < |other| and |
| 51 // |other| < |*this| are both false). | 43 // |other| < |*this| are both false). |
| 52 bool Equal(const StringOrdinal& other) const; | 44 bool Equal(const StringOrdinal& other) const; |
| 53 | 45 |
| 54 // Given |*this| != |other|, returns a StringOrdinal x such that | 46 // Given |*this| != |other|, returns a StringOrdinal x such that |
| 55 // min(|*this|, |other|) < x < max(|*this|, |other|). It is an error | 47 // min(|*this|, |other|) < x < max(|*this|, |other|). It is an error |
| 56 // to call this function when |*this| == |other|. | 48 // to call this function when |*this| == |other|. |
| 57 StringOrdinal CreateBetween(const StringOrdinal& other) const; | 49 StringOrdinal CreateBetween(const StringOrdinal& other) const; |
| 58 | 50 |
| 59 // Returns a StringOrdinal |x| such that |x| < |*this|. | 51 // Returns a StringOrdinal |x| such that |x| < |*this|. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 70 | 62 |
| 71 private: | 63 private: |
| 72 // The string representation of the StringOrdinal. | 64 // The string representation of the StringOrdinal. |
| 73 std::string string_ordinal_; | 65 std::string string_ordinal_; |
| 74 | 66 |
| 75 // The validity of the StringOrdinal (i.e., is it of the format [a-z]*[b-z]), | 67 // The validity of the StringOrdinal (i.e., is it of the format [a-z]*[b-z]), |
| 76 // created to cache validity to prevent frequent recalculations. | 68 // created to cache validity to prevent frequent recalculations. |
| 77 bool is_valid_; | 69 bool is_valid_; |
| 78 }; | 70 }; |
| 79 | 71 |
| 80 // A helper class that can be used by STL containers that require sorting. | |
| 81 class StringOrdinalLessThan { | |
| 82 public: | |
| 83 bool operator() (const StringOrdinal& lhs, const StringOrdinal& rhs) const; | |
| 84 }; | |
| 85 | |
| 86 #endif // CHROME_COMMON_STRING_ORDINAL_H_ | 72 #endif // CHROME_COMMON_STRING_ORDINAL_H_ |
| OLD | NEW |