SlideShare a Scribd company logo
Implementing a basic directory-tree structure that is derived from a base tree structure.
#ifndef SRC_TREENODE_HPP_
#define SRC_TREENODE_HPP_
#include
#include
//#define USE_OSS
#ifndef USE_OSS
#define OUT std::cout
#else
#include
extern std::ostringstream oss;
#define OUT oss
#endif
namespace ensc251 {
static unsigned count = 0;
class TreeNode;
typedef TreeNode* (TreeNode::*action_func)(void);
typedef void (TreeNode::*traverse_func)(const TreeNode*);
class TreeNode
{
typedef std::vector TreeNodePVect;
protected:
TreeNodePVect childPVector;
public:
TreeNode() {};
TreeNode(const TreeNode& nodeToCopy) {
// ***** this needs work *****
if (nodeToCopy.childPVector.size())
add_childP(nodeToCopy.childPVector[0]->clone());
}
virtual TreeNode* clone() const { return new TreeNode(*this); };
virtual ~TreeNode() {
// do not modify this insertion on OUT
OUT << "Destroying TreeNode with " << childPVector.size() << " children."<< std::endl;
// ***** Complete this member function *****
}
void swap(TreeNode & other) // the swap member function (should never fail!)
{
// ***** fill this in if desired *****
}
TreeNode & operator = (TreeNode other) // note: argument passed by value, copy made!
{
// ***** Complete this code *****
return *this; // by convention, always return *this
}
void add_childP(TreeNode* child) { /* ***** Complete this member function ***** */ }
void add_children(const TreeNodePVect& childPV) { childPVector.insert(childPVector.end(),
childPV.begin(), childPV.end()); }
const TreeNodePVect& get_children() const { return childPVector; }
TreeNode* traverse_children_post_order(traverse_func tf, action_func af)
{
for(auto childP : childPVector) {
(childP->*tf)(this); // traverse child's children using tf
}
return (this->*af)();
}
TreeNode* traverse_children_pre_order(traverse_func tf, action_func af)
{
// ***** Complete this member function *****
}
TreeNode* traverse_children_in_order(traverse_func tf, action_func af)
{
// ***** Complete this member function *****
}
TreeNode* count_action()
{
count++;
return nullptr;
}
void count_traverse(const TreeNode*)
{
traverse_children_post_order(count_traverse, count_action);
}
void reset_count() { count = 0; }
unsigned get_count() const { return count; }
};
}
#endif /* SRC_TREENODE_HPP_ */
#include "makeDirectoryTree.hpp"
using namespace std;
int doStuff()
{
// call function to build directory tree in memory
auto root_dir1P = make_directory_tree(".", "test_dir");
if (root_dir1P) {
root_dir1P->print_traverse(nullptr);
OUT << endl;
root_dir1P->reset_count();
root_dir1P->count_traverse(nullptr);
OUT << "Count is " << root_dir1P->get_count() << " " << endl;
auto root_dir2 = Directory(*root_dir1P); // copy construction
root_dir2.print_traverse(nullptr);
OUT << endl;
auto root_dir3P = make_directory_tree("test_dir", "Lectures");
if (root_dir3P) {
root_dir2 = *root_dir3P; // overloaded copy assignment operation
OUT << endl;
delete root_dir3P;
OUT << endl;
}
root_dir2.print_traverse(nullptr);
OUT << endl;
delete root_dir1P;
OUT << endl;
} // destructor for root_dir2 called.
OUT << endl;
return 0;
}
// don't remove the below line.
#ifndef DONT_RUN_MAIN
int main()
{
int rv = doStuff();
#ifdef USE_OSS
std::string s = oss.str();
cout << s << endl;
#endif
return rv;
}
#endif
/* End of dirTree.cpp file */
* makeDirectoryTree.cpp
#include
#include
#include // for find
#include "makeDirectoryTree.hpp"
// The below function may be replaced. Don't worry about trying to understand
// this version.
// traverse directories on the filesystem starting at a certain point and build
// a directory tree in memory
Directory *make_directory_tree(const std::string& path, const std::string& dir_name)
{
using namespace std;
static vector ignore_list = {".",".."};
auto newPath = path + "" + dir_name;
DIR *dir;
if ((dir = opendir(newPath.c_str())) == nullptr)
{
OUT << newPath.c_str() << " Error while opening " << newPath << endl;
return nullptr;
}
auto new_entity = new Directory(dir_name);
struct dirent *dptr;
while ((dptr = readdir(dir)))
{
if(find(ignore_list.begin(), ignore_list.end(), dptr->d_name) != ignore_list.end())
continue;
auto fullPath = newPath + "" + dptr->d_name;
struct stat filestat;
stat(fullPath.c_str(), &filestat);
if(S_ISDIR(filestat.st_mode))
{
auto node = make_directory_tree(newPath, dptr->d_name);
if (!node)
// add directory with no files or subdirs in case of permission problem
node = new Directory(dptr->d_name);
new_entity->add_childP(node);
}
else {
new_entity->add_file(dptr->d_name);
}
}
return new_entity;
}
/*
* makeDirectoryTree.hpp
#ifndef SRC_MAKEDIRECTORYTREE_HPP_
#define SRC_MAKEDIRECTORYTREE_HPP_
#include "Directory.hpp"
Directory *make_directory_tree(const std::string& path, const std::string& dir_name)
;
#endif /* SRC_MAKEDIRECTORYTREE_HPP_ */
#include "TreeNode.hpp"
#ifdef USE_OSS
std::ostringstream oss;
#define OUT oss
#endif
#ifndef SRC_DIRECTORY_HPP_
#define SRC_DIRECTORY_HPP_
#include "TreeNode.hpp"
#include
#include
#include
class Directory : public ensc251::TreeNode
{
typedef std::vector stringVect;
private:
std::string dir_name;
stringVect file_names;
public:
Directory(std::string m_dir_name): dir_name(m_dir_name) {}
Directory(std::string m_dir_name, stringVect m_file_names): dir_name(m_dir_name),
file_names(m_file_names) {}
virtual Directory* clone() const { /* ***** Complete this member function ***** */ };
void set_dir_name(const std::string& m_dir_name){ /* ***** Complete this member function
***** */ }
const std::string & get_dir_name() { return dir_name; }
void add_file(const std::string& m_fileName) { /* ***** Complete this member function
***** */ }
void add_multiple_files(const stringVect& m_files) { file_names.insert(file_names.end(),
m_files.begin(), m_files.end()); }
const stringVect & get_files() const { return file_names; }
TreeNode* print_action()
{
// Do not modify insertion on OUT in this member function!
OUT << std::setw(20) << dir_name+"t|" << " ";
OUT << this->childPVector.size() << " ";
for (auto file : file_names)
{
OUT << " -" << file;
}
OUT << std::endl;
return nullptr;
}
void print_traverse(const TreeNode*)
{
// ***** this needs work *****
// ***** encode the rules in the instructions
traverse_children_post_order(
static_cast(print_traverse),
static_cast(print_action));
}
};
#endif /* SRC_DIRECTORY_HPP_ */
Solution
Step 1: You get the assembly code reference, particularly you will need to know which
mnemonic corresponds to which machine code

