Flutter Windows Embedder
sequential_id_generator.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_SEQUENTIAL_ID_GENERATOR_H_
6 #define FLUTTER_SHELL_PLATFORM_WINDOWS_SEQUENTIAL_ID_GENERATOR_H_
7 
8 #include <cstdint>
9 #include <unordered_map>
10 
11 #include "flutter/fml/macros.h"
12 
13 namespace flutter {
14 
15 // This is used to generate a series of sequential ID numbers in a way that a
16 // new ID is always the lowest possible ID in the sequence.
17 //
18 // based on
19 // https://source.chromium.org/chromium/chromium/src/+/main:ui/gfx/sequential_id_generator.h
21  public:
22  // Creates a new generator with the specified lower bound and uppoer bound for
23  // the IDs.
24  explicit SequentialIdGenerator(uint32_t min_id, uint32_t max_id);
26 
27  // Generates a unique ID to represent |number|. The generated ID is the
28  // smallest available ID greater than or equal to the |min_id| specified
29  // during creation of the generator.
30  uint32_t GetGeneratedId(uint32_t number);
31 
32  // Checks to see if the generator currently has a unique ID generated for
33  // |number|.
34  bool HasGeneratedIdFor(uint32_t number) const;
35 
36  // Removes the ID previously generated for |number| by calling
37  // |GetGeneratedID()| - does nothing if the number is not mapped.
38  void ReleaseNumber(uint32_t number);
39 
40  // Releases ID previously generated by calling |GetGeneratedID()|. Does
41  // nothing if the ID is not mapped.
42  void ReleaseId(uint32_t id);
43 
44  private:
45  typedef std::unordered_map<uint32_t, uint32_t> IdMap;
46 
47  uint32_t GetNextAvailableId();
48 
49  void UpdateNextAvailableIdAfterRelease(uint32_t id);
50 
51  IdMap number_to_id_;
52  IdMap id_to_number_;
53 
54  const uint32_t min_id_;
55  const uint32_t max_id_;
56  uint32_t min_available_id_;
57 
58  FML_DISALLOW_COPY_AND_ASSIGN(SequentialIdGenerator);
59 };
60 
61 } // namespace flutter
62 
63 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_SEQUENTIAL_ID_GENERATOR_H_
flutter::SequentialIdGenerator::ReleaseId
void ReleaseId(uint32_t id)
Definition: sequential_id_generator.cc:54
flutter::SequentialIdGenerator::ReleaseNumber
void ReleaseNumber(uint32_t number)
Definition: sequential_id_generator.cc:47
flutter::SequentialIdGenerator::SequentialIdGenerator
SequentialIdGenerator(uint32_t min_id, uint32_t max_id)
Definition: sequential_id_generator.cc:27
flutter
Definition: accessibility_bridge_windows.cc:11
flutter::SequentialIdGenerator::~SequentialIdGenerator
~SequentialIdGenerator()
Definition: sequential_id_generator.cc:30
flutter::SequentialIdGenerator::HasGeneratedIdFor
bool HasGeneratedIdFor(uint32_t number) const
Definition: sequential_id_generator.cc:43
flutter::SequentialIdGenerator
Definition: sequential_id_generator.h:20
flutter::SequentialIdGenerator::GetGeneratedId
uint32_t GetGeneratedId(uint32_t number)
Definition: sequential_id_generator.cc:32