contract CappedCrowdsale is Crowdsale {
	using SafeMath for uint256;

	uint256 private _cap;

	/**
	 * @dev Constructor, takes maximum amount of tokens accepted in the crowdsale.
	 * @param cap Max amount of tokens to be contributed
	 */
	constructor(uint256 cap) public {
		require(cap > 0, "CappedCrowdsale: cap is 0");
		_cap = cap;
	}

	/**
	 * @return the cap of the crowdsale.
	 */
	function cap() public view returns (uint256) {
		return _cap;
	}

	/**
	 * @dev Checks whether the cap has been reached.
	 * @return Whether the cap was reached
	 */
	function capReached() public view returns (bool) {
		return tokenRaised() >= _cap;
	}

	/**
	 * @dev Extend parent behavior requiring purchase to respect the funding cap.
	 * @param beneficiary Token purchaser
	 * @param tokenAmount Amount of token contributed
	 */
	function _preValidatePurchase(address beneficiary, uint256 tokenAmount)
		internal
		view
	{
		super._preValidatePurchase(beneficiary, tokenAmount);
		require(
			tokenRaised().add(tokenAmount) <= _cap,
			"CappedCrowdsale: cap exceeded"
		);
	}
}
/**
 * @title CappedCrowdsale
 * @dev Crowdsale with a limit for total contributions.
 */
function _preValidatePurchase(address beneficiary, uint256 tokenAmount)
	internal
	view
{
	super._preValidatePurchase(beneficiary, tokenAmount);
	require(
		tokenRaised().add(tokenAmount) <= _cap,
		"CappedCrowdsale: cap exceeded"
	);
}

/**
 	 * @dev Extend parent behavior requiring purchase to respect the funding cap.
 	 * @param beneficiary Token purchaser
 	 * @param tokenAmount Amount of token contributed
 	 */