packages feed

casadi-bindings-control-2.0.0.1: Casadi/Control/Enums.hs

{-# OPTIONS_GHC -Wall #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# LANGUAGE MultiParamTypeClasses #-}

module Casadi.Control.Enums
       (
         DPLEInput(..),
         DPLEOutput(..),
       ) where


import Foreign.C.Types ( CInt(..) )
import Casadi.Internal.Marshal ( Marshal(..) )
import Casadi.Internal.WrapReturn ( WrapReturn(..) )

-- EnumDecl: DPLEInput
data DPLEInput = DPLE_A
               | DPLE_NUM_IN
               | DPLE_V
               deriving (Show, Eq)
instance Enum DPLEInput where
        fromEnum (DPLE_A) = 0
        fromEnum (DPLE_NUM_IN) = 2
        fromEnum (DPLE_V) = 1
        toEnum (0) = DPLE_A
        toEnum (2) = DPLE_NUM_IN
        toEnum (1) = DPLE_V
        toEnum k
          = error $ "DPLEInput: toEnum: got unhandled number: " ++ show k
instance Marshal DPLEInput CInt where
        marshal = return . fromIntegral . fromEnum
instance WrapReturn CInt DPLEInput where
        wrapReturn = return . toEnum . fromIntegral

-- EnumDecl: DPLEOutput
data DPLEOutput = DPLE_NUM_OUT
                | DPLE_P
                deriving (Show, Eq)
instance Enum DPLEOutput where
        fromEnum (DPLE_NUM_OUT) = 1
        fromEnum (DPLE_P) = 0
        toEnum (1) = DPLE_NUM_OUT
        toEnum (0) = DPLE_P
        toEnum k
          = error $ "DPLEOutput: toEnum: got unhandled number: " ++ show k
instance Marshal DPLEOutput CInt where
        marshal = return . fromIntegral . fromEnum
instance WrapReturn CInt DPLEOutput where
        wrapReturn = return . toEnum . fromIntegral