1// Copyright 2014 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
5import '_bitfield_io.dart'
6 if (dart.library.js_util) '_bitfield_web.dart' as bitfield;
7
8/// The largest SMI value.
9///
10/// See <https://www.dartlang.org/articles/numeric-computation/#smis-and-mints>
11///
12/// When compiling to JavaScript, this value is not supported since it is
13/// larger than the maximum safe 32bit integer.
14const int kMaxUnsignedSMI = bitfield.kMaxUnsignedSMI;
15
16/// A BitField over an enum (or other class whose values implement "index").
17/// Only the first 62 values of the enum can be used as indices.
18///
19/// When compiling to JavaScript, this class is not supported.
20abstract class BitField<T extends dynamic> {
21 /// Creates a bit field of all zeros.
22 ///
23 /// The given length must be at most 62.
24 factory BitField(int length) = bitfield.BitField<T>;
25
26 /// Creates a bit field filled with a particular value.
27 ///
28 /// If the value argument is true, the bits are filled with ones. Otherwise,
29 /// the bits are filled with zeros.
30 ///
31 /// The given length must be at most 62.
32 factory BitField.filled(int length, bool value) = bitfield.BitField<T>.filled;
33
34 /// Returns whether the bit with the given index is set to one.
35 bool operator [](T index);
36
37 /// Sets the bit with the given index to the given value.
38 ///
39 /// If value is true, the bit with the given index is set to one. Otherwise,
40 /// the bit is set to zero.
41 void operator []=(T index, bool value);
42
43 /// Sets all the bits to the given value.
44 ///
45 /// If the value is true, the bits are all set to one. Otherwise, the bits are
46 /// all set to zero. Defaults to setting all the bits to zero.
47 void reset([ bool value = false ]);
48}
49