Changeset 10 for trunk/lib/Directory.cc
- Timestamp:
- Dec 30, 2005, 12:57:57 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Directory.cc
r9 r10 2 2 3 3 #include "Directory.h" 4 #include "File.h" 4 5 #include "Node.h" 5 6 … … 16 17 : Node(path) 17 18 { 19 using namespace std; 18 20 DIR* directory=opendir(path.c_str()); 19 21 if (!directory) { 20 22 // Jari, throw exception 21 std::cerr << "ERROR: opendir() failed; terminating" << std::endl;23 cerr << "ERROR: opendir() failed; terminating" << endl; 22 24 exit(1); 23 25 } 26 vector<string> entries; 24 27 struct dirent* entry; 25 errno=0; 26 std::vector<std::string> entries; 28 errno=0; // Global variable used by C to track errors. 27 29 while ((entry=readdir(directory))) 28 entries.push_back(st d::string(entry->d_name)); // Jari, push backing30 entries.push_back(string(entry->d_name)); // Jari, push backing 29 31 if (errno) { 30 32 // Jari, throw exception 31 std::cerr << "ERROR: readdir() failure; terminating" << std::endl;33 cerr << "ERROR: readdir() failure; terminating" << endl; 32 34 exit(1); 33 35 } 34 36 closedir(directory); 35 37 36 copy(entries.begin(),entries.end(), 37 std::ostream_iterator<std::string>(std::cout,"\n")); 38 // Jari, change this to some STL algo? 39 for (vector<string>::iterator i=entries.begin(); i!=entries.end(); i++) 40 if ((*i)!=string(".") && (*i)!=string("..")) { 41 /// Jari, should test if directory in some other way 42 DIR* dirtest=opendir(i->c_str()); 43 if (!dirtest) 44 daughters_.push_back(new File(*i)); 45 else 46 daughters_.push_back(new Directory(*i)); 47 } 38 48 } 49 50 51 Directory::~Directory(void) 52 { 53 // Jari, change this to some STL algo? 54 for (std::vector<Node*>::iterator i=daughters_.begin(); 55 i!=daughters_.end(); i++) 56 delete *i; 57 } 58 39 59 40 60 bool Directory::parse(void) 41 61 { 42 62 // Jari, where is the include for for_each? 43 for_each( nn_.begin(),nn_.end(), std::mem_fun(&Node::parse));63 for_each(daughters_.begin(),daughters_.end(), std::mem_fun(&Node::parse)); 44 64 return true; 45 65 } 46 66 67 68 void Directory::print(void) { 69 // Jari, temporary using this to print directory tree 70 std::cout << "-------------- Directory '" << path_ << "'" << std::endl; 71 for_each(daughters_.begin(),daughters_.end(), std::mem_fun(&Node::print)); 72 } 73 47 74 }} // end of namespace svnstat and namespace theplu
Note: See TracChangeset
for help on using the changeset viewer.