1234567891011121314151617181920212223242526272829303132 |
- // SPDX-License-Identifier: MIT
- pragma solidity ^0.8.0;
- /**
- * @title Counters
- * @author Matt Condon (@shrugs)
- * @dev Provides counters that can only be incremented or decremented by one. This can be used e.g. to track the number
- * of elements in a mapping, issuing ERC721 ids, or counting request ids.
- *
- * Include with `using Counters for Counters.Counter;`
- */
- library Counters {
- struct Counter {
- // This variable should never be directly accessed by users of the library: interactions must be restricted to
- // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
- // this feature: see https://github.com/ethereum/solidity/issues/4637
- uint256 _value; // default: 0
- }
- function current(Counter storage counter) internal view returns (uint256) {
- return counter._value;
- }
- function increment(Counter storage counter) internal {
- counter._value += 1;
- }
- function decrement(Counter storage counter) internal {
- counter._value = counter._value - 1;
- }
- }
|