Friday, February 13, 2015

Program – Dictionary Pointers

The individual dictionary pointers in the program model class were replaced with a standard array of dictionary pointers.  The standard array was chosen (over a map) because it is the most efficient.  The standard unique pointer was used for the dictionary pointers so no extra work is needed to clean up the dictionaries when a program model instance is deleted.

To index the dictionary pointer array, a Operand Type plain enumeration was defined where its enumerators are used as indexes.  A plain enumeration was chosen since is enumerator can be used as integer indexes whereas a C++11 enumeration does not without casting.  The enumerators include Rem, Constant Number, Constant String, Variable Double, Variable Integer and Variable String for each of the current dictionaries.

After the dictionary enumerators, there is a Number Of enumerator that is used to dimension the dictionary pointers array.  It is also used as the limit for the loop that clears the dictionaries in the program model destructor.  There is a No enumerator at the end of the list that is used for codes that do not have operands.  The default enumerator (with a value of zero) would be used for this purpose, but the first enumerator needs to be used to index the first dictionary.

The dictionary pointer array contains the base dictionary class pointer.  The constant number and string dictionaries were Info Dictionary class pointers, but with the last change, the base class pointer can be used for these dictionaries since only the base class virtual functions are used at the moment.  Dynamic casting will eventually be needed to get to the information of these classes.

However,  there was one issue where the destructor of the constant string dictionary was no longer being called (to free the string constants).  This was resolved by making the Dictionary base class destructor a virtual function, which causes the destructors of the derived classes to be called.

Each of the program model dictionary access functions were changed to use the new array and operand type enumerators.  These functions will shortly be replaced with a single generic dictionary access functions taking an operand type argument (for the effort of reducing the number of functions).

[branch table commit 61d82727f8]