File Based Array List Assignment

For this assignment you are going to be writing another array based list, but instead of storing it in memory, it 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 to 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 whole 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 versions of begin() and end(), 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 assignments. 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.

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 your class FileArrayList and put it in a header file called FileArrayList.h.

To help you out, here is what my class 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 FileArrayList {

FileArrayList(const FileArrayList<T> &that) = delete;

FileArrayList<T> operator=(const FileArrayList<T> &that) = delete;

// TODO - Your private data.

// TODO - Private helper functions. (Maybe file IO with an index.)

public:

typedef T value_type;

class const_iterator {

// TODO - Your private data.

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);

friend class FileArrayList;

};

// General Methods

FileArrayList(const std::string &fname);

template<typename I> // The type I will be an iterator.

FileArrayList(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.

}

~FileArrayList();

void push_back(const T &t);

void pop_back();

int size() const;

void clear();

const_iterator insert(const_iterator position, const T &t);

T operator[](int index) const;

const_iterator erase(const_iterator position);

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;

};

Test Rubric:

Basic tests of all methods (5 points)

Large tests (1000+ items) (5 points)

Tests with multiple types, including non-primitives (5 points)

Test that uses existing file (5 points)