Modeling Services > Basic Features > Dictionaries > Defining a Dictionary
 
Defining a Dictionary
A dictionary is an instance of the class template IlsDictionary. This class template takes the type of the objects to be stored in the dictionary as a single argument. You declare the dictionary of a class Airport in the following manner:
typedef IlsDictionary<Airport> AirportDictionary;
As a general rule, the argument passed to the class template IlsDictionary must directly or transitively derive from IlsEntity. Derivation must be public.
class Airport:
public IlsEntity
{
public:
   Airport(IlsIdentifier id): IlsEntity(id){
      _dictionary<<this;
   }
private:
   static IlsDictionary<Airport> _dictionary;
};
The class IlsEntity allows you to directly create objects with an identifier, because it contains the IlsEntity::getIdentifier member function by default. However, if you want to store instances of a class that derives from IlsObject in a dictionary, you must add the member function getIdentifier to that subclass.
This function has the following signature:
IlsIdentifier getIdentifier();
In this case, the class Airport could be defined like this:
class Airport:
public IlsObject
{
public:
   Airport(IlsIdentifier id): identifier(id){
      _dictionary<<this;
   }
   IlsIdentifier getIdentifier() const {return identifier;}
private:
   IlsIdentifier identifier;
   static IlsDictionary<Airport> _dictionary;
};
Generally, a dictionary is global or static to a class.

Version 5.8
Copyright © 2014, Rogue Wave Software, Inc. All Rights Reserved.