Permalink
Browse files

Generalised wrapper from LFG class to Sprng class.

  • Loading branch information...
1 parent e0eea27 commit 466ef1919c3d7412c7f1a93ea36dee7332882223 @bjpop committed Apr 5, 2011
Showing with 74 additions and 60 deletions.
  1. +1 −0 .gitignore
  2. +1 −1 haskell-sprng.cabal
  3. +16 −14 src/Sprng/Internal.hs
  4. +0 −31 src/cbits/lfg_wrapper.cpp
  5. +38 −0 src/cbits/sprng_wrapper.cpp
  6. +0 −14 src/include/lfg_wrapper.h
  7. +18 −0 src/include/sprng_wrapper.h
View
@@ -0,0 +1 @@
+dist
View
@@ -24,7 +24,7 @@ Library
build-tools:
ghc-options: -Wall -fno-warn-name-shadowing -fno-warn-orphans -pgml g++
c-sources:
- src/cbits/lfg_wrapper.cpp
+ src/cbits/sprng_wrapper.cpp
include-dirs:
src/include
hs-source-dirs:
View
@@ -1,23 +1,25 @@
{-# LANGUAGE ForeignFunctionInterface #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
module Sprng.Internal
- ( LFGPtr
- , new_lfg
- , init_lfg
- , get_rn_int_lfg
- , get_rn_flt_lfg
- , get_rn_dbl_lfg
- , free_lfg
+ ( SprngPtr
+ , new_rng
+ , init_rng
+ , get_rn_int
+ , get_rn_flt
+ , get_rn_dbl
+ , free_rng
+ , print_rng
) where
import Foreign.Ptr (Ptr)
import Foreign.C.Types (CInt, CFloat, CDouble)
-type LFGPtr = Ptr ()
+type SprngPtr = Ptr ()
-foreign import ccall "new_lfg" new_lfg :: IO LFGPtr
-foreign import ccall "init_lfg" init_lfg :: LFGPtr -> CInt -> CInt -> CInt -> CInt -> IO ()
-foreign import ccall "get_rn_int_lfg" get_rn_int_lfg :: LFGPtr -> IO CInt
-foreign import ccall "get_rn_flt_lfg" get_rn_flt_lfg :: LFGPtr -> IO CFloat
-foreign import ccall "get_rn_dbl_lfg" get_rn_dbl_lfg :: LFGPtr -> IO CDouble
-foreign import ccall "free_lfg" free_lfg :: LFGPtr -> IO ()
+foreign import ccall "new_rng" new_rng :: CInt -> IO SprngPtr
+foreign import ccall "init_rng" init_rng :: SprngPtr -> CInt -> CInt -> CInt -> CInt -> IO ()
+foreign import ccall "get_rn_int" get_rn_int :: SprngPtr -> IO CInt
+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 ()
View
@@ -1,31 +0,0 @@
-#include "lfg_wrapper.h"
-
-LFG * new_lfg(void)
-{
- return new LFG;
-}
-
-void init_lfg(LFG *lfg, int streamnum, int nstreams, int seed, int pa)
-{
- lfg->init_rng(streamnum, nstreams, seed, pa);
-}
-
-int get_rn_int_lfg(LFG *lfg)
-{
- return lfg->get_rn_int();
-}
-
-float get_rn_flt_lfg(LFG *lfg)
-{
- return lfg->get_rn_flt();
-}
-
-double get_rn_dbl_lfg(LFG *lfg)
-{
- return lfg->get_rn_dbl();
-}
-
-void free_lfg(LFG *lfg)
-{
- lfg->free_rng();
-}
@@ -0,0 +1,38 @@
+#include "sprng_wrapper.h"
+
+// Sprng * new_rng(Rng_type type)
+// XXX should use the enum type instead.
+Sprng * new_rng(int type)
+{
+ return SelectType(type);
+}
+
+void init_rng(Sprng *rng, int streamnum, int nstreams, int seed, int pa)
+{
+ rng->init_rng(streamnum, nstreams, seed, pa);
+}
+
+int get_rn_int(Sprng *rng)
+{
+ return rng->get_rn_int();
+}
+
+float get_rn_flt(Sprng *rng)
+{
+ return rng->get_rn_flt();
+}
+
+double get_rn_dbl(Sprng *rng)
+{
+ return rng->get_rn_dbl();
+}
+
+void free_rng(Sprng *rng)
+{
+ rng->free_rng();
+}
+
+void print_rng(Sprng *rng)
+{
+ rng->print_rng();
+}
View
@@ -1,14 +0,0 @@
-#ifndef LFG_WRAPPER_H
-#define LFG_WRAPPER_H
-
-#include "sprng.h"
-#include "lfg.h"
-
-extern "C" LFG * new_lfg(void);
-extern "C" void init_lfg(LFG *, int, int, int, int);
-extern "C" int get_rn_int_lfg(LFG *);
-extern "C" float get_rn_flt_lfg(LFG *);
-extern "C" double get_rn_dbl_lfg(LFG *);
-extern "C" void free_lfg(LFG *);
-
-#endif
@@ -0,0 +1,18 @@
+#ifndef SPRNG_WRAPPER_H
+#define SPRNG_WRAPPER_H
+
+#include "sprng.h"
+#include "sprng_cpp.h"
+
+typedef enum { LFG, LCG, LCG64, CMRG, MLFG, PMLCG } Rng_type;
+
+//extern "C" Sprng * new_rng(Rng_type);
+extern "C" Sprng * new_rng(int);
+extern "C" void init_rng(Sprng *, int, int, int, int);
+extern "C" int get_rn_int(Sprng *);
+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 *);
+
+#endif

0 comments on commit 466ef19

Please sign in to comment.