Changeset 9 for trunk/lib/Directory.cc


Ignore:
Timestamp:
Dec 30, 2005, 9:24:00 AM (17 years ago)
Author:
Jari Häkkinen
Message:

Started work with reading file structure.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Directory.cc

    r7 r9  
    44#include "Node.h"
    55
     6#include <iostream>
     7#include <iterator>
     8
     9#include <errno.h>  // Needed to check error state below.
     10#include <dirent.h>
     11
    612namespace theplu{
    713namespace svnstat{
    814
    9   Directory::Directory(const std::string& name, Node* mother)
    10     : Node(name,mother)
    11   {
    12   }
     15  Directory::Directory(const std::string& path)
     16    : Node(path)
     17  {
     18    DIR* directory=opendir(path.c_str());
     19    if (!directory) {
     20      // Jari, throw exception
     21      std::cerr << "ERROR: opendir() failed; terminating" << std::endl;
     22      exit(1);
     23    }
     24    struct dirent* entry;
     25    errno=0;
     26    std::vector<std::string> entries;
     27    while ((entry=readdir(directory)))
     28      entries.push_back(std::string(entry->d_name)); // Jari, push backing
     29    if (errno) {
     30      // Jari, throw exception
     31      std::cerr << "ERROR: readdir() failure; terminating" << std::endl;
     32      exit(1);
     33    }
     34    closedir(directory);
    1335
    14   bool Directory::parse(void)
    15   {
    16     for_each(daughters_.begin(),daughters_.end(), std::mem_fun(&Node::parse));
    17     return true;
    18   }
     36    copy(entries.begin(),entries.end(),
     37         std::ostream_iterator<std::string>(std::cout,"\n"));
     38  }
     39
     40  bool Directory::parse(void)
     41  {
     42    // Jari, where is the include for for_each?
     43    for_each(nn_.begin(),nn_.end(), std::mem_fun(&Node::parse));
     44    return true;
     45  }
    1946
    2047}} // end of namespace svnstat and namespace theplu
Note: See TracChangeset for help on using the changeset viewer.