{-# LANGUAGE ForeignFunctionInterface, TypeFamilies, MultiParamTypeClasses, 
             FlexibleInstances, TypeSynonymInstances, EmptyDataDecls, 
             OverlappingInstances, IncoherentInstances #-}

module HROOT.Math.TRandom.Implementation where


import FFICXX.Runtime.Cast

import HROOT.Math.TRandom.RawType
import HROOT.Math.TRandom.FFI
import HROOT.Math.TRandom.Interface
import HROOT.Math.TRandom.Cast
import HROOT.Core.TClass.RawType
import HROOT.Core.TClass.Cast
import HROOT.Core.TClass.Interface
import HROOT.Core.TNamed.RawType
import HROOT.Core.TNamed.Cast
import HROOT.Core.TNamed.Interface
import HROOT.Core.TObject.RawType
import HROOT.Core.TObject.Cast
import HROOT.Core.TObject.Interface
import HROOT.Core.Deletable.RawType
import HROOT.Core.Deletable.Cast
import HROOT.Core.Deletable.Interface

import Data.Word
import Foreign.C
import Foreign.Ptr 
import Foreign.ForeignPtr

import System.IO.Unsafe


instance ITRandom TRandom where
  getSeed = xform0 c_trandom_getseed
  gaus = xform2 c_trandom_gaus
  setSeed = xform1 c_trandom_setseed
  uniform = xform2 c_trandom_uniform
instance ITNamed TRandom where
  setName = xform1 c_trandom_setname
  setNameTitle = xform2 c_trandom_setnametitle
  setTitle = xform1 c_trandom_settitle
instance ITObject TRandom where
  draw = xform1 c_trandom_draw
  findObject = xform1 c_trandom_findobject
  getName = xform0 c_trandom_getname
  isA = xform0 c_trandom_isa
  paint = xform1 c_trandom_paint
  printObj = xform1 c_trandom_printobj
  saveAs = xform2 c_trandom_saveas
  write = xform3 c_trandom_write
instance IDeletable TRandom where
  delete = xform0 c_trandom_delete

instance ITRandom (Exist TRandom) where
  getSeed (ETRandom x) = getSeed x
  gaus (ETRandom x) = gaus x
  setSeed (ETRandom x) = setSeed x
  uniform (ETRandom x) = uniform x
instance ITNamed (Exist TRandom) where
  setName (ETRandom x) = setName x
  setNameTitle (ETRandom x) = setNameTitle x
  setTitle (ETRandom x) = setTitle x
instance ITObject (Exist TRandom) where
  draw (ETRandom x) = draw x
  findObject (ETRandom x) = findObject x
  getName (ETRandom x) = getName x
  isA (ETRandom x) = isA x
  paint (ETRandom x) = paint x
  printObj (ETRandom x) = printObj x
  saveAs (ETRandom x) = saveAs x
  write (ETRandom x) = write x
instance IDeletable (Exist TRandom) where
  delete (ETRandom x) = delete x


newTRandom :: CInt -> IO TRandom
newTRandom = xform0 c_trandom_newtrandom





instance FPtr (Exist TRandom) where
  type Raw (Exist TRandom) = RawTRandom
  get_fptr (ETRandom obj) = castForeignPtr (get_fptr obj)
  cast_fptr_to_obj fptr = ETRandom (cast_fptr_to_obj (fptr :: ForeignPtr RawTRandom) :: TRandom)