mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-13 21:52:30 +00:00
Working on sessions.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@291 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
noinst_LIBRARIES = libsub_utils.a
|
||||
|
||||
libsub_utils_a_SOURCES = \
|
||||
directory.cc \
|
||||
directory.h \
|
||||
functional.h \
|
||||
parse.cc \
|
||||
parse.h \
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <stdexcept>
|
||||
#include <dirent.h>
|
||||
|
||||
#include "directory.h"
|
||||
|
||||
namespace utils {
|
||||
|
||||
void
|
||||
Directory::update() {
|
||||
if (m_path.empty())
|
||||
throw std::logic_error("Directory::update() tried to open an empty path");
|
||||
|
||||
DIR* d = opendir(m_path.c_str());
|
||||
|
||||
if (d == NULL)
|
||||
throw std::runtime_error("Directory::update() could not open directory");
|
||||
|
||||
struct dirent* ent;
|
||||
|
||||
while ((ent = readdir(d)) != NULL) {
|
||||
std::string de(ent->d_name);
|
||||
|
||||
if (de != "." && de != "..")
|
||||
Base::push_back(ent->d_name);
|
||||
}
|
||||
|
||||
std::sort(begin(), end(), std::less<std::string>());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#ifndef RTORRENT_UTILS_DIRECTORY_H
|
||||
#define RTORRENT_UTILS_DIRECTORY_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace utils {
|
||||
|
||||
class Directory : private std::vector<std::string> {
|
||||
public:
|
||||
typedef std::vector<std::string> Base;
|
||||
|
||||
using Base::iterator;
|
||||
using Base::const_iterator;
|
||||
using Base::reverse_iterator;
|
||||
using Base::const_reverse_iterator;
|
||||
|
||||
using Base::begin;
|
||||
using Base::end;
|
||||
using Base::rbegin;
|
||||
using Base::rend;
|
||||
|
||||
using Base::empty;
|
||||
using Base::size;
|
||||
|
||||
Directory() {}
|
||||
Directory(const std::string& path) : m_path(path) {}
|
||||
|
||||
void update();
|
||||
|
||||
const std::string& get_path() { return m_path; }
|
||||
|
||||
private:
|
||||
std::string m_path;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
+12
-1
@@ -10,7 +10,6 @@ std::string
|
||||
escape_string(const std::string& src) {
|
||||
std::stringstream stream;
|
||||
|
||||
// TODO: Correct would be to save the state.
|
||||
stream << std::hex << std::uppercase;
|
||||
|
||||
for (std::string::const_iterator itr = src.begin(); itr != src.end(); ++itr)
|
||||
@@ -25,4 +24,16 @@ escape_string(const std::string& src) {
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
std::string
|
||||
string_to_hex(const std::string& src) {
|
||||
std::stringstream stream;
|
||||
|
||||
stream << std::hex << std::uppercase;
|
||||
|
||||
for (std::string::const_iterator itr = src.begin(); itr != src.end(); ++itr)
|
||||
stream << ((unsigned char)*itr >> 4) << ((unsigned char)*itr & 0xf);
|
||||
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace utils {
|
||||
// Various functinos for manipulating strings.
|
||||
|
||||
std::string escape_string(const std::string& src);
|
||||
std::string string_to_hex(const std::string& src);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user