| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 UI_GFX_SEQUENTIAL_ID_GENERATOR_H_ | 5 #ifndef UI_GFX_SEQUENTIAL_ID_GENERATOR_H_ |
| 6 #define UI_GFX_SEQUENTIAL_ID_GENERATOR_H_ | 6 #define UI_GFX_SEQUENTIAL_ID_GENERATOR_H_ |
| 7 | 7 |
| 8 #include <stdint.h> |
| 9 |
| 8 #include <map> | 10 #include <map> |
| 9 | 11 |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
| 13 #include "base/macros.h" |
| 12 #include "ui/gfx/gfx_export.h" | 14 #include "ui/gfx/gfx_export.h" |
| 13 | 15 |
| 14 namespace ui { | 16 namespace ui { |
| 15 | 17 |
| 16 // This is used to generate a series of sequential ID numbers in a way that a | 18 // This is used to generate a series of sequential ID numbers in a way that a |
| 17 // new ID is always the lowest possible ID in the sequence. | 19 // new ID is always the lowest possible ID in the sequence. |
| 18 class GFX_EXPORT SequentialIDGenerator { | 20 class GFX_EXPORT SequentialIDGenerator { |
| 19 public: | 21 public: |
| 20 // Creates a new generator with the specified lower bound for the IDs. | 22 // Creates a new generator with the specified lower bound for the IDs. |
| 21 explicit SequentialIDGenerator(uint32 min_id); | 23 explicit SequentialIDGenerator(uint32_t min_id); |
| 22 ~SequentialIDGenerator(); | 24 ~SequentialIDGenerator(); |
| 23 | 25 |
| 24 // Generates a unique ID to represent |number|. The generated ID is the | 26 // Generates a unique ID to represent |number|. The generated ID is the |
| 25 // smallest available ID greater than or equal to the |min_id| specified | 27 // smallest available ID greater than or equal to the |min_id| specified |
| 26 // during creation of the generator. | 28 // during creation of the generator. |
| 27 uint32 GetGeneratedID(uint32 number); | 29 uint32_t GetGeneratedID(uint32_t number); |
| 28 | 30 |
| 29 // Checks to see if the generator currently has a unique ID generated for | 31 // Checks to see if the generator currently has a unique ID generated for |
| 30 // |number|. | 32 // |number|. |
| 31 bool HasGeneratedIDFor(uint32 number) const; | 33 bool HasGeneratedIDFor(uint32_t number) const; |
| 32 | 34 |
| 33 // Removes the generated ID |id| from the internal mapping. Since the ID is | 35 // Removes the generated ID |id| from the internal mapping. Since the ID is |
| 34 // no longer mapped to any number, subsequent calls to |GetGeneratedID()| can | 36 // no longer mapped to any number, subsequent calls to |GetGeneratedID()| can |
| 35 // use this ID. | 37 // use this ID. |
| 36 void ReleaseGeneratedID(uint32 id); | 38 void ReleaseGeneratedID(uint32_t id); |
| 37 | 39 |
| 38 // Removes the ID previously generated for |number| by calling | 40 // Removes the ID previously generated for |number| by calling |
| 39 // |GetGeneratedID()|. | 41 // |GetGeneratedID()|. |
| 40 void ReleaseNumber(uint32 number); | 42 void ReleaseNumber(uint32_t number); |
| 41 | 43 |
| 42 void ResetForTest(); | 44 void ResetForTest(); |
| 43 | 45 |
| 44 private: | 46 private: |
| 45 typedef base::hash_map<uint32, uint32> IDMap; | 47 typedef base::hash_map<uint32_t, uint32_t> IDMap; |
| 46 | 48 |
| 47 uint32 GetNextAvailableID(); | 49 uint32_t GetNextAvailableID(); |
| 48 | 50 |
| 49 void UpdateNextAvailableIDAfterRelease(uint32 id); | 51 void UpdateNextAvailableIDAfterRelease(uint32_t id); |
| 50 | 52 |
| 51 IDMap number_to_id_; | 53 IDMap number_to_id_; |
| 52 IDMap id_to_number_; | 54 IDMap id_to_number_; |
| 53 | 55 |
| 54 const uint32 min_id_; | 56 const uint32_t min_id_; |
| 55 uint32 min_available_id_; | 57 uint32_t min_available_id_; |
| 56 | 58 |
| 57 DISALLOW_COPY_AND_ASSIGN(SequentialIDGenerator); | 59 DISALLOW_COPY_AND_ASSIGN(SequentialIDGenerator); |
| 58 }; | 60 }; |
| 59 | 61 |
| 60 } // namespace ui | 62 } // namespace ui |
| 61 | 63 |
| 62 #endif // UI_GFX_SEQUENTIAL_ID_GENERATOR_H_ | 64 #endif // UI_GFX_SEQUENTIAL_ID_GENERATOR_H_ |
| OLD | NEW |