Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
13namespace 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
59};
60
61} // namespace flutter
62
63#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_SEQUENTIAL_ID_GENERATOR_H_
bool HasGeneratedIdFor(uint32_t number) const
uint32_t GetGeneratedId(uint32_t number)
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27