1 /******************************************************************************
2 *
3 * Copyright (C) 2009, The Gentee Group. All rights reserved.
4 * This file is part of the Gentee open source project - http://www.gentee.com.
5 *
6 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE GENTEE LICENSE ("AGREEMENT").
7 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS
8 * ACCEPTANCE OF THE AGREEMENT.
9 *
10 * Author: Alexey Krivonogov ( gentee )
11 *
12 ******************************************************************************/
13
14 #include "ged.h"
15
16 uint ged_findfield( pged pdb, pubyte name )
17 {
18 uint i, len = mem_len( name ) + 1;
19
20 for ( i = 0; i< pdb->head->numfields; i++ )
21 {
22 if ( !mem_cmpign( pdb->fields[ i ].name, name, len ))
23 return i + 1;
24 }
25 return 0;
26 }
27
28 pgedfield ged_field( pged pdb, uint ind )
29 {
30 return pdb->fields + ind;
31 }
32
33 pubyte ged_fieldptr( pged pdb, uint ind, uint ifield )
34 {
35 if ( !ind )
36 return buf_ptr( PRECORD );
37 return pdb->db + ( ind - 1 ) * pdb->fsize + pdb->fields[ ifield ].offset;
38 }
39
40 uint ged_getuint( pged pdb, uint ind, uint ifield )
41 {
42 puint pval = ( puint )ged_fieldptr( pdb, ind, ifield );
43
44 if ( pdb->fields[ ifield ].ftype <= FT_UBYTE )
45 return *( pubyte )pval;
46 if ( pdb->fields[ ifield ].ftype <= FT_USHORT )
47 return *( pushort )pval;
48 return *pval;
49 }
50
51 long64 ged_getlong( pged pdb, uint ind, uint ifield )
52 {
53 return *( plong64 )ged_fieldptr( pdb, ind, ifield );
54 }
55
56 float ged_getfloat( pged pdb, uint ind, uint ifield )
57 {
58 return *( float* )ged_fieldptr( pdb, ind, ifield );
59 }
60
61 double ged_getdouble( pged pdb, uint ind, uint ifield )
62 {
63 return *( double* )ged_fieldptr( pdb, ind, ifield );
64 }
65