Next: , Previous: Music_Node Type Definitions, Up: music node class definition



7.5.5 Functions

— Function: void set_bells (const unsigned int &b);

This function is used to set the number of bells that will be in the rows to be matched against. This provides a way for the algorithms to know when they are finished processing the expressions or row.

— Function: void add (const music_details &md, const unsigned int &i, const unsigned int &key, const unsigned int &pos);

This function is used to add the supplied expression (md), to the tree. The location in the expression to look at is supplied by i, the key is the reference number that the music class stores the md expression against, and the pos is the number of bells deep we are in the tree.

Depending on the item in the expression at index i, the algorithm will do different things, normally, it will call the add_to_subtree(...) function which in turn will usually call this function again; sometimes it will call itself (in the case of a '*') to move along the current expression without necessarily adding it to a subtree. Hence, the add(...) function is an iterative one.

— Function: void add_to_subtree (const unsigned int &place, const music_details &md, const unsigned int &i, const unsigned int &key, const unsigned int &pos, const bool &process_star);

This private function is used to create a branch (if required) and add an expression to a branch of a node. If it cannot allocate memory for the new node, it will either throw a memory_error exception (if enabled), or it will simply return without going any further.

The place parameter provides the branch number (= bell) to create and add to, the process_star parameter is used to indicate if the number of *s remaining should be processed or ignored. The rest of the parameters are as for the add(...) function.

— Function: void match (const row &r, const unsigned int &pos, vector<music_details> &results, const EStroke &stroke);

This function is iterative and is used to match the expressions stored to a row, r. If a node is found to have an expression ending there, the number of counts for that expression are incremented according to the specified stroke. The pos parameter is used to specify the current position in the row r, and the results parameter is the expressions for which the indexes have previously been stored, and against which the count should be incremented as appropriate.