More Related Content

Similar to Implementing a basic directory-tree structure that is derived from a.pdf

filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxfilesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
ssuser454af01
 
Writing A Foreign Data Wrapper
Writing A Foreign Data WrapperWriting A Foreign Data Wrapper
Writing A Foreign Data Wrapper
psoo1978
 
Extbase and Beyond
Extbase and BeyondExtbase and Beyond
Extbase and Beyond
Jochen Rau
 
Add these three functions to the class binaryTreeType (provided).W.pdf
Add these three functions to the class binaryTreeType (provided).W.pdfAdd these three functions to the class binaryTreeType (provided).W.pdf
Add these three functions to the class binaryTreeType (provided).W.pdf
indiaartz
 
Php 5.6
Php 5.6Php 5.6
Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_Tool
Gordon Forsythe
 
Drizzles Approach To Improving Performance Of The Server
Drizzles  Approach To  Improving  Performance Of The  ServerDrizzles  Approach To  Improving  Performance Of The  Server
Drizzles Approach To Improving Performance Of The ServerPerconaPerformance
 
DRUPAL 8 STORAGES OVERVIEW
DRUPAL 8 STORAGES OVERVIEWDRUPAL 8 STORAGES OVERVIEW
DRUPAL 8 STORAGES OVERVIEW
DrupalCamp Kyiv
 
PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data Objects
Wez Furlong
 
Assignment of SOS operating systemThe file lmemman.c has one incom.pdf
Assignment of SOS operating systemThe file lmemman.c has one incom.pdfAssignment of SOS operating systemThe file lmemman.c has one incom.pdf
Assignment of SOS operating systemThe file lmemman.c has one incom.pdf
sktambifortune
 
AST + Better Reflection (PHP Benelux 2016 Unconference)
AST + Better Reflection (PHP Benelux 2016 Unconference)AST + Better Reflection (PHP Benelux 2016 Unconference)
AST + Better Reflection (PHP Benelux 2016 Unconference)
James Titcumb
 
Quebec pdo
Quebec pdoQuebec pdo
Quebec pdo
Valentine Dianov
 
#include iostream #include cstring #include vector #i.pdf
 #include iostream #include cstring #include vector #i.pdf #include iostream #include cstring #include vector #i.pdf
#include iostream #include cstring #include vector #i.pdf
anandatalapatra
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
michardsonkhaicarr37
 
Im having difficulty with the directives i figured out a duplicatio.pdf
Im having difficulty with the directives i figured out a duplicatio.pdfIm having difficulty with the directives i figured out a duplicatio.pdf
Im having difficulty with the directives i figured out a duplicatio.pdf
maheshkumar12354
 
Modify this code to change the underlying data structure to .pdf
Modify this code to change the underlying data structure to .pdfModify this code to change the underlying data structure to .pdf
Modify this code to change the underlying data structure to .pdf
adityaenterprise32
 
srgoc
srgocsrgoc
Create an implementation of a binary tree using the recursive appr.pdf
Create an implementation of a binary tree using the recursive appr.pdfCreate an implementation of a binary tree using the recursive appr.pdf
Create an implementation of a binary tree using the recursive appr.pdf
federaleyecare
 

Similar to Implementing a basic directory-tree structure that is derived from a.pdf (20)

filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxfilesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
 
Writing MySQL UDFs
Writing MySQL UDFsWriting MySQL UDFs
Writing MySQL UDFs
 
Writing A Foreign Data Wrapper
Writing A Foreign Data WrapperWriting A Foreign Data Wrapper
Writing A Foreign Data Wrapper
 
Extbase and Beyond
Extbase and BeyondExtbase and Beyond
Extbase and Beyond
 
Add these three functions to the class binaryTreeType (provided).W.pdf
Add these three functions to the class binaryTreeType (provided).W.pdfAdd these three functions to the class binaryTreeType (provided).W.pdf
Add these three functions to the class binaryTreeType (provided).W.pdf
 
Php 5.6
Php 5.6Php 5.6
Php 5.6
 
Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_Tool
 
Drizzles Approach To Improving Performance Of The Server
Drizzles  Approach To  Improving  Performance Of The  ServerDrizzles  Approach To  Improving  Performance Of The  Server
Drizzles Approach To Improving Performance Of The Server
 
DRUPAL 8 STORAGES OVERVIEW
DRUPAL 8 STORAGES OVERVIEWDRUPAL 8 STORAGES OVERVIEW
DRUPAL 8 STORAGES OVERVIEW
 
PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data Objects
 
