Module eqc_c_enum

This module provides a tool for generating conversion functions for enum-like C types.

Copyright © Quviq AB, 2013-2015

Version: 1.36.1

Description

This module provides a tool for generating conversion functions for enum-like C types.

Example use: given the C header file answer.h:
 typedef int Answer;
 #define YES 1
 #define NO  0
we can define
 -module(enum_test).
 -compile(export_all).
 start() ->
   eqc_c_enum:load(answer_enum, ["answer.h"], {"Answer", ['YES', 'NO']}),
   eqc_c:start(answer, [{c_src, "answer.h"}, {casts, answer_enum}]).
We can then work with YES and NO as values of type Answer:
 1> enum_test:start().
 ok
 2> Ans = eqc_c:alloc("Answer", 'YES').
 {ptr,"Answer",140243361595616}
 3> eqc_c:deref(Ans).
 'YES'

Function Index

load/3Equivalent to load(Module, Includes, TypeSpecs, []).
load/4Generate and load a module Module suitable for use as a casts module with eqc_c:start/2.
load_module/2Equivalent to load_module(Module, Callback, []).
load_module/3Given a callback module a type_cast module is generated.

Function Details

load/3

load(Module::atom(), Includes::[string()], TypeSpecs) -> ok

Equivalent to load(Module, Includes, TypeSpecs, []).

load/4

load(Module::atom(), Includes::[string()], TypeSpecs, Options::proplists:proplist()) -> ok

Generate and load a module Module suitable for use as a casts module with eqc_c:start/2. Each TypeSpec in TypeSpecs is a tuple, {Type, Tags}. The function creates the functions to_c/2 and from_c/2 converting between C integers and the atoms given in Tags. For each tag there should be a #define in the include files Includes providing its value. If Tags is a list of pairs, the first component of each pair specifies the name of the #define and the second component the desired Erlang value.

The Options are passed as options to eqc_c:start/2 when starting the C program to retrieve the tag values.

load_module/2

load_module(Module::atom(), Callback::atom()) -> ok

Equivalent to load_module(Module, Callback, []).

load_module/3

load_module(Module::atom(), Callback::atom(), Options::proplists:proplist()) -> ok

Given a callback module a type_cast module is generated. A callback module contains one obligatory function includes/0, which should return all C header files with #define's in it that one wants to represent symbolically in Erlang tests.

All other 0-ary functions in the callback module are considered type definitions for the symbols. For example, a function

         'ReturnType'() -> [ 'OK', ''NOT_OK' ].
       
Defines a type with two values which are defined in one of the specified header files. This allows the user to use 'OK' and 'NOT_OK' in the Erlang test specifications, instead of hard-coding their actual values.

The provided Module is used by eqc_c as type cast module and should be added in the compiler options to eqc_c:start/2 as {casts,Module}


Generated by EDoc, Sep 8 2015, 11:11:10.