Skip to content

Commit

Permalink
Generalised wrapper from LFG class to Sprng class.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjpop committed Apr 5, 2011
1 parent e0eea27 commit 466ef19
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 60 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
2 changes: 1 addition & 1 deletion haskell-sprng.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
30 changes: 16 additions & 14 deletions src/Sprng/Internal.hs
Original file line number Diff line number Diff line change
@@ -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 ()
31 changes: 0 additions & 31 deletions src/cbits/lfg_wrapper.cpp

This file was deleted.

38 changes: 38 additions & 0 deletions src/cbits/sprng_wrapper.cpp
Original file line number Diff line number Diff line change
@@ -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();
}
14 changes: 0 additions & 14 deletions src/include/lfg_wrapper.h

This file was deleted.

18 changes: 18 additions & 0 deletions src/include/sprng_wrapper.h
Original file line number Diff line number Diff line change
@@ -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.