Table of contents
1.
Introduction
2.
ATL Collections
2.1.
What it Gives
3.
ATL Collection Classes
3.1.
Types of Collection Classes
3.1.1.
Small Collection Classes
3.1.2.
General Purpose Collection Classes
3.1.3.
Specialized Collection Classes
3.2.
Choosing a Collection Class
4.
Enumerator
5.
Design Principles for Collection and Enumerator Interfaces
6.
Frequently Asked Questions
6.1.
Where can I find the Active Template Library?
6.2.
What are ActiveX controls?
6.3.
How do I create an ATL file using project wizard?
7.
Conclusion
Last Updated: Mar 27, 2024
Medium

ATL Collection, Enumerators and its Classes

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Wouldn't it be awesome if we could see different bits and pieces of things that we work with at the same place? It would be just like a toolbox with all the assorted tools that we could use. ATL collection and enumerators are somewhat like that, and they give us an interface for relatable items. Let us find out more about them in the article.

ATL Collection, Enumerators and its Classes

ATL Collections

A collection is a COM object which offers an interface for accessing a collection of data elements. These are either raw data or objects. A "collection interface" is an interface that adheres to the standards for giving access to a set or a group of objects.

What it Gives

Collection interfaces should, at the very least, include a Count property. This COunt property should give the number of items in the collection. It should also offer an Item property that gives an item from the collection based on an index. Finally, it should give a _NewEnum property. It is something which gives an enumerator for the collection. Collection interfaces can optionally offer Add and Remove methods for inserting or removing objects from the collection. They can also give a Clear method for removing all items.

ATL Collection Classes

ATL includes a plethora of classes for storing and accessing data. The class we choose is determined by various factors, they include:

  • The amount of data that must be stored.
  • Efficiency versus performance in data access.
  • The capacity to access data via an index or a key.
  • The manner in which the data is organised.
  • Individual or Personal preference.

Types of Collection Classes

Let us take a look at the ATL Collection Classes in brief.  

Small Collection Classes

For dealing with small quantities of items, ATL provides the array classes that we can see below. These classes, however, are limited and intended for internal ATL usage only. It is not advised that users include them in their programs.

Small Collection Classes Table

General Purpose Collection Classes

As general-purpose collection classes, the classes that we see below implement maps, arrays and lists.

General Purpose Collection Classes Table

We should take note that, when utilised in debug builds, these classes will catch many code problems; however, for performance reasons, these checks will not be performed in retail builds.

Specialized Collection Classes

Memory pointers and interface pointers are managed using more specialised collection classes. Examples and purposes of such classes are shown below.

Specialized Collection Classes Table

Choosing a Collection Class

Each of the possible collection classes has different performance characteristics. Let us take a look at them. We will also see them described in the form of a table below.

  • Taking a look at the table below, we can see that Columns 2 and 3 specify the ordering and access features of each class. The term "ordered" in the table denotes the order in which items are inserted and deleted. This defines their order in the collection. This does not imply that the items are sorted based on their contents. The term "indexed" denotes that the objects in the collection, like elements in a regular array, can be retrieved using an integer index.
  • Let us take a look at Columns 4 and 5. We can see that they describe the performance of each class. Insertion speed may be more significant in applications that demand many insertions into the collection; lookup speed may be more critical in other applications.
  • Further, Column 6 specifies whether duplicate elements are allowed for each shape or not.

Collection Shape Features Table

Source: Microsoft

Enumerator

An enumerator is a COM object which offers an interface for iterating through elements in a collection. Enumerator interfaces enable serial access to collection elements. This is done through four methods: Next, Skip, Reset, and Clone.

ATL Collection and Enumerator Classes Table

Design Principles for Collection and Enumerator Interfaces

Each sort of interface has its own set of design principles:

  • A collection interface gives clients random access to a single item in the collection. This is done through the Item method. It informs the clients know of the number of items in the collection through the Count property. This also usually allows clients to add and remove items.
  • An enumerator interface allows serial access to numerous items in a collection. However but it does not allow the client to determine the number of items in the collection. It is until the enumerator stops returning items. It also does not allow the client to add or remove items.

Each interface type has a specific purpose in providing access to the elements of a collection.

Frequently Asked Questions

Where can I find the Active Template Library?

We can get it in Microsoft Visual Studio. Suppose you are someone who does not have Visual Studio. In that case, you can get the ATL libraries from one of the Visual C++ Redistributable packages that Microsoft offers.

What are ActiveX controls?

ActiveX controls are computer component objects created by Microsoft. They allow applications to execute certain tasks, such as showing a calendar or playing a movie. An ActiveX control is a short programme that other applications can utilise to offer the same functionality without having to do any additional programming or development.

How do I create an ATL file using project wizard?

To create an ATL file using the project wizard, we must go to the main menu in Visual Studio first. There we will go to Choose File > New > Project. To open the ATL Project Wizard, we will click the ATL Project icon in the Templates window. We can define your application settings using the ATL Project Wizard's Application Settings page.

Conclusion

In the article, we read about the ATL collection and enumerators. We saw what it gives and took a read about its classes. We took looks at various elements related to that through simple tables. Refer to our courses and explore Coding Ninjas Studio to find more exciting stuff. You can also look into the interview experiences and solve different problems. Look into our Guided paths, test series, libraries and resources to know more.

Thank You

Happy Coding!

Live masterclass