EnglishРусский  

   ..

   arr.g

   arrstr.g

   arrustr.g

   buf.g

   collection.g

   console.g

   fcopy.g

   ffind.g

   file.g

   hash.g

   math.g

   process.g

   search.g

   stack.g

   stdlib.g

   str.g

   stradv.g

   strfile.g

   system.g

   ustr.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\stdlib\collection.g
  1 /******************************************************************************
  2 *
  3 * Copyright (C) 2004-2007, 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 /*-----------------------------------------------------------------------------
 15 * Id: collections L "Collection"
 16 * 
 17 * Summary: Collection. You can use variables of the #b(collection)
 18    type for working with collections. Collection is an object which can 
 19    contains objects of different types. The #b(collection) type is
 20    inherited from the #b(buf) type. So, you can also use 
 21    #a(buffer, methods of the buf type).
 22 *
 23 * List: *#lng/opers#,collection_oplen,collection_opind,collection_opeq,
 24         collection_opadd,collection_opsum,collection_opfor,
 25         *#lng/methods#,collection_append,collection_clear,collection_gettype,
 26         collection_ptr,
 27         *#lng/types#,collection_colitem
 28 * 
 29 -----------------------------------------------------------------------------*/
 30 
 31 /*-----------------------------------------------------------------------------
 32 * Id: collection_opeq F4
 33 * 
 34 * Summary: Collection copying.
 35 *  
 36 -----------------------------------------------------------------------------*/
 37 
 38 operator collection =( collection left, collection right )
 39 {
 40    left->buf = right->buf
 41    left.count = right.count
 42    return left
 43 }
 44 
 45 /*-----------------------------------------------------------------------------
 46 * Id: collection_opadd F4
 47 * 
 48 * Summary: Appends elements of a collection to another collection.
 49 *  
 50 -----------------------------------------------------------------------------*/
 51 
 52 operator collection +=( collection left, collection right )
 53 {
 54    left->buf += right->buf
 55    left.count += right.count
 56    return left
 57 }
 58 
 59 /*-----------------------------------------------------------------------------
 60 * Id: collection_opsum F4
 61 * 
 62 * Summary: Putting two collections together and creating a resulting 
 63            collection.
 64 *
 65 * Return: The new result collection.            
 66 *  
 67 -----------------------------------------------------------------------------*/
 68 
 69 operator collection +<result> ( collection left, collection right )
 70 {
 71    result = left
 72    result += right     
 73 }
 74 
 75 /*-----------------------------------------------------------------------------
 76 * Id: collection_clear F3
 77 * 
 78 * Summary: Delete all items from the collection. 
 79 *
 80 * Return: #lng/retobj#
 81 *
 82 -----------------------------------------------------------------------------*/
 83 
 84 method collection collection.clear()
 85 {
 86    this->buf.clear()
 87    this.count = 0
 88    return this
 89 }
 90 
 91 /*-----------------------------------------------------------------------------
 92 * Id: collection_append F2
 93 * 
 94 * Summary: Append an object or a numeric value to the collection.
 95 *
 96 * Params: value - The value of the 32-bit number or the pointer to 64-bit /
 97                   number or the ponter to any other object.
 98           itype - The type of the appending value.
 99 *
100 * Return: An index of the appended item.
101 *
102 -----------------------------------------------------------------------------*/
103 
104 method uint collection.append( uint value, uint itype )
105 {
106    this.count++;
107    this->buf += itype
108    if ( itype >= double && itype <= ulong )
109    {
110       this.flag |= 0x01;
111       this->buf += value->ulong
112    }
113    else : this->buf += value
114    return this.count - 1
115 }
116 
117 /*-----------------------------------------------------------------------------
118 * Id: collection_colitem T 
119 * 
120 * Summary: The structure is used in #a(collection_opfor, #b[foreach] ) 
121            operator. The variable of the foreach operator has this type.
122 *
123 * Title: colitem
124 *
125 -----------------------------------------------------------------------------*/
126 
127 type colitem {
128    uint oftype     // The type of the item. 
129    uint val        // The value of the item. 
130    uint hival      // The hi-uint of the value. It is used if the value is  /
131                    // 64-bit.
132    uint ptr        // The pointer to the value.
133 }
134 
135 /*-----------------------------------------------------------------------------
136 ** Id: collection_opfor F5
137 *
138 * Summary: Foreach operator. You can use #b(foreach) operator to look over 
139            items of the collection. The variable #b(var) has
140            #a(collection_colitem, colitem) type.
141 *  
142 * Title: foreach var,collection
143 *
144 * Define: foreach variable,collection {...}
145 * 
146 -----------------------------------------------------------------------------*/
147 
148 type colfordata <inherit=fordata>{
149    uint pcur
150    colitem item
151 }
152 
153 method uint collection.eof( colfordata fd )
154 {
155    return ?( fd.icur < *this, 0,  1 )
156 }
157 
158 method colitem collection.next( colfordata fd )
159 {
160    fd.icur++
161    
162    fd.item.oftype = fd.pcur->uint
163    fd.pcur += 4
164    fd.item.ptr = fd.pcur      
165    if fd.item.oftype == double || fd.item.oftype == long || fd.item.oftype == ulong
166    {
167       (&fd.item.val)->ulong = fd.pcur->ulong 
168       fd.pcur += 8
169    } 
170    else : fd.pcur +=4   
171    
172    fd.item.val = fd.item.ptr->uint 
173    return fd.item
174 }
175 
176 method colitem collection.first( colfordata fd )
177 {
178    fd.icur = -1
179    fd.pcur = .data
180    return .next( fd )
181 }
182 
183 /*Тип collection является встроенным
184 Cтруктура collection включена в компилятор
185 type collection <inherit=buf>
186 {       
187    uint      count;   // The number of items
188    uint      flag;
189 }
190 В компилятор включены следующее методы и операции:
191 uint collection.gettype( uint index )
192 uint collection.getptr( uint index )
193 */
194