Assignment of SOS operating systemThe file lmemman.c has one incom.pdf
Assignment of SOS operating systemThe file lmemman.c has one incom.pdfAssignment of SOS operating systemThe file lmemman.c has one incom.pdf
Assignment of SOS operating systemThe file lmemman.c has one incom.pdf
 
AST + Better Reflection (PHP Benelux 2016 Unconference)
AST + Better Reflection (PHP Benelux 2016 Unconference)AST + Better Reflection (PHP Benelux 2016 Unconference)
AST + Better Reflection (PHP Benelux 2016 Unconference)
 
Quebec pdo
Quebec pdoQuebec pdo
Quebec pdo
 
#include iostream #include cstring #include vector #i.pdf
 #include iostream #include cstring #include vector #i.pdf #include iostream #include cstring #include vector #i.pdf
#include iostream #include cstring #include vector #i.pdf
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
 
Im having difficulty with the directives i figured out a duplicatio.pdf
Im having difficulty with the directives i figured out a duplicatio.pdfIm having difficulty with the directives i figured out a duplicatio.pdf
Im having difficulty with the directives i figured out a duplicatio.pdf
 
Modify this code to change the underlying data structure to .pdf
Modify this code to change the underlying data structure to .pdfModify this code to change the underlying data structure to .pdf
Modify this code to change the underlying data structure to .pdf
 
Hachiojipm11
Hachiojipm11Hachiojipm11
Hachiojipm11
 
srgoc
srgocsrgoc
srgoc
 
Create an implementation of a binary tree using the recursive appr.pdf
Create an implementation of a binary tree using the recursive appr.pdfCreate an implementation of a binary tree using the recursive appr.pdf
Create an implementation of a binary tree using the recursive appr.pdf
 

More from funkybabyindia

Part C AssessmentsAs you examined each specific connective tissue,.pdf
Part C AssessmentsAs you examined each specific connective tissue,.pdfPart C AssessmentsAs you examined each specific connective tissue,.pdf
Part C AssessmentsAs you examined each specific connective tissue,.pdf
funkybabyindia
 
please answer in details12 A communication system consists of 13 a.pdf
please answer in details12 A communication system consists of 13 a.pdfplease answer in details12 A communication system consists of 13 a.pdf
please answer in details12 A communication system consists of 13 a.pdf
funkybabyindia
 
Name the plant phylum that exhibit the follow characteristics Co.pdf
Name the plant phylum that exhibit the follow characteristics  Co.pdfName the plant phylum that exhibit the follow characteristics  Co.pdf
Name the plant phylum that exhibit the follow characteristics Co.pdf
funkybabyindia
 
Individuals that express the disease sickle cell anemia are homozygo.pdf
Individuals that express the disease sickle cell anemia are homozygo.pdfIndividuals that express the disease sickle cell anemia are homozygo.pdf
Individuals that express the disease sickle cell anemia are homozygo.pdf
funkybabyindia
 
I will provide my LinkedList from my last lab.LinkedList.cpp~~~~.pdf
I will provide my LinkedList from my last lab.LinkedList.cpp~~~~.pdfI will provide my LinkedList from my last lab.LinkedList.cpp~~~~.pdf
I will provide my LinkedList from my last lab.LinkedList.cpp~~~~.pdf
funkybabyindia
 
I need help summarizing a research article!! I need to summarize an .pdf
I need help summarizing a research article!! I need to summarize an .pdfI need help summarizing a research article!! I need to summarize an .pdf
I need help summarizing a research article!! I need to summarize an .pdf
funkybabyindia
 
For the pedigree on the right, individuals affected with the genetic.pdf
For the pedigree on the right, individuals affected with the genetic.pdfFor the pedigree on the right, individuals affected with the genetic.pdf
For the pedigree on the right, individuals affected with the genetic.pdf
funkybabyindia
 
How are the xylem and phloem arranged in a eudicot rootA. the xyl.pdf
How are the xylem and phloem arranged in a eudicot rootA. the xyl.pdfHow are the xylem and phloem arranged in a eudicot rootA. the xyl.pdf
How are the xylem and phloem arranged in a eudicot rootA. the xyl.pdf
funkybabyindia
 
