我有一个描述的结构:
#define MAXVAL 20
#define ATOM_EL_LEN 6
#define NUM_H_ISOTOPES 3
typedef signed char S_CHAR;
typedef unsigned char U_CHAR;
typedef signed short S_SHORT;
typedef unsigned short U_SHORT;
typedef S_SHORT AT_NUM;
typedef struct tagInchiAtom {
/* atom coordinates */
double x;
double y;
double z;
/* connectivity */
AT_NUM neighbor[MAXVAL]; /* adjacency list: ordering numbers of */
/* the adjacent atoms, >= 0 */
S_CHAR bond_type[MAXVAL]; /* inchi_BondType */
/* 2D stereo */
S_CHAR bond_stereo[MAXVAL]; /* inchi_BondStereo2D; negative if the */
/* sharp end points to opposite atom */
/* other atom properties */
char elname[ATOM_EL_LEN]; /* zero-terminated chemical element name:*/
/* "H", "Si", etc. */
AT_NUM num_bonds; /* number of neighbors, bond types and bond*/
/* stereo in the adjacency list */
S_CHAR num_iso_H[NUM_H_ISOTOPES+1]; /* implicit hydrogen atoms */
/* [0]: number of implicit non-isotopic H
(exception: num_iso_H[0]=-1 means INCHI
adds implicit H automatically),
[1]: number of implicit isotopic 1H (protium),
[2]: number of implicit 2H (deuterium),
[3]: number of implicit 3H (tritium) */
AT_NUM isotopic_mass; /* 0 => non-isotopic; isotopic mass or */
/* ISOTOPIC_SHIFT_FLAG + mass - (average atomic mass) */
S_CHAR radical; /* inchi_Radical */
S_CHAR charge; /* positive or negative; 0 => no charge */
}inchi_Atom;
为了表示inchi_Atom
我做了下面的数据结构:
type ConnGraph = [CShort]
data INCHIAtom = INCHIAtom {atoms :: ConnGraph,
label :: CString,
bondTypes :: ConnGraph,
charge :: CSChar}
然后,我尝试Storable
为这个结构实现一个实例(使用hsc2hs
):
instance Storable INCHIAtom where
sizeOf _ = (#size inchi_Atom)
alignment _ = alignment (undefined :: CInt)
peek _ = error "peek is not implemented"
poke ptr (INCHIAtom atoms' label' bondType' charge') = do
(#poke inchi_Atom, x) ptr $ (0 ::CDouble)
(#poke inchi_Atom, y) ptr $ (0 ::CDouble)
(#poke inchi_Atom, z) ptr $ (0 ::CDouble)
(#poke inchi_Atom, neighbor) ptr $ atoms'
(#poke inchi_Atom, bond_type) ptr $ bondType'
--(#poke inchi_Atom, bond_stereo) $ nullPtr
(#poke inchi_Atom, elname) ptr $ label'
(#poke inchi_Atom, num_bonds) ptr $ (length atoms')
(#poke inchi_Atom, num_iso_H) ptr $ (0 :: CSChar)
(#poke inchi_Atom, isotopic_mass) ptr $ (0 :: CShort)
(#poke inchi_Atom, radical) ptr $ (0 :: CSChar)
(#poke inchi_Atom, charge) ptr $ charge'
我有几个问题。我没有办法如何Storable
实现ConnGraph
. 其次,我想将一个 NULL 指针指向bondStereo
,但是如果我取消注释,则会出现(#poke inchi_Atom, bond_stereo) $ nullPtr
编译错误。更多,它对alignment (undefined :: CInt)
我的数据结构是否正确?