{-# LINE 1 "./QuantLib/Context.chs" #-}
module QuantLib.Context
(
Error(..)
, setEvaluationDate
, setEnforceTodaysHistoricFixings
, setIncludeTodaysCashFlows
, setIncludeReferenceDateEvents
, disableUpdates
, enableUpdates
, keepingSettings
, keepingSettingsGc
, collectGarbage
, setExtendedPrecision
, evaluationDate
, enforceTodaysHistoricFixings
, includeTodaysCashFlows
, includeReferenceDateEvents
, updatesEnabled
, updatesDeferred
, version
, boostVersion
, epsilon
) where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Marshal.Utils as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import Foreign.C.Types(CDouble)
import Foreign.C.String(CString, peekCString)
import System.IO.Unsafe(unsafePerformIO)
import System.Mem(performGC)
import Control.Exception(bracket)
import QuantLib.Time.Date
import QuantLib.Internal
setExtendedPrecision :: IO ()
setExtendedPrecision :: IO ()
setExtendedPrecision =
IO ()
setExtendedPrecision'_ IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
() -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
{-# LINE 45 "./QuantLib/Context.chs" #-}
evaluationDate :: IO ((Day))
evaluationDate :: IO Day
evaluationDate =
IO CInt
evaluationDate'_ IO CInt -> (CInt -> IO Day) -> IO Day
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \CInt
res ->
let {res' :: Day
res' = CInt -> Day
toDay CInt
res} in
Day -> IO Day
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Day
res')
{-# LINE 55 "./QuantLib/Context.chs" #-}
setEvaluationDate :: (Maybe Day) -> IO ()
setEvaluationDate :: Maybe Day -> IO ()
setEvaluationDate Maybe Day
a1 =
Maybe Day -> (CInt -> IO ()) -> IO ()
forall a. Maybe Day -> (CInt -> IO a) -> IO a
withMaybeDay Maybe Day
a1 ((CInt -> IO ()) -> IO ()) -> (CInt -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CInt
a1' ->
(Ptr (Ptr CChar) -> IO ()) -> IO ()
forall a b. (Ptr (Ptr a) -> IO b) -> IO b
preErrorCheck ((Ptr (Ptr CChar) -> IO ()) -> IO ())
-> (Ptr (Ptr CChar) -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr (Ptr CChar)
a2' ->
CInt -> Ptr (Ptr CChar) -> IO ()
setEvaluationDate'_ CInt
a1' Ptr (Ptr CChar)
a2' IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
Ptr (Ptr CChar) -> IO ()
errorCheck Ptr (Ptr CChar)
a2'IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
() -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
{-# LINE 60 "./QuantLib/Context.chs" #-}
enforceTodaysHistoricFixings :: IO ((Bool))
enforceTodaysHistoricFixings =
enforceTodaysHistoricFixings'_ >>= \res ->
let {res' = C2HSImp.toBool res} in
return (res')
{-# LINE 64 "./QuantLib/Context.chs" #-}
setEnforceTodaysHistoricFixings :: (Bool) -> IO ()
setEnforceTodaysHistoricFixings a1 =
let {a1' = C2HSImp.fromBool a1} in
setEnforceTodaysHistoricFixings'_ a1' >>
return ()
{-# LINE 67 "./QuantLib/Context.chs" #-}
includeTodaysCashFlows :: IO ((Maybe Bool))
includeTodaysCashFlows =
includeTodaysCashFlows'_ >>= \res ->
let {res' = toMaybeBool res} in
return (res')
{-# LINE 71 "./QuantLib/Context.chs" #-}
setIncludeTodaysCashFlows :: (Maybe Bool) -> IO ()
setIncludeTodaysCashFlows a1 =
let {a1' = fromMaybeBool a1} in
setIncludeTodaysCashFlows'_ a1' >>
return ()
{-# LINE 74 "./QuantLib/Context.chs" #-}
includeReferenceDateEvents :: IO ((Bool))
includeReferenceDateEvents =
includeReferenceDateEvents'_ >>= \res ->
let {res' = C2HSImp.toBool res} in
return (res')
{-# LINE 77 "./QuantLib/Context.chs" #-}
setIncludeReferenceDateEvents :: (Bool) -> IO ()
setIncludeReferenceDateEvents a1 =
let {a1' = C2HSImp.fromBool a1} in
setIncludeReferenceDateEvents'_ a1' >>
return ()
{-# LINE 80 "./QuantLib/Context.chs" #-}
disableUpdates :: (Bool)
-> IO ()
disableUpdates :: Bool -> IO ()
disableUpdates Bool
a1 =
let {a1' :: CInt
a1' = Bool -> CInt
forall a. Num a => Bool -> a
C2HSImp.fromBool Bool
a1} in
CInt -> IO ()
disableUpdates'_ CInt
a1' IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
() -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
{-# LINE 85 "./QuantLib/Context.chs" #-}
enableUpdates :: IO ()
enableUpdates =
preErrorCheck $ \a1' ->
enableUpdates'_ a1' >>
errorCheck a1'>>
return ()
{-# LINE 88 "./QuantLib/Context.chs" #-}
updatesEnabled :: IO ((Bool))
updatesEnabled =
updatesEnabled'_ >>= \res ->
let {res' = C2HSImp.toBool res} in
return (res')
{-# LINE 91 "./QuantLib/Context.chs" #-}
updatesDeferred :: IO ((Bool))
updatesDeferred =
updatesDeferred'_ >>= \res ->
let {res' = C2HSImp.toBool res} in
return (res')
{-# LINE 94 "./QuantLib/Context.chs" #-}
keepingSettings :: IO b -> IO b
keepingSettings = bracket qlSavedSettings qlFreeSavedSettings . const
keepingSettingsGc :: IO b -> IO b
keepingSettingsGc :: forall b. IO b -> IO b
keepingSettingsGc = IO (Ptr ()) -> (Ptr () -> IO ()) -> (Ptr () -> IO b) -> IO b
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket IO (Ptr ())
qlSavedSettings (\Ptr ()
s -> IO ()
collectGarbage IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Ptr () -> IO ()
qlFreeSavedSettings Ptr ()
s) ((Ptr () -> IO b) -> IO b)
-> (IO b -> Ptr () -> IO b) -> IO b -> IO b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO b -> Ptr () -> IO b
forall a b. a -> b -> a
const
collectGarbage :: IO ()
collectGarbage :: IO ()
collectGarbage = IO ()
performGC IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> IO ()
performGC
foreign import ccall safe "ql.h qlVersion" qlVersion :: IO CString
foreign import ccall safe "ql.h qlBoostVersion" qlBoostVersion :: IO CString
foreign import ccall safe "ql.h qlEpsilon" qlEpsilon :: CDouble
{-# NOINLINE version #-}
version :: String
version :: String
version = IO String -> String
forall a. IO a -> a
unsafePerformIO (IO String -> String) -> IO String -> String
forall a b. (a -> b) -> a -> b
$ IO (Ptr CChar)
qlVersion IO (Ptr CChar) -> (Ptr CChar -> IO String) -> IO String
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Ptr CChar -> IO String
peekCString
{-# NOINLINE boostVersion #-}
boostVersion :: String
boostVersion :: String
boostVersion = IO String -> String
forall a. IO a -> a
unsafePerformIO (IO String -> String) -> IO String -> String
forall a b. (a -> b) -> a -> b
$ IO (Ptr CChar)
qlBoostVersion IO (Ptr CChar) -> (Ptr CChar -> IO String) -> IO String
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Ptr CChar -> IO String
peekCString
epsilon :: Double
epsilon :: Double
epsilon = CDouble -> Double
forall a b. (Real a, Fractional b) => a -> b
realToFrac CDouble
qlEpsilon
foreign import ccall safe "QuantLib/Context.chs.h qlSetExtendedPrecision"
setExtendedPrecision'_ :: (IO ())
foreign import ccall safe "QuantLib/Context.chs.h qlSettingsEvaluationDate"
evaluationDate'_ :: (IO C2HSImp.CInt)
foreign import ccall safe "QuantLib/Context.chs.h qlSettingsSetEvaluationDate"
setEvaluationDate'_ :: (C2HSImp.CInt -> ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO ())))
foreign import ccall safe "QuantLib/Context.chs.h qlSettingsEnforceTodaysHistoricFixings"
enforceTodaysHistoricFixings'_ :: (IO C2HSImp.CInt)
foreign import ccall safe "QuantLib/Context.chs.h qlSettingsSetEnforceTodaysHistoricFixings"
setEnforceTodaysHistoricFixings'_ :: (C2HSImp.CInt -> (IO ()))
foreign import ccall safe "QuantLib/Context.chs.h qlSettingsIncludeTodaysCashFlows"
includeTodaysCashFlows'_ :: (IO C2HSImp.CInt)
foreign import ccall safe "QuantLib/Context.chs.h qlSettingsSetIncludeTodaysCashFlows"
setIncludeTodaysCashFlows'_ :: (C2HSImp.CInt -> (IO ()))
foreign import ccall safe "QuantLib/Context.chs.h qlSettingsIncludeReferenceDateEvents"
includeReferenceDateEvents'_ :: (IO C2HSImp.CInt)
foreign import ccall safe "QuantLib/Context.chs.h qlSettingsSetIncludeReferenceDateEvents"
setIncludeReferenceDateEvents'_ :: (C2HSImp.CInt -> (IO ()))
foreign import ccall safe "QuantLib/Context.chs.h qlObservableSettingsDisableUpdates"
disableUpdates'_ :: (C2HSImp.CInt -> (IO ()))
foreign import ccall safe "QuantLib/Context.chs.h qlObservableSettingsEnableUpdates"
enableUpdates'_ :: ((C2HSImp.Ptr (C2HSImp.Ptr C2HSImp.CChar)) -> (IO ()))
foreign import ccall safe "QuantLib/Context.chs.h qlObservableSettingsUpdatesEnabled"
updatesEnabled'_ :: (IO C2HSImp.CInt)
foreign import ccall safe "QuantLib/Context.chs.h qlObservableSettingsUpdatesDeferred"
updatesDeferred'_ :: (IO C2HSImp.CInt)