Commit eb7200a6 authored by Rachel Wil Sha Singh's avatar Rachel Wil Sha Singh 💬

Recursion lab

parent 994a9886
#include "File.hpp"
File::File() {}
File::File( string name, string contents )
: FileSystemThing( name, "File" )
{
Setup( contents );
}
void File::Setup( string contents )
{
m_contents = contents;
m_bytes = sizeof( m_contents );
}
void File::Display()
{
FileSystemThing::Display();
}
void File::Details()
{
FileSystemThing::Details();
cout << "Size: " << m_bytes << " bytes" << endl;
cout << "Contents: " << m_contents << endl;
cout << endl;
}
#ifndef _FILE
#define _FILE
#include "FileSystemThing.hpp"
class File : public FileSystemThing
{
public:
File();
File( string name, string contents );
void Setup( string contents );
void Display();
void Details();
protected:
int m_bytes;
string m_contents;
friend class FileSystemManager;
};
#endif
#include "FileSystemManager.hpp"
#include "utilities/Logger.hpp"
#include "utilities/StringUtil.hpp"
File* FileSystemManager::FindFile( string name )
{
Logger::Out( "Find file: " + name, "FileSystemManager::FindFile" );
// Begin searching at root
return Recursive_FindFile( m_allFolders[0], name );
}
Folder* FileSystemManager::FindFolder( string name )
{
Logger::Out( "Find folder: " + name, "FileSystemManager::FindFolder" );
// Begin searching at root
return Recursive_FindFolder( m_allFolders[0], name );
}
File* FileSystemManager::Recursive_FindFile( Folder* ptrFolder, string name )
{
Logger::Out( "Searching folder: " + ptrFolder->GetName(), "FileSystemManager::Recursive_FindFile" );
return nullptr;
}
Folder* FileSystemManager::Recursive_FindFolder( Folder* ptrFolder, string name )
{
Logger::Out( "Searching folder: " + ptrFolder->GetName(), "FileSystemManager::Recursive_FindFolder" );
return nullptr;
}
void FileSystemManager::Display()
{
Logger::Out( "Display filesystem", "FileSystemManager::Display" );
// Start at root
Recursive_DisplayFolder( m_allFolders[0], 0 );
}
void FileSystemManager::Recursive_DisplayFile( File* ptrFile, int level )
{
Logger::Out( "Display file: " + ptrFile->GetName(), "FileSystemManager::Recursive_DisplayFile" );
Indent( level );
ptrFile->Display();
cout << endl;
}
void FileSystemManager::Recursive_DisplayFolder( Folder* ptrFolder, int level )
{
Logger::Out( "Display folder: " + ptrFolder->GetName(), "FileSystemManager::Recursive_DisplayFolder" );
// Display self
Indent( level );
ptrFolder->Display();
cout << endl;
// Display children
for ( auto& ptr : ptrFolder->GetFolders() )
{
Recursive_DisplayFolder( ptr, level+1 );
}
for ( auto& ptr : ptrFolder->GetFiles() )
{
Recursive_DisplayFile( ptr, level+1 );
}
}
FileSystemManager::FileSystemManager()
{
// Create files and folders and set up
// which files go in what folders and so on.
Folder* root = new Folder( "home" ); m_allFolders.push_back( root );
Folder* folder1 = new Folder( "school" ); m_allFolders.push_back( folder1 ); root->AddFolder( folder1 );
Folder* folder1a = new Folder( "cs235" ); m_allFolders.push_back( folder1a ); folder1->AddFolder( folder1a );
Folder* folder1b = new Folder( "cs210" ); m_allFolders.push_back( folder1b ); folder1->AddFolder( folder1b );
Folder* folder2 = new Folder( "work" ); m_allFolders.push_back( folder2 ); root->AddFolder( folder2 );
Folder* folder2a = new Folder( "dayjob" ); m_allFolders.push_back( folder2a ); folder2->AddFolder( folder2a );
Folder* folder2b = new Folder( "sidegig" ); m_allFolders.push_back( folder2b ); folder2->AddFolder( folder2b );
Folder* folder2ba = new Folder( "billing" ); m_allFolders.push_back( folder2ba ); folder2b->AddFolder( folder2ba );
Folder* folder3 = new Folder( "hobbies" ); m_allFolders.push_back( folder3 ); root->AddFolder( folder3 );
Folder* folder3a = new Folder( "basketweaving" ); m_allFolders.push_back( folder3a ); folder3->AddFolder( folder3a );
Folder* folder3b = new Folder( "constructed-languages" ); m_allFolders.push_back( folder3b ); folder3->AddFolder( folder3b );
Folder* folder4 = new Folder( "files" ); m_allFolders.push_back( folder4 ); root->AddFolder( folder4 );
File* file;
file = new File( "homework1.odt", "1. Learn polymorphism, 2. Get A" ); m_allFiles.push_back( file ); folder1a->AddFile ( file );
file = new File( "homework2.odt", "!(p && q) = !p || !q" ); m_allFiles.push_back( file ); folder1b->AddFile ( file );
file = new File( "transcript.odt", "Got all the good grades @ jccc" ); m_allFiles.push_back( file ); folder1->AddFile ( file );
file = new File( "references.odt", "Person who isn't family: 111-2222" ); m_allFiles.push_back( file ); folder1->AddFile ( file );
file = new File( "resume.odt", "Worked job at place, 2019" ); m_allFiles.push_back( file ); folder2->AddFile ( file );
file = new File( "logfile.txt", "Everything crashed" ); m_allFiles.push_back( file ); folder2a->AddFile ( file );
file = new File( "complaints.csv", "Bob microwaves fish" ); m_allFiles.push_back( file ); folder2a->AddFile ( file );
file = new File( "posting.txt", "Software Engineer, $75,000/yr" ); m_allFiles.push_back( file ); folder2b->AddFile ( file );
file = new File( "january.csv", "Co1 owes me $100" ); m_allFiles.push_back( file ); folder2ba->AddFile( file );
file = new File( "february.csv", "Co1 still hasn't paid" ); m_allFiles.push_back( file ); folder2ba->AddFile( file );
file = new File( "march.csv", "Still waiting on Co1's payment" ); m_allFiles.push_back( file ); folder2ba->AddFile( file );
file = new File( "todo.txt", "Learn to draw, learn piano" ); m_allFiles.push_back( file ); folder3->AddFile( file );
file = new File( "done.txt", "Mastered basketweaving!" ); m_allFiles.push_back( file ); folder3->AddFile( file );
file = new File( "coolbaskets.jpg", "u U v V" ); m_allFiles.push_back( file ); folder3a->AddFile( file );
file = new File( "esperanto.txt", "Chu vi parolas?" ); m_allFiles.push_back( file ); folder3b->AddFile( file );
file = new File( "ido.txt", "Ka vu parolas?" ); m_allFiles.push_back( file ); folder3b->AddFile( file );
file = new File( "tokipona.txt", "sina pilin seme?" ); m_allFiles.push_back( file ); folder3b->AddFile( file );
file = new File( "laadan.txt", "BAa thal ne?" ); m_allFiles.push_back( file ); folder3b->AddFile( file );
file = new File( "notpirated.mp4", "The Lost Skeleton of Cadavra" ); m_allFiles.push_back( file ); folder4->AddFile( file );
file = new File( "notavirus.exe", "DeleteHarddrive();" ); m_allFiles.push_back( file ); folder4->AddFile( file );
file = new File( "screenshot.png", "(>o.o)>----| (o_o)" ); m_allFiles.push_back( file ); folder4->AddFile( file );
Logger::Out( StringUtil::ToString( m_allFiles.size() ) + " files created", "FileSystemManager::FileSystemManager" );
for ( unsigned int i = 0; i < m_allFiles.size(); i++ )
{
Logger::Out( "File " + StringUtil::ToString( i ) + ": " + m_allFiles[i]->GetName(), "FileSystemManager::FileSystemManager" );
}
Logger::Out( StringUtil::ToString( m_allFolders.size() ) + " folders created", "FileSystemManager::FileSystemManager" );
for ( unsigned int i = 0; i < m_allFolders.size(); i++ )
{
Logger::Out( "Folder " + StringUtil::ToString( i ) + ": " + m_allFolders[i]->GetName(), "FileSystemManager::FileSystemManager" );
}
}
FileSystemManager::~FileSystemManager()
{
for ( unsigned int i = 0; i < m_allFolders.size(); i++ )
{
Logger::Out( "Delete folder " + m_allFolders[i]->GetName(), "FileSystemManager::~FileSystemManager" );
delete m_allFolders[i];
}
for ( unsigned int i = 0; i < m_allFiles.size(); i++ )
{
Logger::Out( "Delete file " + m_allFiles[i]->GetName(), "FileSystemManager::~FileSystemManager" );
delete m_allFiles[i];
}
}
void FileSystemManager::Indent( int level )
{
for ( int i = 0; i < level; i++ )
{
cout << "--";
}
cout << " ";
}
#ifndef _FILE_SYSTEM_MANAGER
#define _FILE_SYSTEM_MANAGER
#include "File.hpp"
#include "Folder.hpp"
#include <vector>
using namespace std;
class FileSystemManager
{
public:
FileSystemManager();
~FileSystemManager();
void Display();
File* FindFile( string name );
Folder* FindFolder( string name );
private:
void Recursive_DisplayFile( File* ptrFile, int level );
void Recursive_DisplayFolder( Folder* ptrFolder, int level );
File* Recursive_FindFile( Folder* ptrFolder, string name );
Folder* Recursive_FindFolder( Folder* ptrFolder, string name );
void Indent( int level );
vector<File*> m_allFiles;
vector<Folder*> m_allFolders;
};
#endif
#include "FileSystemThing.hpp"
FileSystemThing::FileSystemThing() {}
FileSystemThing::FileSystemThing( string name, string type )
{
SetName( name );
m_type = type;
}
void FileSystemThing::SetName( string name )
{
m_name = name;
}
string FileSystemThing::GetName()
{
return m_name;
}
string FileSystemThing::GetType()
{
return m_type;
}
void FileSystemThing::Display()
{
cout << m_name;
}
void FileSystemThing::Details()
{
cout << "Name: " << m_name << endl;
cout << "Type: " << m_type << endl;
}
#ifndef _FILE_SYSTEM_THING
#define _FILE_SYSTEM_THING
#include <iostream>
#include <string>
using namespace std;
class FileSystemThing
{
public:
FileSystemThing();
FileSystemThing( string name, string type );
void SetName( string name );
string GetName();
string GetType();
void Display();
void Details();
protected:
string m_name;
string m_type;
};
#endif
#include "Folder.hpp"
Folder::Folder() {}
Folder::Folder( string name )
: FileSystemThing( name, "Folder" )
{
}
void Folder::Display()
{
FileSystemThing::Display();
cout << "/";
}
void Folder::Details()
{
FileSystemThing::Details();
cout << "Total subfolders: " << m_childFolders.size() << endl;
cout << "Total files: " << m_childFiles.size() << endl;
cout << endl;
}
void Folder::AddFile( File* ptrFile )
{
m_childFiles.push_back( ptrFile );
}
void Folder::AddFolder( Folder* ptrFolder )
{
m_childFolders.push_back( ptrFolder );
}
vector<Folder*>& Folder::GetFolders()
{
return m_childFolders;
}
vector<File*>& Folder::GetFiles()
{
return m_childFiles;
}
#ifndef _FOLDER
#define _FOLDER
#include <vector>
using namespace std;
#include "FileSystemThing.hpp"
#include "File.hpp"
class Folder : public FileSystemThing
{
public:
Folder();
Folder( string name );
void Display();
void Details();
void AddFile( File* ptrFile );
void AddFolder( Folder* ptrFolder );
vector<Folder*>& GetFolders();
vector<File*>& GetFiles();
protected:
vector<Folder*> m_childFolders;
vector<File*> m_childFiles;
friend class FileSystemManager;
};
#endif
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="Recursion" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/Recursion" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/Recursion" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
</Compiler>
<Unit filename="../File.cpp" />
<Unit filename="../File.hpp" />
<Unit filename="../FileSystemManager.cpp" />
<Unit filename="../FileSystemManager.hpp" />
<Unit filename="../FileSystemThing.cpp" />
<Unit filename="../FileSystemThing.hpp" />
<Unit filename="../Folder.cpp" />
<Unit filename="../Folder.hpp" />
<Unit filename="../main.cpp" />
<Unit filename="../utilities/Logger.cpp" />
<Unit filename="../utilities/Logger.hpp" />
<Unit filename="../utilities/Menu.cpp" />
<Unit filename="../utilities/Menu.hpp" />
<Unit filename="../utilities/StringUtil.cpp" />
<Unit filename="../utilities/StringUtil.hpp" />
<Extensions />
</Project>
</CodeBlocks_project_file>
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="Recursion" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/Recursion" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/Recursion" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
</Compiler>
<Unit filename="../File.cpp" />
<Unit filename="../File.hpp" />
<Unit filename="../FileSystemManager.cpp" />
<Unit filename="../FileSystemManager.hpp" />
<Unit filename="../FileSystemThing.cpp" />
<Unit filename="../FileSystemThing.hpp" />
<Unit filename="../Folder.cpp" />
<Unit filename="../Folder.hpp" />
<Unit filename="../main.cpp" />
<Unit filename="../utilities/Logger.cpp" />
<Unit filename="../utilities/Logger.hpp" />
<Unit filename="../utilities/Menu.cpp" />
<Unit filename="../utilities/Menu.hpp" />
<Unit filename="../utilities/StringGenerator.cpp" />
<Unit filename="../utilities/StringGenerator.hpp" />
<Extensions />
</Project>
</CodeBlocks_project_file>
# depslib dependency file v1.0
1600824253 source:/home/wilsha/RACHEL/_ADULTING/TEACHING/PRIVATE/cs-235-object-oriented-programming-using-cpp/2020/Lab/Recursion/Recursion_Lab/utilities/Menu.cpp
"Menu.hpp"
1600927610 /home/wilsha/RACHEL/_ADULTING/TEACHING/PRIVATE/cs-235-object-oriented-programming-using-cpp/2020/Lab/Recursion/Recursion_Lab/utilities/Menu.hpp
<iostream>
<string>
<vector>
<cstdlib>
<limits>
<map>
<functional>
1601400108 source:/home/wilsha/RACHEL/_ADULTING/TEACHING/PRIVATE/cs-235-object-oriented-programming-using-cpp/2020/Lab/Recursion/Recursion_Lab/main.cpp
<iostream>
"FileSystemManager.hpp"
"utilities/Menu.hpp"
"utilities/Logger.hpp"
1601401424 /home/wilsha/RACHEL/_ADULTING/TEACHING/PRIVATE/cs-235-object-oriented-programming-using-cpp/2020/Lab/Recursion/Recursion_Lab/FileSystemManager.hpp
"File.hpp"
"Folder.hpp"
<vector>
1601399885 /home/wilsha/RACHEL/_ADULTING/TEACHING/PRIVATE/cs-235-object-oriented-programming-using-cpp/2020/Lab/Recursion/Recursion_Lab/File.hpp
"FileSystemThing.hpp"
1601399902 /home/wilsha/RACHEL/_ADULTING/TEACHING/PRIVATE/cs-235-object-oriented-programming-using-cpp/2020/Lab/Recursion/Recursion_Lab/FileSystemThing.hpp
<iostream>
<string>
1601399934 /home/wilsha/RACHEL/_ADULTING/TEACHING/PRIVATE/cs-235-object-oriented-programming-using-cpp/2020/Lab/Recursion/Recursion_Lab/Folder.hpp
<vector>
"FileSystemThing.hpp"
"File.hpp"
1601397528 /home/wilsha/RACHEL/_ADULTING/TEACHING/PRIVATE/cs-235-object-oriented-programming-using-cpp/2020/Lab/Recursion/Recursion_Lab/utilities/StringGenerator.hpp
<string>
1601400123 source:/home/wilsha/RACHEL/_ADULTING/TEACHING/PRIVATE/cs-235-object-oriented-programming-using-cpp/2020/Lab/Recursion/Recursion_Lab/utilities/StringGenerator.cpp
"StringGenerator.hpp"
<vector>
<cstdlib>
<ctime>
1601401495 source:/home/wilsha/RACHEL/_ADULTING/TEACHING/PRIVATE/cs-235-object-oriented-programming-using-cpp/2020/Lab/Recursion/Recursion_Lab/FileSystemManager.cpp
"FileSystemManager.hpp"
"utilities/Logger.hpp"
"utilities/StringUtil.hpp"
1601400027 source:/home/wilsha/RACHEL/_ADULTING/TEACHING/PRIVATE/cs-235-object-oriented-programming-using-cpp/2020/Lab/Recursion/Recursion_Lab/FileSystemThing.cpp
"FileSystemThing.hpp"
1601400022 source:/home/wilsha/RACHEL/_ADULTING/TEACHING/PRIVATE/cs-235-object-oriented-programming-using-cpp/2020/Lab/Recursion/Recursion_Lab/Folder.cpp
"Folder.hpp"
1601400034 source:/home/wilsha/RACHEL/_ADULTING/TEACHING/PRIVATE/cs-235-object-oriented-programming-using-cpp/2020/Lab/Recursion/Recursion_Lab/File.cpp
"File.hpp"
1600665288 /home/wilsha/RACHEL/_ADULTING/TEACHING/PRIVATE/cs-235-object-oriented-programming-using-cpp/2020/Lab/Recursion/Recursion_Lab/utilities/Logger.hpp
<chrono>
<iostream>
<fstream>
<string>
<iomanip>
1600665380 source:/home/wilsha/RACHEL/_ADULTING/TEACHING/PRIVATE/cs-235-object-oriented-programming-using-cpp/2020/Lab/Recursion/Recursion_Lab/utilities/Logger.cpp
"Logger.hpp"
1600814300 source:/home/wilsha/RACHEL/_ADULTING/TEACHING/PRIVATE/cs-235-object-oriented-programming-using-cpp/2020/Lab/Recursion/Recursion_Lab/utilities/StringUtil.cpp
"StringUtil.hpp"
<string>
<sstream>
1600814276 /home/wilsha/RACHEL/_ADULTING/TEACHING/PRIVATE/cs-235-object-oriented-programming-using-cpp/2020/Lab/Recursion/Recursion_Lab/utilities/StringUtil.hpp
<string>
<sstream>
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>