Changeset 1022
- Timestamp:
- 12/23/07 19:12:23 (2 years ago)
- Location:
- trunk
- Files:
-
- 12 modified
-
libtorrent/rak/algorithm.h (modified) (3 diffs)
-
rtorrent/rak/algorithm.h (modified) (3 diffs)
-
rtorrent/src/command_network.cc (modified) (1 diff)
-
rtorrent/src/core/download_store.cc (modified) (4 diffs)
-
rtorrent/src/core/download_store.h (modified) (2 diffs)
-
rtorrent/src/core/manager.cc (modified) (3 diffs)
-
rtorrent/src/input/path_input.cc (modified) (5 diffs)
-
rtorrent/src/main.cc (modified) (1 diff)
-
rtorrent/src/ui/download_list.cc (modified) (1 diff)
-
rtorrent/src/ui/element_string_list.h (modified) (1 diff)
-
rtorrent/src/utils/directory.cc (modified) (3 diffs)
-
rtorrent/src/utils/directory.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtorrent/rak/algorithm.h
r939 r1022 123 123 // Count the number of elements from the start of the containers to 124 124 // the first inequal element. 125 template <typename _InputIter >126 typename std::iterator_traits<_InputIter >::difference_type127 count_base(_InputIter __first1, _InputIter__last1,128 _InputIter __first2, _InputIter__last2) {125 template <typename _InputIter1, typename _InputIter2> 126 typename std::iterator_traits<_InputIter1>::difference_type 127 count_base(_InputIter1 __first1, _InputIter1 __last1, 128 _InputIter2 __first2, _InputIter2 __last2) { 129 129 130 typename std::iterator_traits<_InputIter >::difference_type __n = 0;130 typename std::iterator_traits<_InputIter1>::difference_type __n = 0; 131 131 132 132 for ( ;__first1 != __last1 && __first2 != __last2; ++__first1, ++__first2, ++__n) … … 137 137 } 138 138 139 template <typename _ InputIter>140 typename std::iterator_traits<_InputIter>::value_type 141 make_base(_InputIter __first, _InputIter __last ) {139 template <typename _Return, typename _InputIter, typename _Ftor> 140 _Return 141 make_base(_InputIter __first, _InputIter __last, _Ftor __ftor) { 142 142 if (__first == __last) 143 143 return ""; 144 144 145 typename std::iterator_traits<_InputIter>::value_type __base = *__first++;145 _Return __base = __ftor(*__first++); 146 146 147 147 for ( ;__first != __last; ++__first) { 148 148 typename std::iterator_traits<_InputIter>::difference_type __pos = count_base(__base.begin(), __base.end(), 149 __f irst->begin(), __first->end());149 __ftor(*__first).begin(), __ftor(*__first).end()); 150 150 151 151 if (__pos < (typename std::iterator_traits<_InputIter>::difference_type)__base.size()) … … 156 156 } 157 157 158 159 160 158 } 161 159 -
trunk/rtorrent/rak/algorithm.h
r938 r1022 123 123 // Count the number of elements from the start of the containers to 124 124 // the first inequal element. 125 template <typename _InputIter >126 typename std::iterator_traits<_InputIter >::difference_type127 count_base(_InputIter __first1, _InputIter__last1,128 _InputIter __first2, _InputIter__last2) {125 template <typename _InputIter1, typename _InputIter2> 126 typename std::iterator_traits<_InputIter1>::difference_type 127 count_base(_InputIter1 __first1, _InputIter1 __last1, 128 _InputIter2 __first2, _InputIter2 __last2) { 129 129 130 typename std::iterator_traits<_InputIter >::difference_type __n = 0;130 typename std::iterator_traits<_InputIter1>::difference_type __n = 0; 131 131 132 132 for ( ;__first1 != __last1 && __first2 != __last2; ++__first1, ++__first2, ++__n) … … 137 137 } 138 138 139 template <typename _ InputIter>140 typename std::iterator_traits<_InputIter>::value_type 141 make_base(_InputIter __first, _InputIter __last ) {139 template <typename _Return, typename _InputIter, typename _Ftor> 140 _Return 141 make_base(_InputIter __first, _InputIter __last, _Ftor __ftor) { 142 142 if (__first == __last) 143 143 return ""; 144 144 145 typename std::iterator_traits<_InputIter>::value_type __base = *__first++;145 _Return __base = __ftor(*__first++); 146 146 147 147 for ( ;__first != __last; ++__first) { 148 148 typename std::iterator_traits<_InputIter>::difference_type __pos = count_base(__base.begin(), __base.end(), 149 __f irst->begin(), __first->end());149 __ftor(*__first).begin(), __ftor(*__first).end()); 150 150 151 151 if (__pos < (typename std::iterator_traits<_InputIter>::difference_type)__base.size()) … … 156 156 } 157 157 158 159 160 158 } 161 159 -
trunk/rtorrent/src/command_network.cc
r1013 r1022 39 39 #include <functional> 40 40 #include <rak/address_info.h> 41 #include <rak/file_stat.h>42 41 #include <rak/path.h> 43 42 #include <torrent/connection_manager.h> -
trunk/rtorrent/src/core/download_store.cc
r938 r1022 51 51 #include <torrent/resume.h> 52 52 #include <torrent/object_stream.h> 53 54 #include "utils/directory.h" 53 55 54 56 #include "download.h" … … 145 147 } 146 148 149 // This also needs to check that it isn't a directory. 150 bool 151 not_correct_format(const utils::directory_entry& entry) { 152 return !DownloadStore::is_correct_format(entry.d_name); 153 } 154 147 155 utils::Directory 148 156 DownloadStore::get_formated_entries() { … … 150 158 return utils::Directory(); 151 159 152 utils::Directory d(m_path); 160 utils::Directory d; 161 d.set_path(m_path); 153 162 154 163 if (!d.update()) 155 164 throw torrent::storage_error("core::DownloadStore::update() could not open directory \"" + m_path + "\""); 156 165 157 d.erase(std::remove_if(d.begin(), d.end(), std:: not1(std::ptr_fun(&DownloadStore::is_correct_format))), d.end());166 d.erase(std::remove_if(d.begin(), d.end(), std::ptr_fun(¬_correct_format)), d.end()); 158 167 159 168 return d; … … 161 170 162 171 bool 163 DownloadStore::is_correct_format( std::stringf) {172 DownloadStore::is_correct_format(const std::string& f) { 164 173 if (f.size() != 48 || f.substr(40) != ".torrent") 165 174 return false; -
trunk/rtorrent/src/core/download_store.h
r938 r1022 40 40 #include <string> 41 41 42 #include "utils/directory.h"43 42 #include "utils/lockfile.h" 43 44 namespace utils { 45 class Directory; 46 } 44 47 45 48 namespace core { … … 64 67 utils::Directory get_formated_entries(); 65 68 69 static bool is_correct_format(const std::string& f); 70 66 71 private: 67 static bool is_correct_format(std::string f);68 72 std::string create_filename(Download* d); 69 73 -
trunk/rtorrent/src/core/manager.cc
r1013 r1022 57 57 58 58 #include "rpc/parse_commands.h" 59 #include "utils/directory.h" 59 60 60 61 #include "globals.h" … … 418 419 } 419 420 421 utils::Directory 422 path_expand_transform(std::string path, const utils::directory_entry& entry) { 423 return path + entry.d_name; 424 } 425 420 426 // Move this somewhere better. 421 427 void … … 455 461 // starts with the same. 456 462 itr->update(r.pattern()[0] != '.'); 457 itr->erase(std::remove_if(itr->begin(), itr->end(), std::not1(r)), itr->end());458 459 std::transform(itr->begin(), itr->end(), std::back_inserter(nextCache), std::bind1st(std::plus<std::string>(), itr->get_path() + "/"));463 itr->erase(std::remove_if(itr->begin(), itr->end(), rak::on(rak::mem_ref(&utils::directory_entry::d_name), std::not1(r))), itr->end()); 464 465 std::transform(itr->begin(), itr->end(), std::back_inserter(nextCache), rak::bind1st(std::ptr_fun(&path_expand_transform), itr->get_path() + "/")); 460 466 } 461 467 -
trunk/rtorrent/src/input/path_input.cc
r938 r1022 39 39 #include <functional> 40 40 #include <rak/algorithm.h> 41 #include <rak/f ile_stat.h>41 #include <rak/functional.h> 42 42 #include <rak/path.h> 43 44 #include <sys/types.h> 45 #include <sys/dir.h> 43 46 44 47 #include "path_input.h" … … 69 72 70 73 struct _transform_filename { 71 _transform_filename(const std::string& base) : m_base(base) {} 72 73 void operator () (std::string& filename) { 74 rak::file_stat fs; 75 76 if (!fs.update(rak::path_expand(m_base + filename))) 77 return; 78 79 else if (fs.is_directory()) 80 filename += '/'; 74 void operator () (utils::directory_entry& entry) { 75 if (entry.d_type == DT_DIR) 76 entry.d_name += '/'; 81 77 } 82 83 const std::string& m_base;84 78 }; 85 79 … … 96 90 } 97 91 98 std::for_each(dir.begin(), dir.end(), _transform_filename( str().substr(0, dirEnd)));92 std::for_each(dir.begin(), dir.end(), _transform_filename()); 99 93 100 94 Range r = find_incomplete(dir, str().substr(dirEnd, get_pos())); … … 103 97 return; // Show some nice colors here. 104 98 105 std::string base = rak::make_base (r.first, r.second);99 std::string base = rak::make_base<std::string>(r.first, r.second, rak::const_mem_ref(&utils::directory_entry::d_name)); 106 100 107 101 // Clear the path after the cursor to make this code cleaner. It's … … 134 128 } 135 129 130 inline bool 131 find_complete_compare(const utils::directory_entry& complete, const std::string& base) { 132 return complete.d_name.compare(0, base.size(), base); 133 } 134 135 inline bool 136 find_complete_not_compare(const utils::directory_entry& complete, const std::string& base) { 137 return !complete.d_name.compare(0, base.size(), base); 138 } 139 136 140 PathInput::Range 137 141 PathInput::find_incomplete(utils::Directory& d, const std::string& f) { 138 142 Range r; 139 143 140 r.first = std::find_if(d.begin(), d.end(), std::bind2nd(rak::compare_base<std::string>(), f));141 r.second = std::find_if(r.first, d.end(), std::not1(std::bind2nd(rak::compare_base<std::string>(), f)));144 r.first = std::find_if(d.begin(), d.end(), rak::bind2nd(std::ptr_fun(&find_complete_not_compare), f)); 145 r.second = std::find_if(r.first, d.end(), rak::bind2nd(std::ptr_fun(&find_complete_compare), f)); 142 146 143 147 return r; -
trunk/rtorrent/src/main.cc
r1020 r1022 102 102 load_session_torrents(Control* c) { 103 103 // Load session torrents. 104 std:: list<std::string> l = c->core()->download_store()->get_formated_entries().make_list();105 106 for (std:: list<std::string>::iterator first = l.begin(), last = l.end(); first != last; ++first) {104 std::vector<std::string> l = c->core()->download_store()->get_formated_entries().make_list(); 105 106 for (std::vector<std::string>::iterator first = l.begin(), last = l.end(); first != last; ++first) { 107 107 core::DownloadFactory* f = new core::DownloadFactory(c->core()); 108 108 -
trunk/rtorrent/src/ui/download_list.cc
r992 r1022 256 256 257 257 input->signal_show_range().connect(sigc::hide(sigc::hide(sigc::bind(sigc::mem_fun(*this, &DownloadList::activate_display), DISPLAY_STRING_LIST)))); 258 input->signal_show_range().connect(sigc::mem_fun(*esl, &ElementStringList::set_range <utils::Directory::iterator>));258 input->signal_show_range().connect(sigc::mem_fun(*esl, &ElementStringList::set_range_dirent<utils::Directory::iterator>)); 259 259 260 260 input->bindings()['\n'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_exit_input), type); -
trunk/rtorrent/src/ui/element_string_list.h
r938 r1022 74 74 } 75 75 76 // A hack, clean this up. 77 template <typename InputIter> 78 void set_range_dirent(InputIter first, InputIter last) { 79 m_list.clear(); 80 81 while (first != last) 82 m_list.push_back((first++)->d_name); 83 84 m_window->set_range(m_list.begin(), m_list.end()); 85 m_window->mark_dirty(); 86 } 87 76 88 void next_screen(); 77 89 -
trunk/rtorrent/src/utils/directory.cc
r938 r1022 47 47 namespace utils { 48 48 49 // Keep this? 49 50 bool 50 51 Directory::is_valid() const { … … 58 59 } 59 60 61 // Update should take various flags and sort functors. 60 62 bool 61 63 Directory::update(bool hideDot) { … … 70 72 struct dirent* ent; 71 73 74 // Err... let us use getdirentries here instead. 72 75 while ((ent = readdir(d)) != NULL) { 76 // Don't construct it here, check the const char. 73 77 std::string de(ent->d_name); 74 78 75 if (!de.empty() && (!hideDot || de[0] != '.')) 76 Base::push_back(ent->d_name); 79 if (!de.empty() && (!hideDot || de[0] != '.')) { 80 iterator itr = base_type::insert(end(), value_type()); 81 82 itr->d_fileno = ent->d_fileno; 83 itr->d_reclen = ent->d_reclen; 84 itr->d_type = ent->d_type; 85 itr->d_name = de; 86 } 77 87 } 78 88 79 89 closedir(d); 80 Base::sort(std::less<std::string>());90 std::sort(begin(), end()); 81 91 82 92 return true; 83 93 } 84 94 85 Directory::Base 95 std::vector<std::string> 86 96 Directory::make_list() { 87 Base l; 97 std::vector<std::string> l; 98 l.reserve(size()); 88 99 89 for ( Base::iterator itr = begin(); itr != end(); ++itr)90 l.push_back(m_path + *itr);100 for (iterator itr = begin(); itr != end(); ++itr) 101 l.push_back(m_path + itr->d_name); 91 102 92 103 return l; -
trunk/rtorrent/src/utils/directory.h
r938 r1022 39 39 40 40 #include <string> 41 #include < list>41 #include <vector> 42 42 43 43 namespace utils { 44 44 45 class Directory : private std::list<std::string> { 45 struct directory_entry { 46 // The name and types should match POSIX. 47 uint32_t d_fileno; 48 uint16_t d_reclen; 49 uint8_t d_type; 50 51 std::string d_name; 52 }; 53 54 class Directory : private std::vector<directory_entry> { 46 55 public: 47 typedef std:: list<std::string> Base;56 typedef std::vector<directory_entry> base_type; 48 57 49 using Base::iterator; 50 using Base::const_iterator; 51 using Base::reverse_iterator; 52 using Base::const_reverse_iterator; 58 using base_type::iterator; 59 using base_type::const_iterator; 60 using base_type::reverse_iterator; 61 using base_type::const_reverse_iterator; 62 using base_type::value_type; 53 63 54 using Base::begin;55 using Base::end;56 using Base::rbegin;57 using Base::rend;64 using base_type::begin; 65 using base_type::end; 66 using base_type::rbegin; 67 using base_type::rend; 58 68 59 using Base::empty;60 using Base::size;69 using base_type::empty; 70 using base_type::size; 61 71 62 using Base::erase;72 using base_type::erase; 63 73 64 74 Directory() {} … … 69 79 bool update(bool hideDot = true); 70 80 81 // Ergh... 71 82 const std::string& get_path() { return m_path; } 83 void set_path(const std::string& path) { m_path = path; } 72 84 73 85 // Make a list with full path names. 74 Base make_list(); 86 // 87 // Fix the uses of this, real bad stuff. 88 std::vector<std::string> make_list(); 75 89 76 90 private: … … 78 92 }; 79 93 94 inline bool operator == (const directory_entry& left, const directory_entry& right) { return left.d_name == right.d_name; } 95 inline bool operator != (const directory_entry& left, const directory_entry& right) { return left.d_name != right.d_name; } 96 inline bool operator < (const directory_entry& left, const directory_entry& right) { return left.d_name < right.d_name; } 97 inline bool operator > (const directory_entry& left, const directory_entry& right) { return left.d_name > right.d_name; } 98 inline bool operator <= (const directory_entry& left, const directory_entry& right) { return left.d_name <= right.d_name; } 99 inline bool operator >= (const directory_entry& left, const directory_entry& right) { return left.d_name >= right.d_name; } 100 80 101 } 81 102
