Working on sessions.

git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@291 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2005-02-19 21:45:36 +00:00
parent a5f23adc7b
commit 5b050b594b
8 changed files with 168 additions and 1 deletions
+2
View File
@@ -1,6 +1,8 @@
noinst_LIBRARIES = libsub_utils.a
libsub_utils_a_SOURCES = \
directory.cc \
directory.h \
functional.h \
parse.cc \
parse.h \
+34
View File
@@ -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>());
}
}
+39
View File
@@ -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
View File
@@ -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();
}
}
+1
View File
@@ -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);
}