Assignment 3 File System
Introduction
Overview
There are 6 classes.
· FSObject: File system object. The base class of all file system entities. It is an ABC (abstract base class).
· File: Inherits from FSObject. It can store some string content.
· Directory: Inherits from FSObject. It can contain other files or directories. It is also an ABC.
· SADirectory: Inherits from Directory. It is an implementation of Directory that uses a static array.
· LLDirectory: Inherits from Directory. It is an implementation of Directory that uses a linked list.
· System: It is the file system class. It is on its own and it is a template class. The template type T is either SADirectory or LLDirectory for this assignment. In other words, it can be either a file system of SADirectory or a file system of LLDirectory depending on what template type you provide to it when you create the system.
Your solution to this assignment must be based on the given skeleton code provided in the Download section.
Your task is to complete the following:
· FSObject implementation in FSObject.cpp
· SADirectory implementation in SADirectory.cpp
· LLDirectory implementation in LLDirectory.cpp
· System implementation in System.tpp
These are the only 4 files you are supposed to modify, zip, and then submit to Canvas.
Comments in the corresponding header file lists out the detailed requirements. The description below supplements the only missing information. You need to read both the source/header files and the webpage description carefully to get the whole picture.
While you probably will jump back and forth as you read the materials as they reference each others, we recommend the following general reading order:
· FSObject.h
· File.h
· Directory.h
· SADirectory.h
· LLDirectory.h
· System.h
· Remaining of this webpage
· main.cpp
Read the FAQ page for some common clarifications. You should check that a day before the deadline to make sure you don’t miss any clarification, even if you have already submitted your work then.
Submission details are in the Submission and Deadline section.
Tips
typeid
You can use typeid to find out the type of a polymorphic object.
For example:
if(typeid(someObject) == typeid(LLDirectory)) cout << "someObject is of the type LLDirectory!"; else cout << "someObject is NOT of the type LLDirectory!";
Note: The typeinfo library is already included in Directory.h which is included in SADirectory.h and LLDirectory.h.
dynamic_cast
dynamic_cast can be used to safely convert pointers to classes up, down, and sideways along the inheritance hierarchy.
For example:
Directory* p = dynamic_cast(someFSObjectPointer); //someFSObjectPointer is, well, some FSObject pointer... (surprise!)
Since someFSObjectPointer is a FSObject pointer, so it can potentially be pointing to a SADirectory object, a LLDirectory object, or a File object. (since FSObject and Directory are ABC, we won’t be able to create simply FSObject objects and simply Directory objects). This dynamic_cast will return a Directory pointer if someFSObjectPointer is in fact either a SADirectory or LLDirectory object. However, it will return NULL if the casting is impossible (e.g. someFSObjectPointer points to a File object, or NULL, etc.). Therefore, by checking if p is NULL, you can use dynmaic_cast to check if a pointer actually points to an object of certain classes.
It is also useful to cast to a pointer of certain class so that you can use member functions defined for that class. For example, you won’t be able to do
someFSObjectPointer->getChild("hello");
because someFSObjectPointer is just a FSObject pointer, but you can do
Directory* p = dynamic_cast(someFSObjectPointer);
if(p!=NULL) //make sure the casting is successful
p->getChild("hello");
Lexicographical ordering
In LLDirectory, the children should always be sorted by their names in ascending lexicographical order. For example:
A [Z] a [b] c [e]
(Directory names are surrounded by brackets [] when we list them, but only the names are considered during sorting) Notice that “Z” is smaller than “a” lexicographically.
Comparing names can be done easily by basic string comparison – since a child name is of the C++ string class, the names can be directly compared with operator “>”, “<“, or “==”. For example:
string a = "Apple"; string b = "Banana"; cout << boolalpha << (b>a) << endl; //prints true, as "Banana" is lexicographically larger string c = "a"; string d = "Z"; cout << boolalpha << (c>d) << endl; //prints true, as "a" is lexicographically larger
Note that you don’t really need to use any special sorting algorithm for this task. You just need to make sure you insert the new node (which contains the new child) to a proper place in the linked list in your LLDirectory::addChild implementation.
Sample Output
Your finished program should produce the exact same output as below. Please note that sample outputs, naturally, do not show all possible cases. It is part of the assessment for you to design your own test cases to test your program. Be reminded to remove any debugging message that you might have added before submitting your code.
Also, after testing, make sure your submitted code can compile with the unmodified main.cpp and header files. Put in dummy/empty implementation whenever needed.
Program should terminate without any memory leak.
Submission and Deadline
Deadline: 23:59:00 on November 28, 2018
FAQ
Frequently Asked Questions
Q: My code doesn’t work / there is an error, here is the code, can you help me fix it?
A: As the assignment is a major course assessment, to be fair, you are supposed to work on it on your own and we should not finish the tasks for you. We might provide some very general hints to you, but we shall not fix the problem or debug for you.
Q: Can I add extra helper functions? Can I include additional libraries?
A: No, and no. Everything you need is already included – there is no need for you to add any include statement (under our official environment).
Q: For the LLDirectory test 1 in main.cpp, at line 166, should the cout statement prints “[a] [b] [c] f1 f2 f3 [z]” instead of “[a] [b] f1 f2 f3 [z]” in the message when the output format is incorrect?
A: Yes, thanks for pointing that out, and sorry for the typo. The skeleton has been updated (Nov 13th, 8:33am). This typo is not crucial as this doesn’t affect the final output (because the message only appears as a hint when your list() implementation is not yet correct), so it is up to you to update the skeleton main.cpp or not, if you have aleady downloaded it.
Q: Can I have some examples of what FSObject::getPath return?
A: Sure.
· If the object is the root, “\”
· If the object is a file named “b” under the directory “a” under the root, “\a\b”
· If the object is a directory named “b” under the directory “a” under the root, “\a\b”
A path always starts with “\” but never ends with it unless the object is the root which is represented by simply “\”. Again, please note that when you print “\” on the console, it becomes a single slash . There are more examples in the sample output, please also check them out.