summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-01-02 01:16:35 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2011-01-02 01:16:35 +0100
commit3d5901b73cc4e46e57233ea3ccc9b27ffba4c7df (patch)
tree9a3a3d79f6f8acac9a4298a719dcfcf42fa39596
parent75f14984fa648c66ba6677f0d7c84429169e95f1 (diff)
Moved MusicDirectory conversion code to music::get_directory().
-rw-r--r--commands.cpp7
-rw-r--r--music.cpp11
-rw-r--r--music.h2
3 files changed, 16 insertions, 4 deletions
diff --git a/commands.cpp b/commands.cpp
index 2401690..f37f78c 100644
--- a/commands.cpp
+++ b/commands.cpp
@@ -1,7 +1,6 @@
#include "commands.h"
#include "music.h"
-#include <boost/cast.hpp>
#include <boost/format.hpp>
#include <boost/algorithm/string/join.hpp>
@@ -12,12 +11,12 @@ static std::vector<std::string> ls(const std::vector<std::string>& args) {
throw commands::CommandException("usage: ls DIR");
}
- MusicListing::p ml = music::get(args[1]);
- if(!ml || !fs::is_directory(ml->path)) {
+ MusicDirectory::p dir = music::get_directory(args[1]);
+ if(!dir) {
throw commands::CommandException("no such directory");
}
+ std::cout << dir->path << std::endl;
std::vector<std::string> result;
- MusicDirectory *dir = boost::polymorphic_downcast<MusicDirectory*>(&(*ml));
for(MusicDirectory::PathListings::iterator it = dir->directories.begin(); it != dir->directories.end(); it++) {
std::string rel_path = it->string().substr(music::root_directory.string().size());
result.push_back(rel_path);
diff --git a/music.cpp b/music.cpp
index 772ae9c..6265771 100644
--- a/music.cpp
+++ b/music.cpp
@@ -9,6 +9,7 @@
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
+#include <boost/cast.hpp>
#include <boost/filesystem/fstream.hpp>
#include <soci/soci.h>
@@ -51,6 +52,16 @@ MusicListing::p music::get(const std::string& path) {
return get(path_vector);
}
+MusicDirectory::p music::get_directory(const std::string& path) {
+ MusicListing::p ml = get(path);
+ if(!ml || !fs::is_directory(ml->path)) {
+ return MusicDirectory::p();
+ }
+ MusicDirectory::p dir(boost::dynamic_pointer_cast<MusicDirectory>(ml));
+
+ return dir;
+}
+
std::vector<MusicListing::p> music::find_artist(const std::string artist) {
soci::session sql(config::vm["audist.database"].as<std::string>());
diff --git a/music.h b/music.h
index 0c4e421..3e2d24c 100644
--- a/music.h
+++ b/music.h
@@ -25,6 +25,7 @@ class MusicTrack : public MusicListing {
class MusicDirectory : public MusicListing {
public:
+ typedef boost::shared_ptr<MusicDirectory> p;
typedef std::vector<fs::path> PathListings;
PathListings directories;
PathListings tracks;
@@ -38,6 +39,7 @@ namespace music {
void init(std::string root);
MusicListing::p get(const std::vector<std::string>& path);
MusicListing::p get(const std::string& path);
+ MusicDirectory::p get_directory(const std::string& path);
std::vector<MusicListing::p> find_artist(const std::string artist);
};