#ifndef ARRAY_DATA_ENGINE_H #define ARRAY_DATA_ENGINE_H // header files #include #include #include #include #include "StandardConstants.h" // data structures typedef struct StateDataStruct { char name[ STD_STR_LEN ]; int population; double growth; char majority; struct StateDataStruct *nextPtr; } StateDataType; typedef struct StateLLStruct { StateDataType *headPtr; } StateLLType; typedef enum { NOT_FOUND = -1, FOUND } FoundType; // Function prototypes /* Name: clearDataStructure Process: deallocates memory for the linked list data structure and encapsulated state data using helper function, returns NULL to calling function Function input/parameters: pointer to state linked list array (StateLLType *) Function output/parameters: none Function output/returned: NULL Device input/---: none Device output/---: none Dependencies: free, clearDataStructureHelper */ StateLLType *clearDataStructure( StateLLType *llPtr ); /* Name: copyDataList Process: deallocates destination linked list nodes if it is not empty, then if source list is not empty, copies all nodes from source list to destination list, if source list is empty, copied list will also be configured as empty Function input/parameters: pointer to source state data linked list type (const StateDataType *) Function output/parameters: pointer to destination state data array type (StateLLType *) Function output/returned: none Device input/---: none Device output/---: none Dependencies: clearDataStructureHelper, privateCreateNodeFromNode */ void copyDataList( StateLLType *dest, const StateLLType *src ); /* Name: createDataStructure Process: dynamically creates instance of state linked list type along with initializing the linked list within Function input/parameters: none Function output/parameters: none Function output/returned: pointer to state linked list type (StateLLType *) Device input/---: none Device output/---: none Dependencies: malloc, sizeof (C keyword) */ StateLLType *createDataStructure(); /* Name: deepCopyData Process: copies all members of a StateDataType node into another one Function input/parameters: state data type item (const StateDataType *) Function output/parameters: pointer to state data item (StateDataType *) Function output/returned: none Device input/---: none Device output/---: none Dependencies: privateCopyString */ void deepCopyData( StateDataType *dest, const StateDataType *src ); /* Name: displayData Process: displays comma-delimited data items in linked list if linked list is not empty, otherwise displays "Data not found - Display aborted", allows for subtitle to be added to "Display Data - " Function input/parameters: state linked list type (const StateLLType), subtitle (const char *) Function output/parameters: none Function output/returned: none Device input/---: none Device output/monitor: data displayed as specified Dependencies: printf, listIsEmpty */ void displayData( const StateLLType stateData, const char *subTitle ); /* Name: getItemAtIndex Process: checks for index within bounds, acquires and returns the value as a parameter, and returns true, otherwise sets data in parameter to empty and returns false Function input/parameters: state array type (const StateLLType), list index (int) Function output/parameters: value if found, otherwise, value set to empty (StateDataType *) Function output/returned: Boolean result of operation (bool) Device input/---: none Device output/---: none Dependencies: deepCopyData, setItemToEmpty */ bool getItemAtIndex( StateDataType *returnVal, const StateLLType stateData, int listIndex ); /* Name: getListSize Process: calculates the linked list size Function input/parameters: state array type (const StateLLType) Function output/parameters: none Function output/returned: size of the list (int) Device input/---: none Device output/---: none Dependencies: none */ int getListSize( const StateLLType stateData ); /* Name: insertItemAtIndex Process: checks for index in bounds, inserts item at index, returns true, if index not in bounds, returns false, must also insert item at index = size to all for appending data Function input/parameters: pointer to state array type (StateLLType *), StateDataType item to insert (const StateDataType), index for insertion (int) Function output/parameters: updated pointer to state array type (StateLLType *) Function output/returned: Boolean result of specified process (bool) Device input/---: none Device output/---: none Dependencies: privateCreateNodeFromNode */ bool insertItemAtIndex( StateLLType *stateData, StateDataType toBeInserted, int insertIndex ); /* Name: listIsEmpty Process: returns true if list is empty, false otherwise Function input/parameters: state linked list type (const StateLLType) Function output/parameters: none Function output/returned: Boolean result of test as specified (bool) Device input/---: none Device output/---: none Dependencies: none */ bool listIsEmpty( const StateLLType array ); /* Name: privateClearDataStructureHelper Process: recursively iterates through linked list, removing nodes from bottom to top Function input/parameters: pointer to state data linked list (StateDataType *) Function output/parameters: none Function output/returned: NULL Device input/---: none Device output/---: none Dependencies: free, clearDataStructureHelper (recursively) */ StateDataType *privateClearDataStructureHelper( StateDataType *nodePtr ); /* Name: privateCreateNodeFromData Process: creates linked list node provided member data Function input/parameters: name (const char *), population (int), growth (double), majority (char) Function output/parameters: none Function output/returned: pointer to created node (StateDataType *) Device input/---: none Device output/---: none Dependencies: malloc, privateCopyString, keyword sizeof */ StateDataType *privateCreateNodeFromData( const char *inName, int inPop, double inGrowth, char inMajority ); /* Name: privateCreateNodeFromNode Process: creates linked list node provided another node Function input/parameters: other node (const StateDataType) Function output/parameters: none Function output/returned: pointer to created node (StateDataType *) Device input/---: none Device output/---: none Dependencies: one line of code - privateCreateNodeFromData */ StateDataType *privateCreateNodeFromNode( const StateDataType source ); /* Name: privateCopyString Process: copies string character for character up to NULL_CHAR of source string Function input/parameters: source string to be copied (const char *) Function output/parameters: destination string (char *) Function output/returned: none Device input/---: none Device output/---: none Dependencies: none */ void privateCopyString( char *dest, const char *src ); /* Name: removeItemAtIndex Process: removes node from linked list at index, returns true if found, false otherwise Function input/parameters: pointer to state linked list type (StateLLType *), index to remove (int) Function output/parameters: pointer to updated state linked list type (StateLLType *), pointer to removed item (StateDataType *) Function output/returned: Boolean result of removal operation (bool) Device input/---: none Device output/---: none Dependencies: deepCopyData, free, setItemToEmpty */ bool removeItemAtIndex( StateLLType *stateData, StateDataType *removedItem, int removeIndex ); /* Name: setItemToEmpty Process: sets state data type struct to empty or default values, including empty string and majority 'x' Function input/parameters: pointer to state data value (StateDataType *) Function output/parameters: pointer to updated state data value (StateDataType *) Function output/returned: none Device input/---: none Device output/---: none Dependencies: none */ void setItemToEmpty( StateDataType *data ); #endif // ARRAY_DATA_ENGINE_H