Graph 1 Annual growth () of national output 25 20 15 15 10 0 So.pdf
Graph 1 Annual growth () of national output 25 20 15 15 10 0 So.pdfGraph 1 Annual growth () of national output 25 20 15 15 10 0 So.pdf
Graph 1 Annual growth () of national output 25 20 15 15 10 0 So.pdf
funkybabyindia
 
Explain why Drosophila are often used as model organisms in the study.pdf
Explain why Drosophila are often used as model organisms in the study.pdfExplain why Drosophila are often used as model organisms in the study.pdf
Explain why Drosophila are often used as model organisms in the study.pdf
funkybabyindia
 
Examine the two animals in the photographs figure. Use all of the c.pdf
Examine the two animals in the photographs figure. Use all of the c.pdfExamine the two animals in the photographs figure. Use all of the c.pdf
Examine the two animals in the photographs figure. Use all of the c.pdf
funkybabyindia
 
Assess the types of stakeholders involved in the development process.pdf
Assess the types of stakeholders involved in the development process.pdfAssess the types of stakeholders involved in the development process.pdf
Assess the types of stakeholders involved in the development process.pdf
funkybabyindia
 
There is a well-defined classification s developed originally by Caro.pdf
There is a well-defined classification s developed originally by Caro.pdfThere is a well-defined classification s developed originally by Caro.pdf
There is a well-defined classification s developed originally by Caro.pdf
funkybabyindia
 
Write the level of protein structure below each picture. A word bank .pdf
Write the level of protein structure below each picture. A word bank .pdfWrite the level of protein structure below each picture. A word bank .pdf
Write the level of protein structure below each picture. A word bank .pdf
funkybabyindia
 
Why should assembly language be avoided for general application deve.pdf
Why should assembly language be avoided for general application deve.pdfWhy should assembly language be avoided for general application deve.pdf
Why should assembly language be avoided for general application deve.pdf
funkybabyindia
 
Who was Jesus of Nazareth What was his message How did he convey t.pdf
Who was Jesus of Nazareth What was his message How did he convey t.pdfWho was Jesus of Nazareth What was his message How did he convey t.pdf
Who was Jesus of Nazareth What was his message How did he convey t.pdf
funkybabyindia
 
why has America never been a homogenous societywhy has Amer.pdf
why has America never been a homogenous societywhy has Amer.pdfwhy has America never been a homogenous societywhy has Amer.pdf
why has America never been a homogenous societywhy has Amer.pdf
funkybabyindia
 
Which of these statements about Java are trueA.( T F ) Using va.pdf
Which of these statements about Java are trueA.( T  F ) Using va.pdfWhich of these statements about Java are trueA.( T  F ) Using va.pdf
Which of these statements about Java are trueA.( T F ) Using va.pdf
funkybabyindia
 
When someone suffers from arteriosclerosis, there is a widening of th.pdf
When someone suffers from arteriosclerosis, there is a widening of th.pdfWhen someone suffers from arteriosclerosis, there is a widening of th.pdf
When someone suffers from arteriosclerosis, there is a widening of th.pdf
funkybabyindia
 
What is the relationship of Computer System Validation to the Softwa.pdf
What is the relationship of Computer System Validation to the Softwa.pdfWhat is the relationship of Computer System Validation to the Softwa.pdf
What is the relationship of Computer System Validation to the Softwa.pdf
funkybabyindia
 

More from funkybabyindia (20)

Part C AssessmentsAs you examined each specific connective tissue,.pdf
Part C AssessmentsAs you examined each specific connective tissue,.pdfPart C AssessmentsAs you examined each specific connective tissue,.pdf
Part C AssessmentsAs you examined each specific connective tissue,.pdf
 
please answer in details12 A communication system consists of 13 a.pdf
please answer in details12 A communication system consists of 13 a.pdfplease answer in details12 A communication system consists of 13 a.pdf
please answer in details12 A communication system consists of 13 a.pdf
 
