The next step will be to use smart pointers for RPN list pointers. In keeping with the change to STL classes, the RPN list will be changed from a QList to a std::list. Even though QList is like std::vector internally (an allocated array), a double linked list container is more appropriate because there is one instance so far (the INPUT command) where RPN items are inserted into the list. Inserting into an array requires moving all the elements from the insertion point.
While reviewing the code for these changes, it was noticed that the index member of the RPN item was only being used for test output. This index is set when an RPN item is appended to the list. If an item is inserted into the list, the index of every item after the inserted item needs to be incremented. This index is only output on attached items as a check to make sure the correct item is attached.
Current, attached RPN items always occur before the item that are attached to, which means the indexes could be assigned to an item as it is converted to text. Therefore the index of each item will be assigned and temporarily held in an unordered map (RPN item pointer to index) instead of assigning an index when the item is appended (and incremented later for inserts). The index was removed from the RPN Item class.
The text function of the RPN List class was modified to handle the conversion of each item to text using access functions of the RPN Item class so that the indexes can be added (from the temporary map) instead of calling the text function of the RPN item (which would not have the temporary indexes). Since the text function of the RPN Item class is no longer needed, it was removed. Also, the with indexes option argument was not being utilized and so this feature was also removed.
The text function was also modified to build the text of the RPN List into a standard string stream (std::stringstream, which works like an output stream but puts the result into a string). This is easier for building a string than using the standard string which is feature limited. For now, when the final standard string is obtained from the string steam, it is converted to a QString (since that it how the caller uses it, for now). Also, the text from the token needs to be converted from a QString to a standard string before adding to the string stream.
[branch cpp11 commit da4fcfbb23]
Wednesday, September 3, 2014
Subscribe to:
Post Comments (Atom)
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.)