Permalink
Browse files

Added binding to spawn_rng

  • Loading branch information...
1 parent 466ef19 commit 7851b3a6f24764809d0cb6370af70901ce1205cc @bjpop committed Apr 6, 2011
Showing with 16 additions and 0 deletions.
  1. +8 −0 src/Sprng/Internal.hs
  2. +7 −0 src/cbits/sprng_wrapper.cpp
  3. +1 −0 src/include/sprng_wrapper.h
@@ -9,10 +9,12 @@ module Sprng.Internal
, get_rn_dbl
, free_rng
, print_rng
+ , spawn_rng
) where
import Foreign.Ptr (Ptr)
import Foreign.C.Types (CInt, CFloat, CDouble)
+import Foreign.Marshal.Array (peekArray)
type SprngPtr = Ptr ()
@@ -23,3 +25,9 @@ foreign import ccall "get_rn_flt" get_rn_flt :: SprngPtr -> IO CFloat
foreign import ccall "get_rn_dbl" get_rn_dbl :: SprngPtr -> IO CDouble
foreign import ccall "free_rng" free_rng :: SprngPtr -> IO ()
foreign import ccall "print_rng" print_rng :: SprngPtr -> IO ()
+foreign import ccall "spawn_rng" spawn_rng_ :: SprngPtr -> CInt -> IO (Ptr SprngPtr)
+
+spawn_rng :: SprngPtr -> Int -> IO [SprngPtr]
+spawn_rng rng num = do
+ arr <- spawn_rng_ rng $ fromIntegral num
+ peekArray num arr
@@ -36,3 +36,10 @@ void print_rng(Sprng *rng)
{
rng->print_rng();
}
+
+Sprng **spawn_rng(Sprng *rng, int num)
+{
+ Sprng **new_rngs;
+ rng->spawn_rng(num, &new_rngs);
+ return new_rngs;
+}
@@ -14,5 +14,6 @@ extern "C" float get_rn_flt(Sprng *);
extern "C" double get_rn_dbl(Sprng *);
extern "C" void free_rng(Sprng *);
extern "C" void print_rng(Sprng *);
+extern "C" Sprng **spawn_rng(Sprng *, int);
#endif

0 comments on commit 7851b3a

Please sign in to comment.