Changeset 10 for trunk/lib


Ignore:
Timestamp:
Dec 30, 2005, 12:57:57 PM (16 years ago)
Author:
Jari Häkkinen
Message:

Reading directory structure.

Location:
trunk/lib
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Directory.cc

    r9 r10  
    22
    33#include "Directory.h"
     4#include "File.h"
    45#include "Node.h"
    56
     
    1617    : Node(path)
    1718  {
     19    using namespace std;
    1820    DIR* directory=opendir(path.c_str());
    1921    if (!directory) {
    2022      // Jari, throw exception
    21       std::cerr << "ERROR: opendir() failed; terminating" << std::endl;
     23      cerr << "ERROR: opendir() failed; terminating" << endl;
    2224      exit(1);
    2325    }
     26    vector<string> entries;
    2427    struct dirent* entry;
    25     errno=0;
    26     std::vector<std::string> entries;
     28    errno=0;  // Global variable used by C to track errors.
    2729    while ((entry=readdir(directory)))
    28       entries.push_back(std::string(entry->d_name)); // Jari, push backing
     30      entries.push_back(string(entry->d_name)); // Jari, push backing
    2931    if (errno) {
    3032      // Jari, throw exception
    31       std::cerr << "ERROR: readdir() failure; terminating" << std::endl;
     33      cerr << "ERROR: readdir() failure; terminating" << endl;
    3234      exit(1);
    3335    }
    3436    closedir(directory);
    3537
    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      }
    3848  }
     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
    3959
    4060  bool Directory::parse(void)
    4161  {
    4262    // 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));
    4464    return true;
    4565  }
    4666
     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
    4774}} // end of namespace svnstat and namespace theplu
  • trunk/lib/Directory.h

    r9 r10  
    2525    /// @brief Destructor
    2626    ///
    27     ~Directory(void) {};
     27    ~Directory(void);
    2828
    2929    bool parse(void);
     30
     31    void print(void);
    3032
    3133  private:
     
    3537    Directory(const Directory&);
    3638
    37     std::vector<Node*> nn_;
     39    std::vector<Node*> daughters_;
    3840  };
    3941
  • trunk/lib/File.cc

    r9 r10  
    6262  }
    6363
     64  void File::print(void) {
     65    // Jari, temporary using this to print directory tree
     66    std::cout << "File '" << path_ << "'" << std::endl;
     67  }
     68
    6469}} // end of namespace svnstat and namespace theplu
  • trunk/lib/File.h

    r9 r10  
    2828    bool parse(void);
    2929
     30    void print(void);
     31
    3032  private:
    3133    ///
  • trunk/lib/Node.h

    r9 r10  
    4747    virtual bool parse(void)=0;
    4848
    49     ///
    50     /// Function printing HTML in directory dir
    51     ///
    52     void print(const std::string& dir);
     49    ///
     50    /// Function printing HTML in directory path
     51    ///
     52    virtual void print(void)=0;
    5353
    5454  protected:
Note: See TracChangeset for help on using the changeset viewer.