Sunday, October 6, 2013

Information Template Dictionary

The numeric and string constant dictionaries have slightly different requirements and so will be handled separately.  Both of these dictionaries will have additional information beyond what is in the base dictionary class, namely the constant values themselves.  For both of these dictionaries, this additional information will be stored in a QVector.  At run-time, the constant data for the QVector will be obtained as an array.  This will allow for fast access of the constant values by the indexes stored in the program code.

The Qt QList and QVector classes are almost identical and both can access elements by index.  The big difference is that the elements in the QVector are guaranteed to be stored in consecutive memory addresses.  This allows the data to be access like a C/C++ array.  If this consecutive access is not required, then the QList class should be used, though the only advantage appears to be in the time it takes to prepend items to the beginning of the list (QList is faster).


An information dictionary template class was created based on the dictionary class, which adds a vector of generic information class elements.  The add routine was overloaded, which first calls the base dictionary add routine.  The base dictionary add routine was modified from just returning whether a new item was added or not, to returning the status of whether a new entry was appended to the end of the list, an freed entry was reused, or if the entry already exists.  This status is then used to either append a new information element, replace an information element, or do nothing if the item already exists.

The QVector class was chosen over the QList class for the information so that an array can be used at run-time for constants.  There will be other dictionaries with information that won't have this run-time array requirement, but as noted above, the only disadvantage to using QVector instead of QList is prepending to the beginning of the list, and that operation will not be needed.

One requirement for the generic information class is that it must have a constructor that takes a pointer to a token.  For constants, the information is obtained from the token.  Eventually for other dictionaries, other information beyond what is contained in a token may be needed, at which time, additional argument(s) will be added to the constructors and to the information dictionary add routine, which now just takes a pointer to a token.

[commit 6ffb6901a1]

No comments:

Post a Comment

All comments and feedback welcomed, whether positive or negative.
(Anonymous comments are allowed, but comments with URL links or unrelated comments will be removed.)