1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2024-11-29 01:33:46 +00:00

Rename DirManager to GenericPath.

This commit is contained in:
King_DuckZ 2016-01-26 22:45:31 +01:00
parent 138f112254
commit 9071b25dec
6 changed files with 24 additions and 13 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@ cscope.in.out
cscope.po.out cscope.po.out
cscope.out cscope.out
tags tags
autom4te.cache/

View file

@ -1,4 +1,4 @@
/* Copyright 2015, Michele Santullo /* Copyright 2016, Michele Santullo
* This file is part of "dindexer". * This file is part of "dindexer".
* *
* "dindexer" is free software: you can redistribute it and/or modify * "dindexer" is free software: you can redistribute it and/or modify

View file

@ -4,7 +4,7 @@ add_executable(${PROJECT_NAME}
main.cpp main.cpp
commandline.cpp commandline.cpp
commandprocessor.cpp commandprocessor.cpp
dirmanager.cpp genericpath.cpp
) )
target_include_directories(${PROJECT_NAME} target_include_directories(${PROJECT_NAME}

View file

@ -15,7 +15,7 @@
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>. * along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "dirmanager.hpp" #include "genericpath.hpp"
#include "helpers/infix_iterator.hpp" #include "helpers/infix_iterator.hpp"
#include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/qi.hpp>
#include <boost/range/algorithm/copy.hpp> #include <boost/range/algorithm/copy.hpp>
@ -62,7 +62,7 @@ namespace din {
} }
} //unnamed namespace } //unnamed namespace
void DirManager::push_piece (const std::string& parPiece) { void GenericPath::push_piece (const std::string& parPiece) {
using boost::spirit::qi::parse; using boost::spirit::qi::parse;
PathGrammar<std::string::const_iterator> gramm; PathGrammar<std::string::const_iterator> gramm;
@ -97,7 +97,7 @@ namespace din {
assert(parse_result); assert(parse_result);
} }
std::string DirManager::to_string() const { std::string GenericPath::to_string() const {
std::ostringstream oss; std::ostringstream oss;
oss << '/'; oss << '/';
boost::copy(m_stack, infix_ostream_iterator<std::string>(oss, "/")); boost::copy(m_stack, infix_ostream_iterator<std::string>(oss, "/"));

View file

@ -22,9 +22,9 @@
#include <string> #include <string>
namespace din { namespace din {
class DirManager { class GenericPath {
public: public:
DirManager ( void ) = default; GenericPath ( void ) = default;
void push_piece ( const std::string& parPiece ); void push_piece ( const std::string& parPiece );
std::string to_string ( void ) const; std::string to_string ( void ) const;

View file

@ -17,7 +17,7 @@
#include "commandline.hpp" #include "commandline.hpp"
#include "commandprocessor.hpp" #include "commandprocessor.hpp"
#include "dirmanager.hpp" #include "genericpath.hpp"
#include <iostream> #include <iostream>
#include <ciso646> #include <ciso646>
#include <string> #include <string>
@ -28,7 +28,8 @@ namespace {
void do_navigation ( void ); void do_navigation ( void );
bool on_exit ( void ); bool on_exit ( void );
void on_pwd ( const din::DirManager& parDirMan ); void on_pwd ( const din::GenericPath& parDirMan );
void on_ls ( const din::GenericPath& parDirMan );
} //unnamed namespace } //unnamed namespace
int main (int parArgc, char* parArgv[]) { int main (int parArgc, char* parArgv[]) {
@ -53,25 +54,34 @@ namespace {
bool on_exit() { bool on_exit() {
return true; return true;
} }
void on_pwd (const din::DirManager& parDirMan) {
void on_pwd (const din::GenericPath& parDirMan) {
std::cout << parDirMan.to_string() << '\n'; std::cout << parDirMan.to_string() << '\n';
} }
void do_navigation() { void on_ls (const din::GenericPath& parDirMan) {
}
void do_navigation (din::DBSource& parDB) {
auto& inp = std::cin; auto& inp = std::cin;
bool running = true; bool running = true;
std::string curr_line; std::string curr_line;
din::CommandProcessor proc; din::CommandProcessor proc;
din::DirManager dir_man; din::GenericPath dir_man;
proc.add_command("exit", &on_exit, 0); proc.add_command("exit", &on_exit, 0);
proc.add_command("cd", std::function<void(const std::string&)>(std::bind(&din::DirManager::push_piece, &dir_man, std::placeholders::_1)), 1); proc.add_command("cd", std::function<void(const std::string&)>(std::bind(&din::GenericPath::push_piece, &dir_man, std::placeholders::_1)), 1);
proc.add_command("disconnect", std::function<void()>(std::bind(&din::DBSource::disconnect, &parDB)), 0);
proc.add_command("pwd", std::function<void()>(std::bind(&on_pwd, std::ref(dir_man))), 0); proc.add_command("pwd", std::function<void()>(std::bind(&on_pwd, std::ref(dir_man))), 0);
proc.add_command("ls", std::function<void()>(std::bind(&on_ls, std::ref(dir_man))), 0);
do { do {
do { do {
std::getline(inp, curr_line); std::getline(inp, curr_line);
} while (curr_line.empty()); } while (curr_line.empty());
running = proc.exec_command(curr_line); running = proc.exec_command(curr_line);
} while (running); } while (running);
parDB.disconnect();
} }
} //unnamed namespace } //unnamed namespace