Name the plant phylum that exhibit the follow characteristics Co.pdf
Name the plant phylum that exhibit the follow characteristics  Co.pdfName the plant phylum that exhibit the follow characteristics  Co.pdf
Name the plant phylum that exhibit the follow characteristics Co.pdf
 
Individuals that express the disease sickle cell anemia are homozygo.pdf
Individuals that express the disease sickle cell anemia are homozygo.pdfIndividuals that express the disease sickle cell anemia are homozygo.pdf
Individuals that express the disease sickle cell anemia are homozygo.pdf
 
I will provide my LinkedList from my last lab.LinkedList.cpp~~~~.pdf
I will provide my LinkedList from my last lab.LinkedList.cpp~~~~.pdfI will provide my LinkedList from my last lab.LinkedList.cpp~~~~.pdf
I will provide my LinkedList from my last lab.LinkedList.cpp~~~~.pdf
 
I need help summarizing a research article!! I need to summarize an .pdf
I need help summarizing a research article!! I need to summarize an .pdfI need help summarizing a research article!! I need to summarize an .pdf
I need help summarizing a research article!! I need to summarize an .pdf
 
For the pedigree on the right, individuals affected with the genetic.pdf
For the pedigree on the right, individuals affected with the genetic.pdfFor the pedigree on the right, individuals affected with the genetic.pdf
For the pedigree on the right, individuals affected with the genetic.pdf
 
How are the xylem and phloem arranged in a eudicot rootA. the xyl.pdf
How are the xylem and phloem arranged in a eudicot rootA. the xyl.pdfHow are the xylem and phloem arranged in a eudicot rootA. the xyl.pdf
How are the xylem and phloem arranged in a eudicot rootA. the xyl.pdf
 
Graph 1 Annual growth () of national output 25 20 15 15 10 0 So.pdf
Graph 1 Annual growth () of national output 25 20 15 15 10 0 So.pdfGraph 1 Annual growth () of national output 25 20 15 15 10 0 So.pdf
Graph 1 Annual growth () of national output 25 20 15 15 10 0 So.pdf
 
Explain why Drosophila are often used as model organisms in the study.pdf
Explain why Drosophila are often used as model organisms in the study.pdfExplain why Drosophila are often used as model organisms in the study.pdf
Explain why Drosophila are often used as model organisms in the study.pdf
 
Examine the two animals in the photographs figure. Use all of the c.pdf
Examine the two animals in the photographs figure. Use all of the c.pdfExamine the two animals in the photographs figure. Use all of the c.pdf
Examine the two animals in the photographs figure. Use all of the c.pdf
 
Assess the types of stakeholders involved in the development process.pdf
Assess the types of stakeholders involved in the development process.pdfAssess the types of stakeholders involved in the development process.pdf
Assess the types of stakeholders involved in the development process.pdf
 
There is a well-defined classification s developed originally by Caro.pdf
There is a well-defined classification s developed originally by Caro.pdfThere is a well-defined classification s developed originally by Caro.pdf
There is a well-defined classification s developed originally by Caro.pdf
 
Write the level of protein structure below each picture. A word bank .pdf
Write the level of protein structure below each picture. A word bank .pdfWrite the level of protein structure below each picture. A word bank .pdf
Write the level of protein structure below each picture. A word bank .pdf
 
Why should assembly language be avoided for general application deve.pdf
Why should assembly language be avoided for general application deve.pdfWhy should assembly language be avoided for general application deve.pdf
Why should assembly language be avoided for general application deve.pdf
 
Who was Jesus of Nazareth What was his message How did he convey t.pdf
Who was Jesus of Nazareth What was his message How did he convey t.pdfWho was Jesus of Nazareth What was his message How did he convey t.pdf
Who was Jesus of Nazareth What was his message How did he convey t.pdf
 
why has America never been a homogenous societywhy has Amer.pdf
why has America never been a homogenous societywhy has Amer.pdfwhy has America never been a homogenous societywhy has Amer.pdf
why has America never been a homogenous societywhy has Amer.pdf
 
