EnglishРусский  

   ..

   gt.g

   gtitem.g

   gtload.g

   gtsave.g

   lexgt.g

   lexgtdo.g

The project is closed! You can look at a new scripting language. It is available on GitHub.
Also, try our open source cross-platform automation software.

Ads

Installer and installation software
Commercial and Freeware installers.

source\lib\gt\gtitem.g
  1 /******************************************************************************
  2 *
  3 * Copyright (C) 2006, 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 * ID: gtitem 18.10.06 0.0.A.
 11 *
 12 * Author: Alexey Krivonogov ( gentee )
 13 *
 14 ******************************************************************************/
 15 
 16 method treeitem gtitem.gettreeitem
 17 {
 18    return ( &this - sizeof( treeitem ))->treeitem
 19 }
 20 
 21 method uint gtitem.moveup()
 22 {
 23    uint prev cur
 24    
 25    cur as this.gettreeitem()
 26    prev as cur.getprev()
 27    
 28    if &prev
 29    {
 30       prev as prev.getprev()
 31       return cur.move( prev )
 32    }
 33    return 0
 34 }
 35 
 36 method uint gtitem.movedown()
 37 {
 38    uint next cur
 39    
 40    cur as this.gettreeitem()
 41    next as cur.getnext()
 42    
 43    if &next : return cur.move( next )
 44    return 0
 45 }
 46 
 47 method gtitem gtitem.parent
 48 {
 49    uint parent
 50    
 51    parent as this.gettreeitem().parent()
 52    
 53    return ?( parent,  parent.data()->gtitem, 0->gtitem )
 54 }
 55 
 56 method str gtitem.getfullname( str result )
 57 {
 58    uint   data
 59    stack  tstack
 60    uint   ti = &this.gettreeitem()
 61 
 62    do {
 63       data = ti->treeitem.data()
 64       data as gtitem
 65       if *data.name : tstack.push()->uint = &data.name
 66 //      ti = ti->treeitem.parent      
 67    } while ti = ti->treeitem.parent
 68    
 69    result.clear()
 70 
 71    do {
 72       result += tstack.top()->uint->str
 73       result.appendch( $gt_CHDIV )
 74    } while tstack.pop()
 75 
 76    // Delete the last $gt_CHDIV
 77    result.setlen( *result - 1 )
 78    return result
 79 }
 80 
 81 method uint gtitem.haschild 
 82 {
 83    return ?( this.gettreeitem().child, 1, 0 )
 84 }
 85 
 86 method uint gtitem.isroot
 87 {
 88    return this.gettreeitem().isroot()
 89 }
 90 
 91 method uint gtitem.find( str attr )
 92 {
 93    uint  i
 94    
 95    fornum i = 0, *this.attrib
 96    {
 97       if this.attrib[ i ].name %== attr : return i + 1
 98    }
 99    return 0
100 }
101 
102 method uint gtitem.delattrib( str attrib )
103 {
104    uint id
105    
106    if !*attrib : return 0
107    
108    if id = this.find( attrib ) : this.attrib.del( id - 1 )
109    return 1
110 }
111 
112 method str gtitem.get( str attrib value )
113 {
114    uint id
115    
116    if id = this.find( attrib ) : value = this.attrib[ id - 1 ].value 
117    else : value.clear()
118 
119    return value       
120 }
121 
122 method str gtitem.get( str attrib )
123 {
124    uint id
125    
126    if id = this.find( attrib ) : return this.attrib[ id - 1 ].value 
127    return 0->str       
128 }
129 
130 
131 method uint gtitem.getuint( str attrib )
132 {
133    str  stemp
134    return uint( this.get( attrib, stemp ))
135 }
136 
137 method int gtitem.getint( str attrib )
138 {
139    str  stemp
140    return int( this.get( attrib, stemp ))
141 }
142 
143 operator uint *( gtitem gti )
144 {
145    return *gti.gettreeitem()   
146 }
147 
148 method  gtitem gtitem.lastchild
149 {
150    return this.gettreeitem().lastchild().data()->gtitem 
151 }
152 
153 method  gtitem gtitem.child
154 {
155    return this.gettreeitem().child().data()->gtitem 
156 }
157 
158 method  gtitem gtitem.getnext
159 {
160    return this.gettreeitem().getnext().data()->gtitem 
161 }
162 
163 method  gtitem gtitem.getprev
164 {
165    return this.gettreeitem().getprev().data()->gtitem 
166 }
167 
168 //-----------------------------------------------------------------
169 // For 'foreach' operator 
170 /*
171 type gtitems < index = gtitem > 
172 {        
173    uint   parent
174    uint   cur
175 } 
176 */
177 //-----------------------------------------------------------------
178 /*
179 method  gtitems  gtitem.items( gtitems items )
180 {
181    items.parent = &this
182    items.cur = 0
183    return items
184 }
185 */
186 method uint gtitem.eof( fordata tfd )
187 {
188    return !tfd.icur
189 }
190 
191 method uint gtitem.next( fordata tfd )
192 {
193    if !tfd.icur : return 0
194 
195    tfd.icur = tfd.icur->treeitem.next   
196    return tfd.icur->treeitem.data()
197 }
198 
199 method uint gtitem.first( fordata tfd )
200 {
201    tfd.icur = this.gettreeitem().child
202    return tfd.icur->treeitem.data()
203 }
204 
205 method gtitem.delnames
206 {
207    str name
208    
209    foreach child, this : child.delnames()   
210    .getfullname( name )   
211    .maingt->gt.names.del( name )
212 }
213 
214 method gtitem.setnames( str name )
215 {
216 //   .getfullname( name )
217    .maingt->gt.names[ name ] = &this.gettreeitem()   
218    foreach child, this
219    { 
220       str stemp 
221       ( stemp = name ).appendch( $gt_CHDIV ) += child.name
222       child.setnames( stemp )
223    }
224 }
225 
226 method uint gtitem.move( gtitem target, uint flag )
227 {
228    uint ret
229    str  name
230 
231    .delnames()   
232    ret = this.gettreeitem().move( ?( &target < 2, this.parent().gettreeitem(), 
233                                   target.gettreeitem()), flag )
234    
235    .setnames( .getfullname( name ) )   
236    return ret
237 }
238 
239 method uint gtitem.move( gtitem after )
240 {
241    uint flag
242    
243    if !&after : flag = $TREE_FIRST
244    elif &after == 1 : flag = $TREE_LAST
245    else : flag = $TREE_AFTER
246    return this.move( after, flag )
247 }
248 
249 //-----------------------------------------------------------------
250