contract ERC20CapEnabler is ERC20Mintable, CreatorRole {

    uint256 private _cap;
    bool private _capEnabled;

    event CapEnabled(address sender);
    event CapDisabled(address sender);
    event CapSet(address sender, uint256 amount);

    /**
     * @dev Returns the cap on the token's total supply.
     */
    function cap()
        public
        view
        returns (uint256) {
            return _cap;
    }

    /**
     * @dev Returns the cap control status.
     */
    function capEnabled()
        public
        view
        returns (bool) {
            return _capEnabled;
    }

    /**
     * @dev Enable cap control on minting.
     */
    function enableCap()
        external
        onlyCreator {
            _capEnabled = true;
            emit CapEnabled(msg.sender);
    }

    /**
     * @dev Disable cap control on minting and set cap back to 0.
     */
    function disableCap()
        external
        onlyCreator {
            _capEnabled = false;
            // set cap to 0
            _cap = 0;
            emit CapDisabled(msg.sender);
    }

    /**
     * @dev Set a new cap.
     */
    function setCap(uint256 _newCap)
        external
        onlyCreator {
            _cap = _newCap;
            emit CapSet(msg.sender, _newCap);
    }

    /**
     * @dev Overrides mint by checking whether cap control is enabled and
     * reverting if the token addition to supply will exceed the cap.
     */
    function mint(address account, uint256 value)
        public
        onlyMinter
        returns (bool) {
            if (_capEnabled) require(totalSupply().add(value) <= _cap, "ERC20CapEnabler: cap exceeded");
            return super.mint(account, value);
    }

}
/**
 * @dev Modification of OpenZeppelin's ERC20Capped. Implements a mechanism
 * to enable and disable cap control, as well as cap modification.
 */
function disableCap()
    external
    onlyCreator {
        _capEnabled = false;
        // set cap to 0
        _cap = 0;
        emit CapDisabled(msg.sender);
}

/**
 * @dev Disable cap control on minting and set cap back to 0.
 */