Which of these statements about Java are trueA.( T F ) Using va.pdf
Which of these statements about Java are trueA.( T  F ) Using va.pdfWhich of these statements about Java are trueA.( T  F ) Using va.pdf
Which of these statements about Java are trueA.( T F ) Using va.pdf
 
When someone suffers from arteriosclerosis, there is a widening of th.pdf
When someone suffers from arteriosclerosis, there is a widening of th.pdfWhen someone suffers from arteriosclerosis, there is a widening of th.pdf
When someone suffers from arteriosclerosis, there is a widening of th.pdf
 
What is the relationship of Computer System Validation to the Softwa.pdf
What is the relationship of Computer System Validation to the Softwa.pdfWhat is the relationship of Computer System Validation to the Softwa.pdf
What is the relationship of Computer System Validation to the Softwa.pdf
 

Recently uploaded

Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
gb193092
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 

Recently uploaded (20)

Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 

Implementing a basic directory-tree structure that is derived from a.pdf

  • 1. Implementing a basic directory-tree structure that is derived from a base tree structure. #ifndef SRC_TREENODE_HPP_ #define SRC_TREENODE_HPP_ #include #include //#define USE_OSS #ifndef USE_OSS #define OUT std::cout #else #include extern std::ostringstream oss; #define OUT oss #endif namespace ensc251 { static unsigned count = 0; class TreeNode; typedef TreeNode* (TreeNode::*action_func)(void); typedef void (TreeNode::*traverse_func)(const TreeNode*); class TreeNode { typedef std::vector TreeNodePVect; protected: TreeNodePVect childPVector; public: TreeNode() {}; TreeNode(const TreeNode& nodeToCopy) { // ***** this needs work ***** if (nodeToCopy.childPVector.size()) add_childP(nodeToCopy.childPVector[0]->clone()); } virtual TreeNode* clone() const { return new TreeNode(*this); }; virtual ~TreeNode() { // do not modify this insertion on OUT OUT << "Destroying TreeNode with " << childPVector.size() << " children."<< std::endl;
  • 2. // ***** Complete this member function ***** } void swap(TreeNode & other) // the swap member function (should never fail!) { // ***** fill this in if desired ***** } TreeNode & operator = (TreeNode other) // note: argument passed by value, copy made! { // ***** Complete this code ***** return *this; // by convention, always return *this } void add_childP(TreeNode* child) { /* ***** Complete this member function ***** */ } void add_children(const TreeNodePVect& childPV) { childPVector.insert(childPVector.end(), childPV.begin(), childPV.end()); } const TreeNodePVect& get_children() const { return childPVector; } TreeNode* traverse_children_post_order(traverse_func tf, action_func af) { for(auto childP : childPVector) { (childP->*tf)(this); // traverse child's children using tf } return (this->*af)(); } TreeNode* traverse_children_pre_order(traverse_func tf, action_func af) { // ***** Complete this member function ***** } TreeNode* traverse_children_in_order(traverse_func tf, action_func af) { // ***** Complete this member function ***** } TreeNode* count_action() { count++; return nullptr; }
  • 3. void count_traverse(const TreeNode*) { traverse_children_post_order(count_traverse, count_action); } void reset_count() { count = 0; } unsigned get_count() const { return count; } }; } #endif /* SRC_TREENODE_HPP_ */ #include "makeDirectoryTree.hpp" using namespace std; int doStuff() { // call function to build directory tree in memory auto root_dir1P = make_directory_tree(".", "test_dir"); if (root_dir1P) { root_dir1P->print_traverse(nullptr); OUT << endl; root_dir1P->reset_count(); root_dir1P->count_traverse(nullptr); OUT << "Count is " << root_dir1P->get_count() << " " << endl; auto root_dir2 = Directory(*root_dir1P); // copy construction root_dir2.print_traverse(nullptr); OUT << endl; auto root_dir3P = make_directory_tree("test_dir", "Lectures"); if (root_dir3P) { root_dir2 = *root_dir3P; // overloaded copy assignment operation OUT << endl; delete root_dir3P; OUT << endl; } root_dir2.print_traverse(nullptr); OUT << endl; delete root_dir1P; OUT << endl; } // destructor for root_dir2 called.
  • 4. OUT << endl; return 0; } // don't remove the below line. #ifndef DONT_RUN_MAIN int main() { int rv = doStuff(); #ifdef USE_OSS std::string s = oss.str(); cout << s << endl; #endif return rv; } #endif /* End of dirTree.cpp file */ * makeDirectoryTree.cpp #include #include #include // for find #include "makeDirectoryTree.hpp" // The below function may be replaced. Don't worry about trying to understand // this version. // traverse directories on the filesystem starting at a certain point and build // a directory tree in memory Directory *make_directory_tree(const std::string& path, const std::string& dir_name) { using namespace std; static vector ignore_list = {".",".."}; auto newPath = path + "" + dir_name; DIR *dir; if ((dir = opendir(newPath.c_str())) == nullptr) { OUT << newPath.c_str() << " Error while opening " << newPath << endl; return nullptr; }
  • 5. auto new_entity = new Directory(dir_name); struct dirent *dptr; while ((dptr = readdir(dir))) { if(find(ignore_list.begin(), ignore_list.end(), dptr->d_name) != ignore_list.end()) continue; auto fullPath = newPath + "" + dptr->d_name; struct stat filestat; stat(fullPath.c_str(), &filestat); if(S_ISDIR(filestat.st_mode)) { auto node = make_directory_tree(newPath, dptr->d_name); if (!node) // add directory with no files or subdirs in case of permission problem node = new Directory(dptr->d_name); new_entity->add_childP(node); } else { new_entity->add_file(dptr->d_name); } } return new_entity; } /* * makeDirectoryTree.hpp #ifndef SRC_MAKEDIRECTORYTREE_HPP_ #define SRC_MAKEDIRECTORYTREE_HPP_ #include "Directory.hpp" Directory *make_directory_tree(const std::string& path, const std::string& dir_name) ; #endif /* SRC_MAKEDIRECTORYTREE_HPP_ */ #include "TreeNode.hpp" #ifdef USE_OSS std::ostringstream oss; #define OUT oss #endif
  • 6. #ifndef SRC_DIRECTORY_HPP_ #define SRC_DIRECTORY_HPP_ #include "TreeNode.hpp" #include #include #include class Directory : public ensc251::TreeNode { typedef std::vector stringVect; private: std::string dir_name; stringVect file_names; public: Directory(std::string m_dir_name): dir_name(m_dir_name) {} Directory(std::string m_dir_name, stringVect m_file_names): dir_name(m_dir_name), file_names(m_file_names) {} virtual Directory* clone() const { /* ***** Complete this member function ***** */ }; void set_dir_name(const std::string& m_dir_name){ /* ***** Complete this member function ***** */ } const std::string & get_dir_name() { return dir_name; } void add_file(const std::string& m_fileName) { /* ***** Complete this member function ***** */ } void add_multiple_files(const stringVect& m_files) { file_names.insert(file_names.end(), m_files.begin(), m_files.end()); } const stringVect & get_files() const { return file_names; } TreeNode* print_action() { // Do not modify insertion on OUT in this member function! OUT << std::setw(20) << dir_name+"t|" << " "; OUT << this->childPVector.size() << " "; for (auto file : file_names) { OUT << " -" << file; } OUT << std::endl;
  • 7. return nullptr; } void print_traverse(const TreeNode*) { // ***** this needs work ***** // ***** encode the rules in the instructions traverse_children_post_order( static_cast(print_traverse), static_cast(print_action)); } }; #endif /* SRC_DIRECTORY_HPP_ */ Solution Step 1: You get the assembly code reference, particularly you will need to know which mnemonic corresponds to which machine code