on master help sign in
added a few instances
cebcaa2aslatter
Data/UUID.hs+25
@@ -1,4 +1,5 @@
1{-# INCLUDE <uuid/uuid.h> #-}
1{-# INCLUDE <uuid/uuid.h> #-}
2+{-# INCLUDE <string.h> #-}
2{-# LANGUAGE ForeignFunctionInterface #-}
3{-# LANGUAGE ForeignFunctionInterface #-}
3
4
4-- |Haskell bindings to /libuuid/.
5-- |Haskell bindings to /libuuid/.
@@ -26,6 +27,8 @@ import Foreign.C
26import Foreign.ForeignPtr
27import Foreign.ForeignPtr
27import Foreign
28import Foreign
28
29
30+import Data.Typeable
31+
29import Prelude hiding (null)
32import Prelude hiding (null)
30
33
31import Data.UUID.Internal
34import Data.UUID.Internal
@@ -50,6 +53,23 @@ instance Read UUID where
50 Nothing -> []
53 Nothing -> []
51 Just u -> [(u,drop 36 str)]
54 Just u -> [(u,drop 36 str)]
52
55
56+instance Typeable UUID where
57+ typeOf _ = mkTyConApp (mkTyCon "Data.UUID.UUID") []
58+
59+instance Storable UUID where
60+ sizeOf _ = (16 *) $ alignment (undefined :: CChar)
61+ alignment _ = alignment (undefined :: CChar)
62+
63+ peek psource = do
64+ fp <- mallocForeignPtrArray 16
65+ withForeignPtr fp $ \pdest ->
66+ memcpy pdest psource $ fromIntegral $ sizeOf (undefined :: UUID)
67+ return $ U fp
68+
69+ poke pdest (U fp) = withForeignPtr fp $ \psource ->
70+ memcpy pdest psource $ fromIntegral $ sizeOf (undefined :: UUID)
71+
72+
53-- |Creates a new 'UUID'. If \/dev\/urandom is available, it will be used.
73-- |Creates a new 'UUID'. If \/dev\/urandom is available, it will be used.
54-- Otherwise a UUID will be generated based on the current time and the
74-- Otherwise a UUID will be generated based on the current time and the
55-- hardware MAC address, if available.
75-- hardware MAC address, if available.
@@ -177,3 +197,8 @@ foreign import ccall unsafe "uuid_type"
177
197
178foreign import ccall unsafe "uuid_variant"
198foreign import ccall unsafe "uuid_variant"
179 c_variant :: C_UUID -> CInt
199 c_variant :: C_UUID -> CInt
200+
201+-- Other
202+
203+foreign import ccall unsafe "memcpy"
204+ memcpy :: Ptr a -> Ptr b -> CSize -> IO ()
uuid.cabal+2−4
@@ -15,6 +15,7 @@ Description:
15 The library libuuid is available as a part of e2fsprogs:
15 The library libuuid is available as a part of e2fsprogs:
16 <http://e2fsprogs.sourceforge.net/>.
16 <http://e2fsprogs.sourceforge.net/>.
17
17
18+
18 This library is useful for creating, comparing, parsing and
19 This library is useful for creating, comparing, parsing and
19 printing Universally Unique Identifiers.
20 printing Universally Unique Identifiers.
20 See <http://en.wikipedia.org/wiki/UUID> for the general idea.
21 See <http://en.wikipedia.org/wiki/UUID> for the general idea.
@@ -28,7 +29,4 @@ Library
28
29
29 Extensions: ForeignFunctionInterface
30 Extensions: ForeignFunctionInterface
30
31
31− Extra-Libraries: uuid
32+ Extra-Libraries: uuid
32−
33−
34−