languages

A collection of programs made with different programming languages.
git clone git://evanalba.com/languages
Log | Files | Refs

todo_list.h (2557B)


      1 /*
      2  * Name        : todo_list.h
      3  * Author      : Evan Alba
      4  * Description : Header File for class TodoList.
      5  */
      6 #ifndef TODO_LIST
      7 #define TODO_LIST
      8 #include "todo_item.h"
      9 #include <algorithm>
     10 #include <iostream>
     11 #include <string>
     12 #include <sstream>
     13 
     14 class TodoList {
     15  public:
     16     /* 
     17       Creates a dynamic array of 25 elements and initializes the elements 
     18       to NULL. 
     19     */
     20     TodoList();
     21 
     22     /* 
     23       Frees the memory for all TodoItems 
     24       Frees the memory for the dynamic TodoItem* array
     25     */
     26     ~TodoList();
     27 
     28     /*
     29       Add an item to the list.
     30       If there is room in the array add the new 
     31       dynamic instance to the first available spot (i.e. the current size). If
     32       the array is full, increase capacity by 10 and then add the item. 
     33     */
     34     void AddItem(TodoItem* add);
     35 
     36     /*
     37        Delete a item from the list given the location.
     38        Checks first if location valid to delete item from list.
     39        Please note the location (area) is in human-readable form, i.e. 
     40        location 1 is really array index 0. After you delete the item you will 
     41        need to pack your array (shift all items "down" so there are no 
     42        empty slots between items). 
     43     */
     44     void DeleteItem(unsigned int location);
     45 
     46     /*
     47        Gets an item from the list given the location.
     48        Checks first if location valid to get an item from the list.
     49        Please note the location is in human-
     50        readable form, i.e. location 1 is really array index 0. This function 
     51        will return a pointer to the TodoItem requested. If that location 
     52        doesn't exist it returns NULL. 
     53     */
     54     TodoItem* GetItem(int location);
     55 
     56     /* 
     57        Returns an unsigned integer containing the 
     58        current size of the list (number of items present).
     59     */
     60     unsigned int GetSize() const;
     61 
     62     /* 
     63        Returns an unsigned integer containing the
     64        current maximum capacity of the list (number of slots).
     65     */
     66     unsigned int GetCapacity() const;
     67 
     68     /*
     69        Sorts the array by the priorities of the items. (1 is 
     70        highest priority, 5 is lowest). 
     71     */
     72     void Sort();
     73 
     74 
     75     std::string ToFile();
     76     friend std::ostream& operator << (std::ostream &out, const TodoList &obj);
     77 
     78  private:
     79     /* PRIVATE Data for Todo List Class */
     80     unsigned int size_; /* Current size of your list. */
     81     unsigned int cap_; /* Max capacity of your list. */
     82     TodoItem** list_; /* Pointer to TodoItem*. */
     83     /* PRIVATE Prototypes for Todo List Class */
     84     void IncreaseCap();
     85     void TightenArray(int start);
     86 };
     87 #endif