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 StringOrdinal, this is generally 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 CreateValidOrdinal(); | |
akalin
2011/11/17 03:06:32
maybe "CreateFirstOrdinal"?
Finnur
2011/11/17 14:59:25
I went back and forth on this.
I vaguely prefer C
csharp
2011/11/17 19:51:58
Changing to CreateInitialOrdinal since that expres
| |
36 | |
32 bool IsValid() const; | 37 bool IsValid() const; |
33 | 38 |
34 // All remaining functions can only be called if IsValid() holds. | 39 // All remaining functions can only be called if IsValid() holds. |
35 // It is an error to call them if IsValid() is false. | 40 // It is an error to call them if IsValid() is false. |
36 | 41 |
37 // Order-related Functions | 42 // Order-related Functions |
38 | 43 |
39 // Returns true iff |*this| < |other|. | 44 // Returns true iff |*this| < |other|. |
40 bool LessThan(const StringOrdinal& other) const; | 45 bool LessThan(const StringOrdinal& other) const; |
41 | 46 |
42 // Returns true iff |*this| == |other| (i.e. |*this| < |other| and | 47 // Returns true iff |*this| == |other| (i.e. |*this| < |other| and |
43 // |other| < |*this| are both false). | 48 // |other| < |*this| are both false). |
44 bool Equal(const StringOrdinal& other) const; | 49 bool Equal(const StringOrdinal& other) const; |
45 | 50 |
46 // Given |*this| != |other|, returns a StringOrdinal x such that | 51 // Given |*this| != |other|, returns a StringOrdinal x such that |
47 // min(|*this|, |other|) < x < max(|*this|, |other|). It is an error | 52 // min(|*this|, |other|) < x < max(|*this|, |other|). It is an error |
48 // to call this function when |*this| == |other|. | 53 // to call this function when |*this| == |other|. |
49 StringOrdinal CreateBetween(const StringOrdinal& other) const; | 54 StringOrdinal CreateBetween(const StringOrdinal& other) const; |
50 | 55 |
51 // Returns a StringOrdinal |x| such that |x| < |*this|. | 56 // Returns a StringOrdinal |x| such that |x| < |*this|. |
52 StringOrdinal CreateBefore() const; | 57 StringOrdinal CreateBefore() const; |
53 | 58 |
54 // Returns a StringOrdinal |x| such that |*this| < |x|. | 59 // Returns a StringOrdinal |x| such that |*this| < |x|. |
55 StringOrdinal CreateAfter() const; | 60 StringOrdinal CreateAfter() const; |
56 | 61 |
57 // It is guaranteed that a StringOrdinal constructed from the returned | 62 // It is guaranteed that a StringOrdinal constructed from the returned |
58 // string will be valid. | 63 // string will be valid. |
59 std::string ToString() const; | 64 std::string ToString() const; |
60 | 65 |
66 // A comparsion struct that can be use by STL containers that require sorting. | |
67 struct Comparsion { | |
akalin
2011/11/17 03:06:32
Comparsion -> Comparison
Although the usual name
csharp
2011/11/17 19:51:58
Done.
| |
68 bool operator() (const StringOrdinal& lhs, const StringOrdinal& rhs) const { | |
69 return lhs.LessThan(rhs); | |
akalin
2011/11/17 03:06:32
de-inline this
csharp
2011/11/17 19:51:58
Done.
| |
70 } | |
71 }; | |
72 | |
61 // Use of copy constructor and default assignment for this class is allowed. | 73 // Use of copy constructor and default assignment for this class is allowed. |
62 | 74 |
63 private: | 75 private: |
64 // The string representation of the StringOrdinal. | 76 // The string representation of the StringOrdinal. |
65 std::string string_ordinal_; | 77 std::string string_ordinal_; |
66 | 78 |
67 // The validity of the StringOrdinal (i.e., is it of the format [a-z]*[b-z]), | 79 // The validity of the StringOrdinal (i.e., is it of the format [a-z]*[b-z]), |
68 // created to cache validity to prevent frequent recalculations. | 80 // created to cache validity to prevent frequent recalculations. |
69 bool is_valid_; | 81 bool is_valid_; |
70 }; | 82 }; |
71 | 83 |
72 #endif // CHROME_COMMON_STRING_ORDINAL_H_ | 84 #endif // CHROME_COMMON_STRING_ORDINAL_H_ |
OLD | NEW |