@mlightcad/data-model
Version:
The data-model package provides the core classes for interacting with AutoCAD's database and entities. This package mimics AutoCAD ObjectARX's AcDb (Database) classes and implements the drawing database structure that AutoCAD developers are familiar with.
84 lines • 2.52 kB
JavaScript
/**
* Iterator used for iterating over database objects.
*
* This class provides an iterator interface for traversing collections
* of database objects. It implements both IterableIterator and provides
* additional methods for checking if more items are available.
*
* @template ResultType - The type of objects being iterated over
*/
var AcDbObjectIterator = /** @class */ (function () {
/**
* Creates a new AcDbObjectIterator instance.
*
* @param records - Array of objects to iterate over
*
* @example
* ```typescript
* const entities = [entity1, entity2, entity3];
* const iterator = new AcDbObjectIterator(entities);
* ```
*/
function AcDbObjectIterator(records) {
/** Current index in the iteration */
this.i = 0;
this._records = records;
this._keys = Array.from(records.keys());
}
Object.defineProperty(AcDbObjectIterator.prototype, "count", {
/**
* The number of items
*/
get: function () {
return this._records.size;
},
enumerable: false,
configurable: true
});
/**
* Converts values in the current iterator to one array
* @returns An array of values in the current iterator
*/
AcDbObjectIterator.prototype.toArray = function () {
return Array.from(this._records.values());
};
/**
* Returns the iterator itself, allowing it to be used in for...of loops.
*
* @returns This iterator instance
*
* @example
* ```typescript
* for (const entity of iterator) {
* console.log('Entity:', entity);
* }
* ```
*/
AcDbObjectIterator.prototype[Symbol.iterator] = function () {
return this;
};
/**
* Increments the iterator to the next entry.
*
* @returns Iterator result containing the next value or null if done
*
* @example
* ```typescript
* const result = iterator.next();
* if (!result.done) {
* console.log('Next item:', result.value);
* }
* ```
*/
AcDbObjectIterator.prototype.next = function () {
while (this.i < this._keys.length) {
var value = this._records.get(this._keys[this.i]);
this.i += 1;
return { value: value, done: false };
}
return { value: null, done: true };
};
return AcDbObjectIterator;
}());
export { AcDbObjectIterator };
//# sourceMappingURL=AcDbObjectIterator.js.map