packages feed

squeeze-1.0.1.4: src/Squeeze/CommandOptions.hs

{-
	Copyright (C) 2010 Dr. Alistair Ward

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
-}
{- |
 [@AUTHOR@]	Dr. Alistair Ward

 [@DESCRIPTION@]

	* Defines options for program-operation, which are expected to be set from the command-line.

	* Defines appropriate default values.
-}

module Squeeze.CommandOptions(
-- * Types
-- ** Data-types
	CommandOptions(
--		MkCommandOptions,
		bisectionRatio,
		maximumBytes,
		minimumUsageRatio,
		verbose
	),
-- * Functions
	fileSizeBounds,
	minimumBytes,
	setVerbose
) where

import qualified	Squeeze.File		as File
import qualified	Squeeze.FileSizeBounds	as FileSizeBounds
import qualified	ToolShed.Defaultable	as Defaultable

-- | Declare a record used to contain command-line options.
data CommandOptions	= MkCommandOptions {
	bisectionRatio		:: Double,		-- ^ To facilitate parallelization, the file-list is bisected at LHS/Total, and combinations from the LHS are concatenated in parallel with each of those from the RHS.
	maximumBytes		:: File.FileSize,	-- ^ The maximum space (in bytes) available in which to store a subset of the specified files.
	minimumUsageRatio	:: Double,		-- ^ The minimum acceptable usage of 'maximumBytes'.
	verbose			:: Bool			-- ^ The minimum acceptable usage of 'maximumBytes'.
}

instance Defaultable.Defaultable CommandOptions	where
	defaultValue	= MkCommandOptions {
		bisectionRatio		= 0.5,		--Setting this this option to 'Nothing', will prevent parallelization, but will return solutions in a more predictable order.
		maximumBytes		= 4700000000,	--DVD-size; just under 4.4GiB.
		minimumUsageRatio	= 0.99,		--99% full.
		verbose			= False
	}

-- | Derives the minimum number of bytes, from other options.
minimumBytes :: CommandOptions -> File.FileSize
minimumBytes commandOptions	= floor $ minimumUsageRatio commandOptions * fromIntegral (maximumBytes commandOptions)

-- | The permissible bounds on the size of a file, or set of files.
fileSizeBounds :: CommandOptions -> FileSizeBounds.FileSizeBounds
fileSizeBounds commandOptions	= (minimumBytes commandOptions, maximumBytes commandOptions)

-- | Mutator.
setVerbose :: CommandOptions -> CommandOptions
setVerbose commandOptions	= commandOptions { verbose = True }