packages feed

casadi-bindings-core-1.9.0.1: Casadi/Core/Classes/PrintableObject.hs

{-# OPTIONS_GHC -Wall #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# Language ForeignFunctionInterface #-}
{-# Language FlexibleInstances #-}
{-# Language MultiParamTypeClasses #-}

module Casadi.Core.Classes.PrintableObject
       (
         PrintableObject,
         PrintableObjectClass(..),
         printableObject_getDescription,
         printableObject_getRepresentation,
       ) where


import Prelude hiding ( Functor )

import Data.Vector ( Vector )
import Foreign.C.Types
import Foreign.Marshal ( new, free )
import Foreign.Storable ( peek )
import Foreign.Ptr ( Ptr, nullPtr )
import Foreign.ForeignPtr ( newForeignPtr )
import System.IO.Unsafe ( unsafePerformIO ) -- for show instances

import Casadi.Internal.CToolsInstances ( )
import Casadi.Internal.FormatException ( formatException )
import Casadi.Internal.MarshalTypes ( StdVec, StdString) -- StdPair StdOstream'
import Casadi.Internal.Marshal ( Marshal(..), withMarshal )
import Casadi.Internal.WrapReturn ( WrapReturn(..) )
import Casadi.Core.Data
import Casadi.Core.Enums

instance Show PrintableObject where
  show = unsafePerformIO . printableObject_getDescription
-- direct wrapper
foreign import ccall unsafe "casadi__PrintableObject__getDescription" c_casadi__PrintableObject__getDescription
  :: Ptr (Ptr StdString) -> Ptr PrintableObject' -> IO (Ptr StdString)
casadi__PrintableObject__getDescription
  :: PrintableObject -> IO String
casadi__PrintableObject__getDescription x0 =
  withMarshal x0 $ \x0' ->
  do
    errStrPtrP <- new nullPtr
    ret <- c_casadi__PrintableObject__getDescription errStrPtrP x0'
    errStrPtr <- peek errStrPtrP
    free errStrPtrP
    if errStrPtr == nullPtr then wrapReturn ret else wrapReturn errStrPtr >>= (error . formatException)


-- classy wrapper
printableObject_getDescription :: PrintableObjectClass a => a -> IO String
printableObject_getDescription x = casadi__PrintableObject__getDescription (castPrintableObject x)


-- direct wrapper
foreign import ccall unsafe "casadi__PrintableObject__getRepresentation" c_casadi__PrintableObject__getRepresentation
  :: Ptr (Ptr StdString) -> Ptr PrintableObject' -> IO (Ptr StdString)
casadi__PrintableObject__getRepresentation
  :: PrintableObject -> IO String
casadi__PrintableObject__getRepresentation x0 =
  withMarshal x0 $ \x0' ->
  do
    errStrPtrP <- new nullPtr
    ret <- c_casadi__PrintableObject__getRepresentation errStrPtrP x0'
    errStrPtr <- peek errStrPtrP
    free errStrPtrP
    if errStrPtr == nullPtr then wrapReturn ret else wrapReturn errStrPtr >>= (error . formatException)


-- classy wrapper
printableObject_getRepresentation :: PrintableObjectClass a => a -> IO String
printableObject_getRepresentation x = casadi__PrintableObject__getRepresentation (castPrintableObject x)