File Based Lists Assignment

For this assignment you are going to be writing the same two types of lists you wrote last time, but instead of having them be memory based, they should be stored on disk in a file. This changes up some of the basics of the classes. You will not have copy constructors or assignment operators. Those need to be forbidden so that they don't happen by accident. This means that instances of these classes can only be passed and returned by reference or pointer. I do want you to write a constructor that makes a copy, but it will need an extra argument for the name of the file to use with the copy. You also need a constructor that just takes the file name (passed as a const std::string &). That constructor should link the object ot that file and enable access to whatever had been stored in that file previously. It is fine if your container only allows an int worth of elements. The main rule for this collection is that the data set can never be loaded into memory at one time. At most, only 2 elements should ever be stored in memory by the collection methods at a given time.

In addition, you won't have a regular iterator, only a const_iterator. You should still include all the version of begin, but they will all return a const_iterator. In addition, your operator[] will return a T and not a T&. We will add a set method to the class instead. I will let you think of why these changes are required. The set method should have the following signature.

void set(const T &value,int index);

Your classes need to have working bi-directional iterators as did those in the previous assignment. You only need to handle fixed length records that do not contain pointers. That is to say that sizeof(T) is all the storage you need for a given record. As with the previous assignment, I want your classes to inherit from the given definition of List. (That is what specifies the methods you need to include.)

Note that I don't care what format you use for the data file, as long as I could run a second program that uses the same file and find it has the same contents.

Call the two classes FileArrayList and FileLinkedList and put them in header files called FileArrayList.h and FileLinkedList.h.

To help you out, here is what one of my classes looks like without any code in it. I have taken out the private things except for the methods where I am using private to hide them.

template<typename T>

class FileLinkedList {

FileLinkedList(const FileLinkedList<T> &that) {}

FileLinkedList<T> operator=(const FileLinkedList<T> &that) {}

public:

typedef T value_type;

class const_iterator {

public:

const_iterator(int i,FILE *f);

const_iterator(const const_iterator &i);

T operator*();

bool operator==(const const_iterator &i) const;

bool operator!=(const const_iterator &i) const;

const_iterator &operator=(const const_iterator &i);

const_iterator &operator++();

const_iterator &operator--();

const_iterator operator++(int);

const_iterator operator--(int);

};

// General Methods

FileLinkedList(const std::string &fname);

template<typename I>

FileLinkedList(I begin,I end,const std::string &fname) {

// TODO - Write this one here. It is easier than trying to fight with adding a template below.

}

virtual ~FileLinkedList();

virtual void push_back(const T &t);

virtual void pop_back();

virtual int size() const;

virtual void clear();

virtual void insert(const T &t,int index);

virtual T operator[](int index) const;

virtual void remove(int index);

virtual void set(const T &value,int index);

const_iterator begin();

const_iterator begin() const;

const_iterator end();

const_iterator end() const;

const_iterator cbegin() const;

const_iterator cend() const;

};