Safe Haskell | None |
---|---|
Language | Haskell2010 |
Runtime support for generated Haskell bindings.
- newtype CBool = CBool CUChar
- newtype CUChar :: * = CUChar Word8
- coerceIntegral :: (Integral a, Integral b, Typeable a, Typeable b, Show a) => a -> b
- class CppPtr this where
- class Deletable this where
- class Assignable cppType value where
- class Encodable cppPtrType hsType | cppPtrType -> hsType where
- encodeAs :: Encodable cppPtrType hsType => cppPtrType -> hsType -> IO cppPtrType
- class Decodable cppPtrType hsType | cppPtrType -> hsType where
- decodeAndDelete :: (Deletable cppPtrType, Decodable cppPtrType hsType) => cppPtrType -> IO hsType
- withCppObj :: (Deletable cppPtrType, Encodable cppPtrType hsType) => hsType -> (cppPtrType -> IO a) -> IO a
- withScopedPtr :: Deletable cppPtrType => IO cppPtrType -> (cppPtrType -> IO a) -> IO a
- class HasContents c e | c -> e where
- toContents :: c -> IO [e]
- class FromContents c e | c -> e where
- fromContents :: [e] -> IO c
- newtype CCallback fnHsCType = CCallback (Ptr ())
- freeHaskellFunPtrFunPtr :: FunPtr (FunPtr (IO ()) -> IO ())
Primitive types
A numeric type representing a C++ boolean.
newtype CUChar :: *
Haskell type representing the C unsigned char
type.
coerceIntegral :: (Integral a, Integral b, Typeable a, Typeable b, Show a) => a -> b Source
Converts between integral types by going from a
to b
, and also
round-tripping the b
value back to an a
value. If the two a
values
don't match, then an error is signalled.
Objects
class CppPtr this where Source
An instance of this class represents a pointer to a C++ object. All C++
classes bound by Hoppy have instances of CppPtr
.
class Deletable this where Source
C++ values that can be deleted. All C++ classes bound by Hoppy have
instances of Deletable
.
class Assignable cppType value where Source
A typeclass for references to C++ values that can be assigned to. This
includes raw pointers (Ptr
), as well as pointers to object types that have
an assignment operator (see
Assignable
).
assign :: cppType -> value -> IO () Source
assign x v
assigns the value v
at the location pointed to by x
.
Storable a => Assignable (Ptr a) a Source | |
Assignable (Ptr CBool) Bool Source |
class Encodable cppPtrType hsType | cppPtrType -> hsType where Source
For a C++ class that also has a native Haskell representation (e.g. value
types such as std::string
), this typeclass allows converting a Haskell
value into a C++ object on the heap. Encoding to both the non-const and
const objects is supported.
Because the functional dependency points in the direction it does, calls of
the form
are ambiguously typed, so encode
valueencodeAs
is provided to
resolve the ambiguity.
Prefer withCppObj
over calling encode
directly, to manage the lifetime of
the object.
See also Decodable
.
class Decodable cppPtrType hsType | cppPtrType -> hsType where Source
A typeclass for converting references to C++ values into Haskell values.
What this means depends on the type of C++ value. Pointers to numeric types
and to other pointers (i.e.
) are decodable by peeking at
the value.Ptr
(Ptr
...)
For a C++ class that also has a native Haskell representation (e.g. value
types such as std::string
), this typeclass allows converting a C++ heap
object into a Haskell value based on the defined conversion. Decoding from
both the non-const and const objects is supported.
See also Encodable
.
Decodable (Ptr CChar) CChar Source | |
Decodable (Ptr CUChar) CUChar Source | |
Decodable (Ptr CShort) CShort Source | |
Decodable (Ptr CUShort) CUShort Source | |
Decodable (Ptr CInt) CInt Source | |
Decodable (Ptr CUInt) CUInt Source | |
Decodable (Ptr CLong) CLong Source | |
Decodable (Ptr CULong) CULong Source | |
Decodable (Ptr CLLong) CLLong Source | |
Decodable (Ptr CULLong) CULLong Source | |
Decodable (Ptr CFloat) CFloat Source | |
Decodable (Ptr CDouble) CDouble Source | |
Decodable (Ptr CSize) CSize Source | |
Decodable (Ptr CBool) Bool Source | |
Decodable (Ptr (Ptr a)) (Ptr a) Source |
decodeAndDelete :: (Deletable cppPtrType, Decodable cppPtrType hsType) => cppPtrType -> IO hsType Source
withCppObj :: (Deletable cppPtrType, Encodable cppPtrType hsType) => hsType -> (cppPtrType -> IO a) -> IO a Source
Temporarily encodes the Haskell value into a C++ object and passes it to the given function. When the function finishes, the C++ object is deleted.
withScopedPtr :: Deletable cppPtrType => IO cppPtrType -> (cppPtrType -> IO a) -> IO a Source
withScopedPtr m f
runs m
to get a pointer, which is given to f
to
execute. When f
finishes, the pointer is deleted.
Containers
class HasContents c e | c -> e where Source
Containers whose contents can be convered to a list.
For a container Cont
holding values with C-side type Foo
and Haskell-side
type Bar
, if the container uses ConvertPtr
then the following instances are recommended:
instance HasContents ContConst FooConst instance HasContents Cont Foo
If the container uses ConvertValue
then the
following instances are recommended:
instance HasContents ContConst Bar instance HasContents Cont Bar
toContents :: c -> IO [e] Source
Extracts the contents of a container, returning the elements in a list.
class FromContents c e | c -> e where Source
Containers that can be created from a list.
For a container Cont
holding values with C-side type Foo
and Haskell-side
type Bar
, if the container uses ConvertPtr
then the following instance is recommended:
instance FromContents Cont Foo
If the container uses ConvertValue
then the
following instance is recommended:
instance HasContents Cont Bar
No instances for ContConst
are needed because it is easy enough to cast the
resulting collection to a const pointer.
fromContents :: [e] -> IO c Source
Creates and returns a new container holding the given elements.
Internal
newtype CCallback fnHsCType Source
Internal type that represents a pointer to a C++ callback object (callback impl object, specifically).
freeHaskellFunPtrFunPtr :: FunPtr (FunPtr (IO ()) -> IO ()) Source
A global constant function pointer that points to freeHaskellFunPtr
.