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 method uint gedsel.open( ged pdb, collection sfilter sindex )
15 {
16 buf filter
17 buf index
18 uint i len
19 ustr utemp stemp
20
21 filter += 0
22 if !*sfilter : filter += $SF_ALL
23 fornum i, *sfilter
24 {
25 filter += sfilter[i]
26
27 if ( sfilter[i] & 0xffffff ) > $SF_ALL
28 {
29 uint ifield
30
31 if sfilter.gettype( ++i ) == str
32 {
33 ifield = pdb.findfield( sfilter[i]->str ) - 1
34 }
35 else : ifield = sfilter[i] - 1
36 if ifield >= pdb.fieldcount() : return 0
37 filter += ifield
38 uint pfield
39 pfield as pdb.field( ifield )
40 i++
41 switch pfield.ftype
42 {
43 case $FT_BYTE, $FT_SHORT, $FT_INT, $FT_FLOAT,$FT_UBYTE,
44 $FT_USHORT, $FT_UINT
45 {
46 if sfilter.gettype( i ) == str : filter += uint( sfilter[i] )
47 else : filter += sfilter[i]
48 }
49 case $FT_LONG, $FT_ULONG, $FT_DOUBLE
50 {
51 if sfilter.gettype( i ) == uint : filter += ulong( sfilter[i] )
52 else : filter += sfilter.ptr( i )->ulong
53 }
54 case $FT_STR
55 {
56 stemp.clear()
57
58 switch sfilter.gettype( i )
59 {
60 case str : stemp = sfilter[i]->str
61 case ustr : stemp = str( sfilter[i]->ustr )
62 }
63 len = min( 255, *stemp )
64 filter += len
65 filter.append( stemp.ptr(), len )
66 }
67 case $FT_USTR
68 {
69 utemp.clear()
70
71 switch sfilter.gettype( i )
72 {
73 case str : utemp = ustr( sfilter[i]->str )
74 case ustr : utemp = sfilter[i]->ustr
75 }
76 len = min( 255, *utemp )
77 filter += len
78 filter.append( utemp.ptr(), len << 1 )
79 }
80 }
81 }
82 }
83 // filter += $SF_END
84 filter.ptr()->uint = *filter - sizeof( uint )
85 index += 0
86 fornum i = 0, *sindex
87 {
88 uint ifield
89 if sindex.gettype( i ) == str
90 {
91 ifield = pdb.findfield( sindex[i]->str ) - 1
92 }
93 else : ifield = sindex[i] - 1
94 if ifield >= pdb.fieldcount() : return 0
95 index += ifield
96 index += sindex[ ++i ]
97 }
98 index.ptr()->uint = *index - sizeof( uint )
99 return ges_select( this, pdb, filter.ptr(), index.ptr() )
100 }
101
102 method uint gedsel.reverse()
103 {
104 return ges_reverse( this )
105 }
106
107 method uint gedsel.update()
108 {
109 return ges_update( this )
110 }
111
112 method uint gedsel.close()
113 {
114 return ges_close( this )
115 }
116
117 operator uint *( gedsel psel )
118 {
119 return psel.reccount
120 }
121
122 method uint gedsel.eof( fordata fd )
123 {
124 return ges_eof( this )
125 }
126
127 method uint gedsel.first( fordata fd )
128 {
129 return ges_goto( this, 1 )
130 }
131
132 method uint gedsel.next( fordata fd )
133 {
134 return ges_goto( this, this.reccur + 1 )
135 }
136