Changeset 9


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

Started work with reading file structure.

Location:
trunk
Files:
1 added
7 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
  • trunk/lib/Directory.h

    r7 r9  
    1111namespace svnstat{
    1212
    13   ///
    14   /// Class taking care of directories. Mainly containing pointers to
    15   /// files in directory.
    16   ///
    17   class Directory : public Node
    18   {
    19   public:
    20     ///
    21     /// @brief Constructor
    22     ///
    23     Directory(const std::string& name, Node* mother);
    24    
    25     bool parse(void);
    26  
    27   private:
    28     ///
    29     /// @brief Copy Constructor
    30     ///
    31     Directory(const Directory& other);
    32    
    33     std::vector<Node*> daughters_;
     13  ///
     14  /// Class taking care of directories.
     15  ///
     16  class Directory : public Node
     17  {
     18  public:
     19    ///
     20    /// @brief Constructor
     21    ///
     22    Directory(const std::string& path);
    3423
    35   };
     24    ///
     25    /// @brief Destructor
     26    ///
     27    ~Directory(void) {};
     28
     29    bool parse(void);
     30
     31  private:
     32    ///
     33    /// @brief Copy Constructor, not implemented
     34    ///
     35    Directory(const Directory&);
     36
     37    std::vector<Node*> nn_;
     38  };
    3639
    3740}} // end of namespace svnstat and namespace theplu
  • trunk/lib/File.cc

    r7 r9  
    1313namespace svnstat{
    1414
    15   File::File(const std::string& path, Node* mother)
    16     : Node(path,mother), binary_(false)
    17   {
    18   }
    19  
    2015  bool File::blame() const
    2116  {
  • trunk/lib/File.h

    r7 r9  
    1919    /// @brief Default Constructor
    2020    ///
    21     File(const std::string& name, Node*);
    22    
     21    inline File(const std::string& path) : Node(path), binary_(false) {}
     22
    2323    ///
    2424    /// Parsing out information from svn repository
     
    2929
    3030  private:
    31     ///
    32     /// @brief Copy Constructor
    33     ///
    34     File(const File& c);
     31    ///
     32    /// @brief Copy Constructor, not implemented
     33    ///
     34    File(const File&);
    3535
    3636    ///
  • trunk/lib/Node.cc

    r7 r9  
    1212namespace theplu{
    1313namespace svnstat{
    14 
    15   Node::Node(const std::string& path, Node* mother)
    16     : path_(path), mother_(mother)
    17   {
    18     info();
    19   }
    2014
    2115  std::vector<u_int> Node::accumulated(void) const
     
    5246      vec.resize(rev+1);
    5347      for (; i<rev; i++)
    54   vec[i]=0;
     48        vec[i]=0;
    5549      vec[rev]=1;
    5650    }
     
    5852      vec[rev]++;
    5953    stats_[user]=vec;
    60 
    61     if (mother_)
    62       mother_->add(user,rev);
    6354  }
    6455
     
    7869      getline(ss,tag,':');
    7970      if (tag == std::string("Repository UUID"))
    80   ss >> uuid_;
     71        ss >> uuid_;
    8172      else if (tag == std::string("Last Changed Author"))
    82   ss >> author_;
     73        ss >> author_;
    8374      else if (tag == std::string("Last Changed Rev"))
    84   ss >> revision_;
     75        ss >> revision_;
    8576    }
    8677   
  • trunk/lib/Node.h

    r7 r9  
    2020    /// @brief Constructor
    2121    ///
    22     Node(const std::string& name, Node*);
     22    inline Node(const std::string& path) : path_(path) { info(); }
    2323
    24     virtual ~Node() {};
     24    ///
     25    /// @brief Destructor
     26    ///
     27    virtual inline ~Node(void) {};
    2528
    2629    ///
     
    5861
    5962    std::string author_;
    60     Node* mother_;
    6163    std::string path_;
    6264    u_int revision_;
     
    6567    std::string uuid_;
    6668
    67   };
     69  private:
     70    ///
     71    /// @brief Copy Constructor, not implemented
     72    ///
     73    Node(const Node&);
     74  };
    6875
    6976}} // end of namespace svnstat and namespace theplu
  • trunk/test/Makefile.am

    r8 r9  
    33# $Id$
    44
    5 TESTS = svnstat
     5TESTS = svnstat tree
    66
    77check_PROGRAMS = $(TESTS)
    8 
    9 svnstat_SOURCES = svnstat.cc
    108
    119LDADD = @top_srcdir@/lib/libsvnstat.a
    1210
    1311INCLUDES = -I@top_srcdir@/lib
     12
     13svnstat_SOURCES = svnstat.cc
     14tree_SOURCES = tree.cc
Note: See TracChangeset for help on using the changeset viewer.