Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Directory.cc
r22 r23 6 6 7 7 #include <algorithm> 8 #include <fstream> 8 9 #include <iostream> 9 10 #include <iterator> … … 70 71 71 72 72 void Directory::print(void) { 73 // Jari, temporary using this to print directory tree 74 for_each(daughters_.begin(),daughters_.end(), std::mem_fun(&Node::print)); 73 void Directory::print(const std::string& path) const 74 { 75 // Peter, creation of dir should be done without system call 76 std::string system_call("mkdir " + path + name()+">& /dev/null"); 77 system(system_call.c_str()); 78 std::string output(path + name() + "/index.html"); 79 std::ofstream os(output.c_str()); 80 print_header(os); 81 os << std::endl; 82 stats_.print(os); 83 os << std::endl; 84 85 for (NodeConstIter_ i=daughters_.begin();i!=daughters_.end();i++){ 86 (*i)->print_link(os); 87 os << "<br/>" << std::endl; 88 } 89 90 print_footer(os); 91 os.close(); 92 93 for (NodeConstIter_ i=daughters_.begin();i!=daughters_.end();i++) 94 (*i)->print(path+name()+"/"); 95 } 96 97 void Directory::print_link(std::ostream& os) const 98 { 99 os << "<a href=\"" << name() << "/index.html\">" << name() << "</a>"; 75 100 } 76 101 -
trunk/lib/Directory.h
r22 r23 39 39 const Stats& parse(void); 40 40 41 void print(void); 41 void print(const std::string&) const; 42 43 void print_link(std::ostream&) const; 42 44 43 45 void purge(void); … … 50 52 51 53 typedef std::list<Node*>::iterator NodeIterator; 54 typedef std::list<Node*>::const_iterator NodeConstIter_; 52 55 std::list<Node*> daughters_; 53 56 }; -
trunk/lib/File.cc
r16 r23 22 22 } 23 23 24 void File::info(void) 25 { 26 std::string system_call = "svn info " + path_ + " > svnstat.tmp"; 27 int system_return = system(system_call.c_str()); 28 if (system_return){ 29 // Jari, throw exception. 30 std::cerr << "svnstat: svn info " << path_ << std::endl; 31 exit(-1); 32 } 33 std::ifstream is("svnstat.tmp"); 34 std::string line; 35 while (getline(is,line)){ 36 std::stringstream ss(line); 37 std::string tag; 38 getline(ss,tag,':'); 39 if (tag == std::string("Last Changed Author")) 40 ss >> author_; 41 else if (tag == std::string("Last Changed Rev")) 42 ss >> revision_; 43 } 44 } 45 46 24 47 const Stats& File::parse(void) 25 48 { 26 49 stats_.reset(); 50 info(); 51 27 52 if (binary_){ 28 53 stats_.add(author_,revision_); … … 41 66 getline(is,line,' '); 42 67 if (line==std::string("binary")){ 43 is.close();44 binary_ = true;45 return parse();68 is.close(); 69 binary_ = true; 70 return parse(); 46 71 } 47 72 } … … 51 76 while (getline(is,line, '\n')){ 52 77 if (!line.size()) // skip empty line 53 continue;78 continue; 54 79 std::stringstream ss(line); 55 80 u_int revision; … … 63 88 } 64 89 65 void File::print(void) { 66 // Jari, temporary using this to print directory tree 67 std::cout << "File '" << path_ << "'" << std::endl; 90 void File::print(const std::string& path) const 91 { 92 std::string output(path + name() + ".html"); 93 std::ofstream os(output.c_str()); 94 print_header(os); 95 os << std::endl; 96 stats_.print(os); 97 os << std::endl; 98 print_footer(os); 99 os.close(); 100 101 } 102 103 void File::print_link(std::ostream& os) const 104 { 105 os << "<a href=\"" << name() << ".html\">" << name() << "</a>"; 68 106 } 69 107 -
trunk/lib/File.h
r15 r23 26 26 const Stats& parse(void); 27 27 28 void print(void); 28 /// 29 /// 30 /// 31 void print(const std::string& path) const; 32 33 /// 34 /// 35 /// 36 void print_link(std::ostream&) const; 29 37 30 38 private: 31 ///32 /// @brief Copy Constructor, not implemented33 ///34 File(const File&);35 36 39 /// 37 40 /// @brief Parsing svn blame output … … 41 44 bool blame(void) const; 42 45 43 46 /// 47 /// @brief Copy Constructor, not implemented 48 /// 49 File(const File&); 50 51 /// 52 /// Extracts information from 'svn info <node>' 53 /// 54 /// @note <node> must be in subversion control. 55 /// 56 void info(void); 57 58 std::string author_; 44 59 bool binary_; 60 u_int revision_; 45 61 46 62 }; -
trunk/lib/Node.cc
r20 r23 4 4 #include "utility.h" 5 5 6 #include <ctime> 6 7 #include <fstream> 7 8 #include <iostream> … … 11 12 namespace svnstat{ 12 13 13 void Node::info(void) 14 15 std::string system_call = "svn info " + path_ + " > svnstat.tmp";16 int system_return = system(system_call.c_str());17 if (system_return){ 18 // Jari, throw exception.19 std::cerr << "Error: svn info " << path_ << std::endl; 20 exit(-1); 21 } 22 std::cerr << "Ok: svn info " << path_ << std::endl; 23 std::ifstream is("svnstat.tmp"); 24 std::string line; 25 while (getline(is,line)){ 26 std::stringstream ss(line); 27 std::string tag; 28 getline(ss,tag,':'); 29 if (tag == std::string("Repository UUID")) 30 ss >> uuid_;31 else if (tag == std::string("Last Changed Author")) 32 ss >> author_;33 else if (tag == std::string("Last Changed Rev")) 34 ss >> revision_;35 } 36 14 std::string Node::name(void) const 15 { 16 std::stringstream ss(path_); 17 std::string name; 18 while (getline(ss,name,'/')) {} 19 return name; 20 } 21 22 23 void Node::print_footer(std::ostream& os) const 24 { 25 os << "</body>\n" 26 << "</html>"; 27 } 28 29 30 void Node::print_header(std::ostream& os) const 31 { 32 os << "<html>\n" 33 << "<head>\n" 34 << "<title> svnstat " << name() << "\n" 35 << "</head>\n" 36 << "<body bgcolor='FFFBFB'\n"; 37 } 37 38 38 39 -
trunk/lib/Node.h
r20 r23 27 27 virtual inline ~Node(void) {}; 28 28 29 ///30 /// Extracts information from 'svn info <node>'31 ///32 /// @note <node> must be in subversion control.33 ///34 void info(void);35 36 29 /// 37 30 /// @brief parsing file using svn blame. … … 42 35 /// Function printing HTML in directory path 43 36 /// 44 virtual void print( void)=0;37 virtual void print(const std::string& path) const=0; 45 38 39 /// 40 /// Prints a html link. 41 /// 42 virtual void print_link(std::ostream&) const=0; 43 44 /// 45 /// 46 /// 47 // Peter to Jari, inlining virtual functions? 46 48 inline virtual void purge(void) { /* Nothing to be done */ }; 47 49 … … 55 57 56 58 protected: 57 std::string author_; 59 /// 60 /// Function returning everything after the last '/' 61 /// 62 /// @return name of node (not full path) 63 /// 64 std::string name(void) const; 65 66 /// 67 /// @brief print html footer of page 68 /// 69 void print_footer(std::ostream&) const; 70 71 /// 72 /// @brief print html header of page 73 /// 74 void print_header(std::ostream&) const; 75 58 76 std::string path_; 59 u_int revision_;60 77 Stats stats_; 61 std::string uuid_;62 78 63 79 private: -
trunk/lib/Stats.cc
r14 r23 7 7 #include <numeric> 8 8 #include <string> 9 #include <utility> 9 10 #include <vector> 11 12 #include <iostream> 10 13 11 14 namespace theplu{ … … 59 62 } 60 63 64 void Stats::print(std::ostream& os) const 65 { 66 std::vector<std::pair<std::string, std::vector<u_int> > > accum; 67 for (MapConstIter_ i= map_.begin(); i != map_.end(); i++){ 68 std::pair<std::string, std::vector<u_int> > element(*i); 69 std::partial_sum(element.second.begin(),element.second.end(), 70 element.second.begin()); 71 accum.push_back(element); 72 } 73 sort(accum.begin(),accum.end(), CodingMore()); 74 os << "<table>\n"; 75 for (size_t i = 0; i<accum.size(); i++){ 76 os << "<tr><td>\n" << accum[i].first << "</td><td>" 77 << accum[i].second.back() << "</td></tr>"; 78 } 79 os << "</table>\n"; 80 81 os << "<p>[Plot to be here.]</p>\n"; 82 } 83 61 84 Stats& Stats::operator+=(const Stats& other) 62 85 { 63 for ( _MapConstIto_i= other.map_.begin(); o_i != other.map_.end(); ++o_i)86 for (MapConstIter_ o_i= other.map_.begin(); o_i != other.map_.end(); ++o_i) 64 87 { 65 std::pair< _MapIt,bool> result = map_.insert(*o_i);88 std::pair<MapIter_,bool> result = map_.insert(*o_i); 66 89 if (!result.second) 67 map_[(*(result.first)).first] =68 90 map_[(*(result.first)).first] = 91 VectorPlus<u_int>()( (*(result.first)).second, (*o_i).second ); 69 92 70 93 } -
trunk/lib/Stats.h
r14 r23 22 22 23 23 /// 24 /// @brief adding a line to user from revision to the stats 25 /// 26 void add(const std::string& user, const u_int& revision); 27 28 /// 29 /// @bief print statistics 30 /// 31 void print(std::ostream&) const; 32 33 /// 34 /// @brief Clear all statistics 35 /// 36 inline void reset(void) { map_.clear(); } 37 38 /// 39 /// @return resulting Stats 40 /// 41 Stats& operator+=(const Stats&); 42 43 private: 44 /// 45 /// Copy constructor (not implemented) 46 /// 47 Stats(const Stats& other); 48 49 /// 24 50 /// @return accumulated vector of total 25 51 /// … … 31 57 std::vector<u_int> accumulated(const std::string& user); 32 58 33 ///34 /// @brief adding a line to user from revision to the stats35 ///36 void add(const std::string& user, const u_int& revision);37 38 inline void reset(void) { map_.clear(); }39 40 41 ///42 /// @return resulting Stats43 ///44 Stats& operator+=(const Stats&);45 46 private:47 Stats(const Stats& other);48 49 59 // Peter, if the vector is sparse make it a map 50 typedef std::map<std::string, std::vector<u_int> > _Map;51 typedef _Map::iterator _MapIt;52 typedef _Map::const_iterator _MapConstIt;53 _Mapmap_;60 typedef std::map<std::string, std::vector<u_int> > Map_; 61 typedef Map_::iterator MapIter_; 62 typedef Map_::const_iterator MapConstIter_; 63 Map_ map_; 54 64 }; 55 65 }} -
trunk/lib/utility.h
r14 r23 6 6 #include <algorithm> 7 7 #include <functional> 8 #include <string> 8 9 #include <utility> 9 10 #include <vector> … … 12 13 namespace svnstat{ 13 14 14 15 16 17 18 19 20 21 22 23 24 const std::vector<T>& v) const25 26 if ( u.size() > v.size() ){27 28 29 30 31 }15 /// 16 /// Calculating sum of two vectors. 17 /// 18 /// @return resulting vector 19 /// 20 template <class T > 21 struct VectorPlus : 22 public std::binary_function<std::vector<T>,std::vector<T>,std::vector<T> > 23 { 24 std::vector<T> operator()(const std::vector<T>& u, 25 const std::vector<T>& v) const 26 { 27 if ( u.size() > v.size() ){ 28 std::vector<T> res(u.size()); 29 transform(u.begin(), u.end(), v.begin(), res.begin(), std::plus<T>()); 30 copy(u.begin()+v.size(), u.end(), res.begin()+v.size()); 31 return res; 32 } 32 33 33 std::vector<T> res(v.size());34 transform(v.begin(), v.end(), u.begin(), res.begin(), std::plus<T>());35 if ( v.size() > u.size() )36 copy(u.begin()+v.size(), u.end(), res.begin()+v.size());37 return res;38 34 std::vector<T> res(v.size()); 35 transform(v.begin(), v.end(), u.begin(), res.begin(), std::plus<T>()); 36 if ( v.size() > u.size() ) 37 copy(v.begin()+u.size(), v.end(), res.begin()+u.size()); 38 return res; 39 } 39 40 40 41 }; 41 42 42 43 /// … … 44 45 /// 45 46 template <class Key, class T> 46 struct PairValuePlus : 47 public std::binary_function<std::vector<T>, 48 std::pair<const Key, std::vector<T> >, 49 std::vector<T> > 50 { 51 std::vector<T> operator()(const std::vector<T>& sum, 52 const std::pair<const Key,std::vector<T> >& p) 53 { 54 return VectorPlus<T>()(sum, p.second); 55 } 56 }; 47 struct PairValuePlus : 48 public std::binary_function<std::vector<T>, 49 std::pair<const Key, std::vector<T> >, 50 std::vector<T> > 51 { 52 std::vector<T> operator()(const std::vector<T>& sum, 53 const std::pair<const Key,std::vector<T> >& p) 54 { 55 return VectorPlus<T>()(sum, p.second); 56 } 57 }; 58 59 /// 60 struct CodingMore : 61 public std::binary_function<std::pair<std::string,std::vector<u_int> >, 62 std::pair<std::string,std::vector<u_int> >, 63 bool > 64 { 65 inline bool operator() 66 (const std::pair<std::string,std::vector<u_int> >& a, 67 const std::pair<std::string,std::vector<u_int> >& b) 68 { 69 if (a.second.back() > b.second.back()) 70 return true; 71 else if (a.second.back() < b.second.back()) 72 return false; 73 return a.first < b.first; 74 } 75 }; 76 57 77 }} 58 78 59 #endif // end of namespace svnstat end of namespace theplu 79 // end of namespace svnstat end of namespace theplu 80 #endif
Note: See TracChangeset
for help on using the changeset viewer.